-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathApplication.vala
More file actions
153 lines (119 loc) · 5.76 KB
/
Application.vala
File metadata and controls
153 lines (119 loc) · 5.76 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
/*
* Copyright 2020 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 SettingsDaemon.Application : GLib.Application {
public const OptionEntry[] OPTIONS = {
{ "version", 'v', 0, OptionArg.NONE, out show_version, "Display the version", null},
{ null }
};
public static bool show_version;
private Application () {}
private SessionClient? session_client;
private AccountsService? accounts_service;
private PantheonShell.Pantheon.AccountsService pantheon_accounts_service;
private Backends.KeyboardSettings keyboard_settings;
private Backends.MouseSettings mouse_settings;
private Backends.PrefersColorSchemeSettings prefers_color_scheme_settings;
private Backends.Housekeeping housekeeping;
construct {
application_id = Build.PROJECT_NAME;
add_main_option_entries (OPTIONS);
housekeeping = new Backends.Housekeeping ();
}
public override int handle_local_options (VariantDict options) {
if (show_version) {
stdout.printf ("%s\n", Build.VERSION);
return 0;
}
return -1;
}
public override void activate () {
register_with_session_manager.begin ();
setup_accountsservice.begin ();
hold ();
}
private async bool register_with_session_manager () {
session_client = yield register_with_session (Build.PROJECT_NAME);
session_client.query_end_session.connect (() => end_session (false));
session_client.end_session.connect (() => end_session (false));
session_client.stop.connect (() => end_session (true));
return true;
}
private async void setup_accountsservice () {
try {
var act_service = yield GLib.Bus.get_proxy<FDO.Accounts> (GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
"/org/freedesktop/Accounts");
var user_path = act_service.find_user_by_name (GLib.Environment.get_user_name ());
accounts_service = yield GLib.Bus.get_proxy (GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
user_path,
GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES);
} catch (Error e) {
warning ("Could not connect to AccountsService. Settings will not be synced to the greeter");
}
if (accounts_service != null) {
keyboard_settings = new Backends.KeyboardSettings (accounts_service);
mouse_settings = new Backends.MouseSettings (accounts_service);
}
try {
var act_service = yield GLib.Bus.get_proxy<FDO.Accounts> (GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
"/org/freedesktop/Accounts");
var user_path = act_service.find_user_by_name (GLib.Environment.get_user_name ());
pantheon_accounts_service = yield GLib.Bus.get_proxy (GLib.BusType.SYSTEM,
"org.freedesktop.Accounts",
user_path,
GLib.DBusProxyFlags.GET_INVALIDATED_PROPERTIES);
} catch (Error e) {
warning ("Unable to get AccountsService proxy, color scheme preference may be incorrect");
}
if (pantheon_accounts_service != null) {
prefers_color_scheme_settings = new Backends.PrefersColorSchemeSettings (pantheon_accounts_service);
}
}
void end_session (bool quit) {
if (quit) {
release ();
return;
}
try {
session_client.end_session_response (true, "");
} catch (Error e) {
warning ("Unable to respond to session manager: %s", e.message);
}
}
public override bool dbus_register (DBusConnection connection, string object_path) throws Error {
// We must chain up to the parent class:
base.dbus_register (connection, object_path);
// Now we can do our own stuff here. For example, we could export some D-Bus objects
connection.register_object (object_path, new Backends.SystemUpgrade ());
return true;
}
public override void dbus_unregister (DBusConnection connection, string object_path) {
// Do our own stuff here, e.g. unexport any D-Bus objects we exported in the dbus_register
// hook above. Be sure to check that we actually did export them, since the hook
// above might have returned early due to the parent class' hook returning false!
base.dbus_unregister (connection, object_path);
}
public static int main (string[] args) {
var application = new Application ();
return application.run (args);
}
}