From c0a84d6b6969d18389cbb8c0bfbd9160b5e80dc9 Mon Sep 17 00:00:00 2001 From: Danielle Fore Date: Tue, 23 Jan 2024 12:52:55 -0800 Subject: [PATCH] Application: use startup --- src/Application.vala | 55 ++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/Application.vala b/src/Application.vala index b3d076b4..0225f463 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -77,6 +77,33 @@ namespace Switchboard { activate (); } + public override void startup () { + base.startup (); + + Granite.init (); + + var granite_settings = Granite.Settings.get_default (); + var gtk_settings = Gtk.Settings.get_default (); + + gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; + + granite_settings.notify["prefers-color-scheme"].connect (() => { + gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; + }); + + var back_action = new SimpleAction ("back", null); + var quit_action = new SimpleAction ("quit", null); + + add_action (back_action); + add_action (quit_action); + + set_accels_for_action ("app.back", {"Left", "Back"}); + set_accels_for_action ("app.quit", {"q"}); + + back_action.activate.connect (action_navigate_back); + quit_action.activate.connect (quit); + } + public override void activate () { var plugsmanager = Switchboard.PlugsManager.get_default (); if (link != null) { @@ -109,26 +136,8 @@ namespace Switchboard { return; } - var granite_settings = Granite.Settings.get_default (); - var gtk_settings = Gtk.Settings.get_default (); - - gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; - - granite_settings.notify["prefers-color-scheme"].connect (() => { - gtk_settings.gtk_application_prefer_dark_theme = granite_settings.prefers_color_scheme == Granite.Settings.ColorScheme.DARK; - }); - plug_widgets = new GLib.HashTable (null, null); - var back_action = new SimpleAction ("back", null); - var quit_action = new SimpleAction ("quit", null); - - add_action (back_action); - add_action (quit_action); - - set_accels_for_action ("app.back", {"Left", "Back"}); - set_accels_for_action ("app.quit", {"q"}); - navigation_button = new Gtk.Button.with_label (_(all_settings_label)); navigation_button.action_name = "app.back"; navigation_button.set_tooltip_markup ( @@ -238,14 +247,6 @@ namespace Switchboard { } }); - back_action.activate.connect (() => { - handle_navigation_button_clicked (); - }); - - quit_action.activate.connect (() => { - quit (); - }); - shutdown.connect (() => { if (plug_widgets[leaflet.visible_child] != null && plug_widgets[leaflet.visible_child] is Switchboard.Plug) { plug_widgets[leaflet.visible_child].hidden (); @@ -371,7 +372,7 @@ namespace Switchboard { } // Handles clicking the navigation button - private void handle_navigation_button_clicked () { + private void action_navigate_back () { if (leaflet.get_adjacent_child (Adw.NavigationDirection.BACK) == category_view) { opened_directly = false; leaflet.mode_transition_duration = 200;