Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application: use startup #280

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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