-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathApplication.vala
More file actions
178 lines (143 loc) · 6.44 KB
/
Application.vala
File metadata and controls
178 lines (143 loc) · 6.44 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Copyright 2020-2023 elementary, Inc. (https://elementary.io)
* SPDX-License-Identifier: GPL-3.0-or-later
*/
public sealed class SettingsDaemon.Application : Gtk.Application {
private AccountsService accounts_service;
private Pantheon.AccountsService pantheon_service;
private DisplayManager.AccountsService display_manager_service;
private Backends.KeyboardSettings keyboard_settings;
private Backends.MouseSettings mouse_settings;
private Backends.InterfaceSettings interface_settings;
private Backends.NightLightSettings night_light_settings;
private Backends.PrefersColorSchemeSettings prefers_color_scheme_settings;
private Backends.Housekeeping housekeeping;
private Backends.WeatherAlerts weather_alerts;
private const string FDO_ACCOUNTS_NAME = "org.freedesktop.Accounts";
private const string FDO_ACCOUNTS_PATH = "/org/freedesktop/Accounts";
public Application () {
Object (
application_id: Build.PROJECT_NAME,
flags: GLib.ApplicationFlags.IS_SERVICE | GLib.ApplicationFlags.ALLOW_REPLACEMENT,
register_session: true
);
}
construct {
GLib.Intl.setlocale (ALL, "");
GLib.Intl.bindtextdomain (Build.GETTEXT_PACKAGE, Build.LOCALEDIR);
GLib.Intl.bind_textdomain_codeset (Build.GETTEXT_PACKAGE, "UTF-8");
GLib.Intl.textdomain (Build.GETTEXT_PACKAGE);
add_main_option ("version", 'v', NONE, NONE, "Display the version", null);
}
protected override int handle_local_options (VariantDict options) {
if ("version" in options) {
stdout.printf ("%s\n", Build.VERSION);
return 0;
}
return -1;
}
protected override void startup () {
query_end.connect (() => release ());
base.startup ();
housekeeping = new Backends.Housekeeping ();
weather_alerts = new Backends.WeatherAlerts ();
var check_firmware_updates_action = new GLib.SimpleAction ("check-firmware-updates", null);
check_firmware_updates_action.activate.connect (check_firmware_updates);
add_action (check_firmware_updates_action);
var show_firmware_updates_action = new GLib.SimpleAction ("show-firmware-updates", null);
show_firmware_updates_action.activate.connect (show_firmware_updates);
add_action (show_firmware_updates_action);
setup_accounts_services.begin ();
hold ();
}
private async void setup_accounts_services () {
unowned GLib.DBusConnection connection;
string path;
try {
connection = yield GLib.Bus.get (SYSTEM);
var reply = yield connection.call (
FDO_ACCOUNTS_NAME, FDO_ACCOUNTS_PATH,
FDO_ACCOUNTS_NAME, "FindUserByName",
new GLib.Variant.tuple ({ new GLib.Variant.string (GLib.Environment.get_user_name ()) }),
new VariantType ("(o)"),
NONE,
-1
);
reply.get_child (0, "o", out path);
accounts_service = yield connection.get_proxy (FDO_ACCOUNTS_NAME, path, GET_INVALIDATED_PROPERTIES);
keyboard_settings = new Backends.KeyboardSettings (accounts_service);
mouse_settings = new Backends.MouseSettings (accounts_service);
night_light_settings = new Backends.NightLightSettings (accounts_service);
} catch {
warning ("Could not connect to AccountsService. Settings will not be synced");
return;
}
try {
display_manager_service = yield connection.get_proxy (FDO_ACCOUNTS_NAME, path, GET_INVALIDATED_PROPERTIES);
interface_settings = new Backends.InterfaceSettings (accounts_service, display_manager_service);
} catch {
warning ("Unable to get LightDM's AccountsService proxy, background file might be incorrect");
}
try {
pantheon_service = yield connection.get_proxy (FDO_ACCOUNTS_NAME, path, GET_INVALIDATED_PROPERTIES);
prefers_color_scheme_settings = new Backends.PrefersColorSchemeSettings (pantheon_service);
} catch {
warning ("Unable to get pantheon's AccountsService proxy, color scheme preference may be incorrect");
}
}
private void check_firmware_updates () {
var client = new Fwupd.Client ();
var updates = 0;
try {
var devices = client.get_devices ();
foreach (unowned var device in devices) {
if (!device.has_flag (Fwupd.DEVICE_FLAG_UPDATABLE)) {
continue;
}
Fwupd.Release? release = null;
try {
var upgrades = client.get_upgrades (device.get_id ());
if (upgrades != null) {
release = upgrades[0];
}
} catch (Error e) {
warning (e.message);
continue;
}
if (release != null && device.get_version () != release.get_version ()) {
updates++;
}
}
} catch (Error e) {
warning (e.message);
}
if (updates != 0) {
var title = ngettext ("Firmware Update Available", "Firmware Updates Available", updates);
var body = ngettext (
"%u update is available for your hardware",
"%u updates are available for your hardware",
updates
);
var notification = new Notification (title);
notification.set_body (body.printf (updates));
notification.set_icon (new ThemedIcon ("application-x-firmware"));
notification.set_default_action ("app.show-firmware-updates");
send_notification ("firmware.updates", notification);
} else {
withdraw_notification ("firmware.updates");
}
}
private void show_firmware_updates () {
var context = Gdk.Display.get_default ().get_app_launch_context ();
GLib.AppInfo.launch_default_for_uri_async.begin ("settings://about/firmware", context, null, (obj, res) => {
try {
GLib.AppInfo.launch_default_for_uri_async.end (res);
} catch (GLib.Error e) {
critical (e.message);
}
});
}
public static int main (string[] args) {
return new SettingsDaemon.Application ().run (args);
}
}