mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-11-21 20:36:01 +03:00
Changed debug logging
- stdout logs got rid of rustls messages and now are pretty styled - logs are saved into the `debug.log` file in the launcher folder they're not filtered and contain all the messages - toasts timeout fixed to 5 seconds - added "save" button which will, well, not save logs but open `debug.log` file using `xdg-open`
This commit is contained in:
parent
4965a9f005
commit
44d074d864
4 changed files with 48 additions and 7 deletions
|
@ -3,6 +3,7 @@ none = None
|
|||
default = Default
|
||||
details = Details
|
||||
close = Close
|
||||
save = Save
|
||||
|
||||
|
||||
checking-free-space = Checking free space
|
||||
|
|
|
@ -3,6 +3,7 @@ none = Нет
|
|||
default = По умолчанию
|
||||
details = Подробнее
|
||||
close = Закрыть
|
||||
save = Сохранить
|
||||
|
||||
|
||||
checking-free-space = Проверка свободного места
|
||||
|
|
37
src/main.rs
37
src/main.rs
|
@ -4,6 +4,8 @@ use anime_launcher_sdk::config;
|
|||
use anime_launcher_sdk::anime_game_core::prelude::*;
|
||||
use anime_launcher_sdk::anime_game_core::genshin::prelude::*;
|
||||
|
||||
use tracing_subscriber::prelude::*;
|
||||
|
||||
pub mod i18n;
|
||||
pub mod ui;
|
||||
|
||||
|
@ -25,6 +27,9 @@ pub fn is_ready() -> bool {
|
|||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
/// Path to `debug.log` file. Standard is `$HOME/.local/share/anime-game-launcher/debug.log`
|
||||
pub static ref DEBUG_FILE: std::path::PathBuf = anime_launcher_sdk::consts::launcher_dir().unwrap_or_default().join("debug.log");
|
||||
|
||||
/// Config loaded on the app's start. Use `config::get()` to get up to date config instead.
|
||||
/// This one is used to prepare some launcher UI components on start
|
||||
pub static ref CONFIG: config::Config = config::get().expect("Failed to load config");
|
||||
|
@ -56,12 +61,32 @@ lazy_static::lazy_static! {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
tracing_subscriber::fmt()
|
||||
.with_span_events(tracing_subscriber::fmt::format::FmtSpan::FULL)
|
||||
.with_max_level(if APP_DEBUG || std::env::args().any(|arg| &arg == "--debug") {
|
||||
tracing::Level::TRACE
|
||||
} else {
|
||||
tracing::Level::WARN
|
||||
let stdout = tracing_subscriber::fmt::layer().pretty();
|
||||
|
||||
let file = match std::fs::File::create(DEBUG_FILE.as_path()) {
|
||||
Ok(file) => file,
|
||||
Err(error) => panic!("Failed to create debug.log file: {:?}", error)
|
||||
};
|
||||
|
||||
let mut debug_log = tracing_subscriber::fmt::layer()
|
||||
.with_writer(std::sync::Arc::new(file));
|
||||
|
||||
debug_log.set_ansi(false);
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with({
|
||||
stdout
|
||||
.with_filter(tracing_subscriber::filter::LevelFilter::from_level({
|
||||
if APP_DEBUG || std::env::args().any(|arg| &arg == "--debug") {
|
||||
tracing::Level::TRACE
|
||||
} else {
|
||||
tracing::Level::WARN
|
||||
}
|
||||
}))
|
||||
.with_filter(tracing_subscriber::filter::filter_fn(|metadata| {
|
||||
!metadata.target().starts_with("rustls")
|
||||
}))
|
||||
.and_then(debug_log)
|
||||
})
|
||||
.init();
|
||||
|
||||
|
|
|
@ -222,7 +222,7 @@ impl SimpleAsyncComponent for App {
|
|||
AppMsg::Toast { title, description } => unsafe {
|
||||
let toast = adw::Toast::new(&title);
|
||||
|
||||
toast.set_timeout(5000);
|
||||
toast.set_timeout(5);
|
||||
|
||||
if let Some(description) = description {
|
||||
toast.set_button_label(Some(&tr("details")));
|
||||
|
@ -230,6 +230,20 @@ impl SimpleAsyncComponent for App {
|
|||
let dialog = adw::MessageDialog::new(PREFERENCES_WINDOW.as_ref(), Some(&title), Some(&description));
|
||||
|
||||
dialog.add_response("close", &tr("close"));
|
||||
dialog.add_response("save", &tr("save"));
|
||||
|
||||
dialog.set_response_appearance("save", adw::ResponseAppearance::Suggested);
|
||||
|
||||
#[allow(unused_must_use)]
|
||||
dialog.connect_response(Some("save"), |_, _| {
|
||||
let result = std::process::Command::new("xdg-open")
|
||||
.arg(crate::DEBUG_FILE.as_os_str())
|
||||
.output();
|
||||
|
||||
if let Err(err) = result {
|
||||
tracing::error!("Failed to open debug file: {}", err);
|
||||
}
|
||||
});
|
||||
|
||||
toast.connect_button_clicked(move |_| {
|
||||
dialog.show();
|
||||
|
|
Loading…
Reference in a new issue