Skip to content
Draft
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
53 changes: 53 additions & 0 deletions lib/Widgets/Application.vala
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and Granite.Services.Application should be merged, also Application classes aren't widgets, so this file should be direct at the src folder.

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2025 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-2.0-or-later
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure we use LGPL-3.0-or-later in granite.

*/

/**
* A {@link Gtk.Application} subclass that includes Granite initialization and
* setup for common accelerator actions.
*
* @since 7.7.0
*/

[Version (since = "7.7.0")]
public class Granite.Application : Gtk.Application {

public Application () {
Object (
flags: ApplicationFlags.DEFAULT_FLAGS
);
}
Comment on lines +16 to +20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Public constructors, in this case, is only for the use of procedural code (i.e., c and rust bindings). So this should take the application_id and flags as parameters.

Suggested change
public Application () {
Object (
flags: ApplicationFlags.DEFAULT_FLAGS
);
}
public Application (string? application_id, GLib.ApplicationFlags flags) {
Object (
application_id: application_id,
flags: flags
);
}

Otherwise, it has no use for us in the vala side of the things.


construct {
Intl.setlocale (LocaleCategory.ALL, "");
Intl.bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
Intl.bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
Intl.textdomain (GETTEXT_PACKAGE);
Comment on lines +23 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Granite.init() should be handling this already, also, we don't have any granite specific command line argument to this be executed before startup() anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it looks like init does handle some of this already:

GLib.Intl.bindtextdomain (Granite.GETTEXT_PACKAGE, Granite.LOCALEDIR);

}

public override void startup () {
Granite.init ();
base.startup ();

// Respond to user theme preferences
var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.SEttings.get_default ();
Comment on lines +34 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little typo, also thoses objects are unowned.

Suggested change
var granite_settings = Granite.Settings.get_default ();
var gtk_settings = Gtk.SEttings.get_default ();
unowned var granite_settings = Granite.Settings.get_default ();
unowned var gtk_settings = Gtk.Settings.get_default ();


gtk_settings.gtk_application_prefer_dark_theme = (
granite_settings.prefers_color_scheme == DARK
);

granite_settings.noftify["prefers-color-scheme"].connect (() => {
gtk_settings.gtk_application_prefer_dark_theme = (
granite_settings.prefers_color_scheme == DARK
);
});
Comment on lines +37 to +45
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going to handling this here, we need a property that controls the "no-preference" behavior between default dark and default bright applications.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually already handle this in StyleManager as well. I think that's automatically added in Granite.init ()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right, the flatpak SDK doesn't have the 7.7.0 stuff, so my boilerplate reference code is old* 😓


// Set up common actions
var quit_action = new SimpleAction ("quit", null);
add_action (quit_action);
set_accels_for_action ("app.quit", {"<Control>q"});
quit_action.activate.connect (quit);
Comment on lines +48 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Application actions can be activated from external applications after added, so we need to have it completely setup before adding it.

Suggested change
var quit_action = new SimpleAction ("quit", null);
add_action (quit_action);
set_accels_for_action ("app.quit", {"<Control>q"});
quit_action.activate.connect (quit);
var quit_action = new SimpleAction ("quit", null);
quit_action.activate.connect (quit);
add_action (quit_action);
set_accels_for_action ("app.quit", {"<Control>q"});

}
}