-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathApplication.vala
More file actions
87 lines (74 loc) · 3.01 KB
/
Application.vala
File metadata and controls
87 lines (74 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Copyright 2019-2023 elementary, Inc. (https://elementary.io)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
*/
public class Notifications.Application : Gtk.Application {
private static Granite.Settings granite_settings;
private static Gtk.Settings gtk_settings;
public Application () {
Object (
application_id: "io.elementary.notifications",
flags: ApplicationFlags.IS_SERVICE | ApplicationFlags.ALLOW_REPLACEMENT
);
}
protected override bool dbus_register (DBusConnection connection, string object_path) throws Error {
try {
new Notifications.Server (connection);
} catch (Error e) {
Error.prefix_literal (out e, "Registering notification server failed: ");
throw e;
}
return base.dbus_register (connection, object_path);
}
protected override void startup () {
base.startup ();
Granite.init ();
granite_settings = Granite.Settings.get_default ();
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;
});
unowned var context = CanberraGtk4.context_get ();
context.change_props (
Canberra.PROP_APPLICATION_NAME, "Notifications",
Canberra.PROP_APPLICATION_ID, application_id,
null
);
context.open ();
var dbus_flags = BusNameOwnerFlags.DO_NOT_QUEUE | BusNameOwnerFlags.ALLOW_REPLACEMENT;
if (ApplicationFlags.REPLACE in flags) {
dbus_flags |= BusNameOwnerFlags.REPLACE;
}
Bus.own_name_on_connection (
get_dbus_connection (),
"org.freedesktop.Notifications",
dbus_flags,
() => hold (),
(conn, name) => {
critical ("Could not aquire bus: %s", name);
name_lost ();
}
);
IdleMonitor.get_default (); // Start listening to MutterIdleMonitor
}
public static int main (string[] args) {
var app = new Application ();
return app.run (args);
}
}