LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust
Quit from the macOS menu: save settings and the library (and honour the unsaved-changes prompt) before exiting
Brandon Thomas761631c56cc9
diff --git a/apps/lightcraft/src/main.rs b/apps/lightcraft/src/main.rsindex a0394da95..aedbf7fbc 100644--- a/apps/lightcraft/src/main.rs+++ b/apps/lightcraft/src/main.rs@@ -52,8 +52,15 @@ struct App(LightcraftApp, PrefsWriter, #[cfg(target_os = "macos")] Option<nativeimpl eframe::App for App {fn logic(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {#[cfg(target_os = "macos")]- if let Some(m) = self.2.as_mut() {- m.update(&mut self.0, ctx);+ if let Some(m) = self.2.as_mut()+ && m.update(&mut self.0, ctx)+ && lightcraft_ui_egui::panels::notices::may_close(&mut self.0)+ {+ // Quit from the menu bar: save exactly what closing the window saves (settings and+ // library, after the unsaved-changes check; otherwise its prompt shows), then end the+ // process instead of closing the viewport while AppKit is terminating (PR #444).+ eframe::App::on_exit(self);+ std::process::exit(0);}self.0.logic(ctx);self.1.tick(&mut self.0, ctx);diff --git a/apps/lightcraft/src/native_menu.rs b/apps/lightcraft/src/native_menu.rsindex 6c6d2f2b6..256faa1f8 100644--- a/apps/lightcraft/src/native_menu.rs+++ b/apps/lightcraft/src/native_menu.rs@@ -355,12 +355,16 @@ impl NativeMenu {}/// Per frame: run chosen items, then sync labels / enabled / checked and the text-focus- /// accelerators with the app state.- pub fn update(&mut self, app: &mut LightcraftApp, ctx: &egui::Context) {+ /// accelerators with the app state. Returns whether Quit was chosen: the caller saves+ /// everything and exits the process itself (closing the viewport while AppKit terminates the+ /// app can crash in winit's teardown, PR #444).+ pub fn update(&mut self, app: &mut LightcraftApp, ctx: &egui::Context) -> bool {lightcraft_ui_egui::i18n::set_language(app.ui.language);+ let mut quit = false;while let Ok(key) = self.rx.try_recv() {if key == QUIT {- std::process::exit(0);+ quit = true;+ continue;}if key == "app.about" || key == SETTINGS {let _ = app.run(&key, serde_json::json!({}));@@ -374,7 +378,7 @@ impl NativeMenu {let bar = menu_bar(app);if structure_of(&bar) != self.structure {self.rebuild(app);- return;+ return quit;}fn walk(nodes: &[MenuNode], items: &mut HashMap<String, Item>) {for n in nodes {@@ -428,6 +432,7 @@ impl NativeMenu {}self.publish_shortcuts(app);}+ quit}}