From 45c86dbfe8453c0f61b0a5b53ddc60b53fcb3b11 Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Sat, 1 Apr 2023 00:55:42 -0500 Subject: [PATCH] Revert "b/logs: do some things to try to log panics on startups" (#148) --- src-tauri/Cargo.lock | 1 - src-tauri/Cargo.toml | 1 - src-tauri/src/main.rs | 106 +++++++++----------------------------- src-tauri/tauri.conf.json | 5 +- 4 files changed, 29 insertions(+), 84 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 2dc098da..a1a8d805 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -2258,7 +2258,6 @@ dependencies = [ name = "opengoal-launcher" version = "2.0.5" dependencies = [ - "backtrace", "chrono", "dir-diff", "fern", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 0858e7c1..11decafd 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -35,7 +35,6 @@ thiserror = "1.0.40" rev_buf_reader = "0.3.0" flate2 = "1.0.25" tar = "0.4.38" -backtrace = "0.3.67" [features] # by default Tauri runs in production mode diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6f8c6c0a..9fe4193e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -7,36 +7,15 @@ use fern::colors::{Color, ColoredLevelConfig}; use tauri::{Manager, RunEvent}; use util::file::create_dir; -use backtrace::Backtrace; -use std::{env, io::Write}; +use std::env; mod commands; mod config; mod textures; mod util; -fn panic_hook(info: &std::panic::PanicInfo) { - let backtrace = Backtrace::new(); - log::error!("panic occurred: {:?}\n{:?}", info, backtrace); - match std::fs::File::create("og-launcher-crash.log") { - Ok(mut file) => { - if let Err(err) = - file.write_all(format!("panic occurred: {:?}\n{:?}", info, backtrace).as_bytes()) - { - log::error!("unable to log crash report to a file - {:?}", err) - } - } - Err(err) => log::error!("unable to log crash report to a file - {:?}", err), - } - std::process::exit(1); -} - fn main() { - // In the event that some catastrophic happens, atleast log it out - // the panic_hook will log to a file in the folder of the executable - std::panic::set_hook(Box::new(panic_hook)); - - let tauri_setup = tauri::Builder::default() + tauri::Builder::default() .setup(|app| { // Setup Logging let log_path = app @@ -58,7 +37,7 @@ fn main() { // since almost all of them are the same as the color for the whole line, we // just clone `colors_line` and overwrite our changes let colors_level = colors_line.clone().info(Color::Cyan); - let log_setup_ok = fern::Dispatch::new() + fern::Dispatch::new() // Perform allocation-free log formatting .format(move |out, message, record| { out.finish(format_args!( @@ -81,26 +60,23 @@ fn main() { .chain(std::io::stdout()) .chain(fern::DateBased::new(&log_path, "/%Y-%m-%d.log")) // Apply globally - .apply(); - match log_setup_ok { - Ok(_) => { - log::info!("Logging Initialized"); - // Truncate rotated log files to '5' - let mut paths: Vec<_> = std::fs::read_dir(&log_path)?.map(|r| r.unwrap()).collect(); - paths.sort_by_key(|dir| dir.path()); - paths.reverse(); - let mut i = 0; - for path in paths { - i += 1; - log::info!("{}", path.path().display()); - if i > 5 { - log::info!("deleting - {}", path.path().display()); - std::fs::remove_file(path.path())?; - } - } + .apply() + .expect("Could not setup logs"); + log::info!("Logging Initialized"); + + // Truncate rotated log files to '5' + let mut paths: Vec<_> = std::fs::read_dir(&log_path)?.map(|r| r.unwrap()).collect(); + paths.sort_by_key(|dir| dir.path()); + paths.reverse(); + let mut i = 0; + for path in paths { + i += 1; + log::info!("{}", path.path().display()); + if i > 5 { + log::info!("deleting - {}", path.path().display()); + std::fs::remove_file(path.path())?; } - Err(err) => log::error!("Could not initialize logging {:?}", err), - }; + } // Load the config (or initialize it with defaults) // @@ -148,43 +124,11 @@ fn main() { commands::window::open_dir_in_os ]) .build(tauri::generate_context!()) - .map_err(|err| { - let backtrace = Backtrace::new(); - log::error!( - "unexpected top level error occurred: {:?}\n{:?}", - err, - backtrace - ); - match std::fs::File::create("og-launcher-crash.log") { - Ok(mut file) => { - if let Err(file_err) = file.write_all( - format!( - "unexpected top level error occurred: {:?}\n{:?}", - err, backtrace - ) - .as_bytes(), - ) { - log::error!("unable to log crash report to a file - {:?}", file_err) - } - } - Err(err) => log::error!("unable to log crash report to a file - {:?}", err), + .expect("error building tauri app") + .run(|_app_handle, event| match event { + RunEvent::ExitRequested { .. } => { + std::process::exit(0); } - std::process::exit(1); - }); - match tauri_setup { - Ok(app) => { - log::info!("application starting up"); - app.run(|_app_handle, event| match event { - RunEvent::ExitRequested { .. } => { - log::info!("Exit requested, exiting!"); - std::process::exit(0); - } - _ => (), - }) - } - Err(err) => { - log::error!("Could not setup tauri application {:?}, exiting", err); - std::process::exit(1); - } - }; + _ => (), + }) } diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 3d0d8159..7042ad5a 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -38,7 +38,10 @@ "windows": { "certificateThumbprint": null, "digestAlgorithm": "sha256", - "timestampUrl": "" + "timestampUrl": "", + "webviewInstallMode": { + "type": "embedBootstrapper" + } } }, "allowlist": {