Skip to content

Commit

Permalink
Application: use startup (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Jan 23, 2024
1 parent 872fcb8 commit c0c3399
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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", {"<Alt>Left", "Back"});
set_accels_for_action ("app.quit", {"<Control>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) {
Expand Down Expand Up @@ -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 <Gtk.Widget, Switchboard.Plug> (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", {"<Alt>Left", "Back"});
set_accels_for_action ("app.quit", {"<Control>q"});

navigation_button = new Gtk.Button.with_label (_(all_settings_label));
navigation_button.action_name = "app.back";
navigation_button.set_tooltip_markup (
Expand Down Expand Up @@ -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 ();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c0c3399

Please sign in to comment.