main: fix closing

This commit is contained in:
hinto.janai 2023-12-28 09:22:45 -05:00
parent 62865f7c41
commit a51234d353
No known key found for this signature in database
GPG key ID: D47CE05FA175A499

View file

@ -1191,26 +1191,35 @@ impl eframe::App for App {
// If closing.
// Used to be `eframe::App::on_close_event(&mut self) -> bool`.
ctx.input(|input| {
let close_signal = ctx.input(|input| {
use egui::viewport::ViewportCommand;
if !input.viewport().close_requested() {
return;
return None;
}
if self.state.gupax.ask_before_quit {
// If we're already on the [ask_before_quit] screen and
// the user tried to exit again, exit.
if self.error_state.quit_twice {
if self.state.gupax.save_before_quit { self.save_before_quit(); }
ctx.send_viewport_cmd(egui::viewport::ViewportCommand::Close);
return Some(ViewportCommand::Close);
}
// Else, set the error
self.error_state.set("", ErrorFerris::Oops, ErrorButtons::StayQuit);
self.error_state.quit_twice = true;
Some(ViewportCommand::CancelClose)
// Else, just quit.
} else {
if self.state.gupax.save_before_quit { self.save_before_quit(); }
ctx.send_viewport_cmd(egui::viewport::ViewportCommand::Close);
Some(ViewportCommand::Close)
}
});
// This will either:
// 1. Cancel a close signal
// 2. Close the program
if let Some(cmd) = close_signal {
ctx.send_viewport_cmd(cmd);
}
// If [F11] was pressed, reverse [fullscreen] bool
let key: KeyPressed = ctx.input_mut(|input| {