improve reliability of panic hook by moving it to main and always creating its storage path
This commit is contained in:
+1
-9
@@ -3,21 +3,13 @@ use crate::{
|
|||||||
app::{App, WINDOW_SIZE},
|
app::{App, WINDOW_SIZE},
|
||||||
tools,
|
tools,
|
||||||
},
|
},
|
||||||
util::{log, persistent_state::PersistentState, win},
|
util::{persistent_state::PersistentState, win},
|
||||||
};
|
};
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
|
|
||||||
fn panic_hook(panic_info: &std::panic::PanicHookInfo<'_>) {
|
|
||||||
let backtrace = std::backtrace::Backtrace::capture();
|
|
||||||
let message = format!("{panic_info}\nstack backtrace:\n{backtrace}\n");
|
|
||||||
log::log(log::LogLevel::Panic, &message);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn app_creator(
|
fn app_creator(
|
||||||
cc: &eframe::CreationContext<'_>,
|
cc: &eframe::CreationContext<'_>,
|
||||||
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
) -> Result<Box<dyn eframe::App>, Box<dyn std::error::Error + Send + Sync>> {
|
||||||
// use our own panic hook which logs all panics to a file
|
|
||||||
std::panic::set_hook(Box::new(panic_hook));
|
|
||||||
// initialize App early to modify some things before returning it
|
// initialize App early to modify some things before returning it
|
||||||
let mut app = Box::new(App::default());
|
let mut app = Box::new(App::default());
|
||||||
// load previously selected launch platform & settings from persistent state
|
// load previously selected launch platform & settings from persistent state
|
||||||
|
|||||||
+14
@@ -7,6 +7,20 @@ mod features;
|
|||||||
mod gui;
|
mod gui;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
|
fn init_storage() {
|
||||||
|
if !crate::util::consts::path::APP_STORAGE.exists() {
|
||||||
|
std::fs::create_dir(crate::util::consts::path::APP_STORAGE.as_path()).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn panic_hook(panic_info: &std::panic::PanicHookInfo<'_>) {
|
||||||
|
let backtrace = std::backtrace::Backtrace::capture();
|
||||||
|
let message = format!("{panic_info}\nstack backtrace:\n{backtrace}\n");
|
||||||
|
crate::util::log::log(crate::util::log::LogLevel::Panic, &message);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
init_storage();
|
||||||
|
std::panic::set_hook(Box::new(panic_hook));
|
||||||
gui::run::run();
|
gui::run::run();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,7 @@ impl PersistentState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn set(&self) {
|
pub fn set(&self) {
|
||||||
let config_path = path::APP_CONFIG.as_path();
|
let mut config_file = File::create(path::APP_CONFIG.as_path()).unwrap();
|
||||||
let config_path_parent = config_path.parent().unwrap();
|
|
||||||
if !config_path_parent.exists() {
|
|
||||||
fs::create_dir(config_path_parent).unwrap();
|
|
||||||
}
|
|
||||||
let mut config_file = File::create(config_path).unwrap();
|
|
||||||
let json = serde_json::to_string_pretty(&self).unwrap();
|
let json = serde_json::to_string_pretty(&self).unwrap();
|
||||||
config_file.write_all(json.as_bytes()).unwrap();
|
config_file.write_all(json.as_bytes()).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user