mirror of
https://github.com/hinto-janai/gupax.git
synced 2025-01-18 23:54:30 +00:00
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:
parent
d1a4d66268
commit
7439c89a52
3 changed files with 22 additions and 5 deletions
|
@ -886,8 +886,8 @@ impl Helper {
|
||||||
// And... wipe it again (only if we're stopping full).
|
// And... wipe it again (only if we're stopping full).
|
||||||
// If we're restarting, the next start will wipe it for us.
|
// If we're restarting, the next start will wipe it for us.
|
||||||
if signal != ProcessSignal::Restart { SudoState::wipe(&sudo); }
|
if signal != ProcessSignal::Restart { SudoState::wipe(&sudo); }
|
||||||
} else {
|
} else if let Err(e) = child_pty.lock().unwrap().kill() {
|
||||||
if let Err(e) = child_pty.lock().unwrap().kill() { error!("XMRig Watchdog | Kill error: {}", e); }
|
error!("XMRig Watchdog | Kill error: {}", e);
|
||||||
}
|
}
|
||||||
let exit_status = match child_pty.lock().unwrap().wait() {
|
let exit_status = match child_pty.lock().unwrap().wait() {
|
||||||
Ok(e) => {
|
Ok(e) => {
|
||||||
|
|
21
src/main.rs
21
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 {
|
fn new(now: Instant) -> Self {
|
||||||
info!("Initializing App Struct...");
|
info!("Initializing App Struct...");
|
||||||
debug!("App Init | P2Pool & XMRig processes...");
|
debug!("App Init | P2Pool & XMRig processes...");
|
||||||
|
@ -908,10 +914,18 @@ fn main() {
|
||||||
|
|
||||||
impl eframe::App for App {
|
impl eframe::App for App {
|
||||||
fn on_close_event(&mut self) -> bool {
|
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);
|
self.error_state.set("", ErrorFerris::Oops, ErrorButtons::StayQuit);
|
||||||
false
|
false
|
||||||
|
// Else, just quit.
|
||||||
} else {
|
} else {
|
||||||
|
if self.state.gupax.save_before_quit { self.save_before_quit(); }
|
||||||
true
|
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() {
|
if key.is_esc() || ui.add_sized([width, height/2.0], Button::new("Stay")).clicked() {
|
||||||
self.error_state = ErrorState::new();
|
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
|
// 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.
|
// Another error after this either means an IO error or permission error, which Gupax can't fix.
|
||||||
|
|
|
@ -367,7 +367,7 @@ impl Ping {
|
||||||
}
|
}
|
||||||
|
|
||||||
for handle in handles {
|
for handle in handles {
|
||||||
handle.await;
|
handle.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let node_vec = std::mem::take(&mut *node_vec.lock().unwrap());
|
let node_vec = std::mem::take(&mut *node_vec.lock().unwrap());
|
||||||
|
|
Loading…
Reference in a new issue