From 7439c89a52b3a5ece5079b4509aa51b25b16a985 Mon Sep 17 00:00:00 2001 From: hinto-janaiyo Date: Sat, 17 Dec 2022 10:09:50 -0500 Subject: [PATCH] main: quit if [ALT+F4] on [ask_before_quit], add [save_before_quit] If user clicked the [X] or [ALT+F4] while on the [ask_before_quit] screen, it'll actually exit now. The [save_before_quit] option actually... saves before quitting now. No cloning since we're exiting and no [ErrorState] setting on errors. The console logs will show if a save error happens. --- src/helper.rs | 4 ++-- src/main.rs | 21 +++++++++++++++++++-- src/node.rs | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/helper.rs b/src/helper.rs index c71903c..d126d9b 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -886,8 +886,8 @@ impl Helper { // And... wipe it again (only if we're stopping full). // If we're restarting, the next start will wipe it for us. if signal != ProcessSignal::Restart { SudoState::wipe(&sudo); } - } else { - if let Err(e) = child_pty.lock().unwrap().kill() { error!("XMRig Watchdog | Kill error: {}", e); } + } else if let Err(e) = child_pty.lock().unwrap().kill() { + error!("XMRig Watchdog | Kill error: {}", e); } let exit_status = match child_pty.lock().unwrap().wait() { Ok(e) => { diff --git a/src/main.rs b/src/main.rs index cde3df4..fd9db94 100644 --- a/src/main.rs +++ b/src/main.rs @@ -157,6 +157,12 @@ impl App { } } + fn save_before_quit(&mut self) { + if let Err(e) = State::save(&mut self.state, &self.state_path) { error!("State file: {}", e); } + if let Err(e) = Node::save(&self.node_vec, &self.node_path) { error!("Node list: {}", e); } + if let Err(e) = Pool::save(&self.pool_vec, &self.pool_path) { error!("Pool list: {}", e); } + } + fn new(now: Instant) -> Self { info!("Initializing App Struct..."); debug!("App Init | P2Pool & XMRig processes..."); @@ -908,10 +914,18 @@ fn main() { impl eframe::App for App { fn on_close_event(&mut self) -> bool { - if self.state.gupax.ask_before_quit { + // If we're already on the [ask_before_quit] screen and + // the user tries to exit again, exit. + if self.error_state.buttons == ErrorButtons::StayQuit { + if self.state.gupax.save_before_quit { self.save_before_quit(); } + true + // Else, set up the [ask_before_quit] screen (if enabled). + } else if self.state.gupax.ask_before_quit { self.error_state.set("", ErrorFerris::Oops, ErrorButtons::StayQuit); false + // Else, just quit. } else { + if self.state.gupax.save_before_quit { self.save_before_quit(); } true } } @@ -1130,7 +1144,10 @@ impl eframe::App for App { if key.is_esc() || ui.add_sized([width, height/2.0], Button::new("Stay")).clicked() { self.error_state = ErrorState::new(); } - if ui.add_sized([width, height/2.0], Button::new("Quit")).clicked() { exit(0); } + if ui.add_sized([width, height/2.0], Button::new("Quit")).clicked() { + if self.state.gupax.save_before_quit { self.save_before_quit(); } + exit(0); + } }, // This code handles the [state.toml/node.toml] resetting, [panic!]'ing if it errors once more // Another error after this either means an IO error or permission error, which Gupax can't fix. diff --git a/src/node.rs b/src/node.rs index 4f21cab..f3b2ea9 100644 --- a/src/node.rs +++ b/src/node.rs @@ -367,7 +367,7 @@ impl Ping { } for handle in handles { - handle.await; + handle.await?; } let node_vec = std::mem::take(&mut *node_vec.lock().unwrap());