feat: verbose toggle, info tab, many misc fixes

This commit is contained in:
2025-04-14 19:20:08 +00:00
parent 37df371006
commit f588892b05
30 changed files with 410 additions and 186 deletions

View File

@ -9,11 +9,10 @@ mod modules;
mod profiles;
mod patcher;
use std::{sync::OnceLock, time::SystemTime};
use std::sync::OnceLock;
use anyhow::anyhow;
use closure::closure;
use appdata::{AppData, ToggleAction};
use fern::colors::{Color, ColoredLevelConfig};
use model::misc::Game;
use pkg::PkgKey;
use pkg_store::Payload;
@ -48,42 +47,7 @@ pub async fn run(_args: Vec<String>) {
util::init_dirs(&apph);
let mut fern_builder;
{
let colors = ColoredLevelConfig::new()
.debug(Color::Green)
.info(Color::Blue)
.warn(Color::Yellow)
.error(Color::Red);
fern_builder = fern::Dispatch::new()
.format(move |out, message, record| {
out.finish(format_args!(
"[{} {} {}] {}",
humantime::format_rfc3339_seconds(SystemTime::now()),
colors.color(record.level()),
record.target(),
message
))
})
.chain(std::io::stdout())
.chain(fern::log_file(util::data_dir().join("log.txt")).expect("unable to initialize the logger"));
}
#[cfg(debug_assertions)]
{
fern_builder = fern_builder.level(log::LevelFilter::Debug);
}
#[cfg(not(debug_assertions))]
{
if std::env::var("DEBUG_LOG").is_ok() {
fern_builder = fern_builder.level(log::LevelFilter::Debug);
} else {
fern_builder = fern_builder.level(log::LevelFilter::Info);
}
}
fern_builder.apply()?;
let mut app_data = AppData::new(app.handle().clone());
log::info!(
"running from {}",
@ -93,7 +57,6 @@ pub async fn run(_args: Vec<String>) {
.unwrap_or_default()
);
let mut app_data = AppData::new(app.handle().clone());
let start_immediately;
if let Ok(matches) = app.cli().matches() {
@ -244,6 +207,8 @@ pub async fn run(_args: Vec<String>) {
cmd::list_platform_capabilities,
cmd::list_directories,
cmd::file_exists,
cmd::open_file,
cmd::get_changelog,
cmd::list_com_ports,
@ -326,7 +291,7 @@ async fn update(app: tauri::AppHandle) -> tauri_plugin_updater::Result<()> {
update.download_and_install(
|chunk_length, content_length| {
downloaded += chunk_length;
_ = app.emit("update-progress", (chunk_length as f64) / (content_length.unwrap_or(u64::MAX) as f64));
_ = app.emit("update-progress", (downloaded as f64) / (content_length.unwrap_or(u64::MAX) as f64));
},
|| {
log::info!("download finished");