diff --git a/fitnesstrax/app/src/main.rs b/fitnesstrax/app/src/main.rs index d03733b..921f708 100644 --- a/fitnesstrax/app/src/main.rs +++ b/fitnesstrax/app/src/main.rs @@ -34,6 +34,20 @@ const APP_ID_PROD: &str = "com.luminescent-dreams.fitnesstrax"; const RESOURCE_BASE_PATH: &str = "/com/luminescent-dreams/fitnesstrax/"; +/// Sets up an application-global action, `app.quit`, which will terminate the application. +fn setup_app_close_action(app: &adw::Application) { + let action = ActionEntry::builder("quit") + .activate(|app: &adw::Application, _, _| { + // right now, stopping the application is dirt simple. But we could use this + // block to add extra code that does additional shutdown steps if we ever want + // some states that shouldn't be discarded. + app.quit(); + }) + .build(); + app.add_action_entries([action]); + app.set_accels_for_action("app.quit", &["Q"]); +} + fn main() { // I still don't fully understand gio resources. resources_register_include! is convenient // because I don't have to deal with filesystem locations at runtime. However, I think other @@ -67,13 +81,7 @@ fn main() { let icon_theme = gtk::IconTheme::for_display(&gdk::Display::default().unwrap()); icon_theme.add_resource_path(&(RESOURCE_BASE_PATH.to_owned() + "/icons/scalable/actions")); - let app_close_action = ActionEntry::builder("quit") - .activate(|app: &adw::Application, _, _| { - app.quit(); - }) - .build(); - adw_app.add_action_entries([app_close_action]); - adw_app.set_accels_for_action("app.quit", &["Q"]); + setup_app_close_action(&adw_app); AppWindow::new(app_id, RESOURCE_BASE_PATH, adw_app, ft_app.clone()); });