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.
This commit is contained in:
hinto-janaiyo 2022-12-17 10:09:50 -05:00
parent d1a4d66268
commit 7439c89a52
No known key found for this signature in database
GPG key ID: B1C5A64B80691E45
3 changed files with 22 additions and 5 deletions

View file

@ -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) => {

View file

@ -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.

View file

@ -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());