-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprefs.js
302 lines (228 loc) · 7.71 KB
/
prefs.js
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/* prefs.js
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import Adw from 'gi://Adw';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Gtk from 'gi://Gtk';
import Secret from 'gi://Secret';
import {
ExtensionPreferences,
gettext as _
} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
Gio._promisify(Secret.Collection, 'for_alias', 'for_alias_finish');
Gio._promisify(Secret.Service, 'get', 'get_finish');
function adwCheckVersion(req_major, req_minor)
{
const major = Adw.get_major_version();
if (major < req_major)
return false;
if (major > req_major)
return true;
return Adw.get_minor_version() >= req_minor;
}
class CollectionRow extends Adw.ActionRow {
static {
GObject.registerClass(this);
}
#switch;
#path;
constructor(collection, active, aliases = [])
{
super({
title: collection.label,
title_lines: 1,
title_selectable: true,
subtitle: collection.get_object_path(),
subtitle_lines: 1,
});
if (adwCheckVersion(1, 3))
this.subtitle_selectable = true;
this.#path = collection.get_object_path();
if (aliases)
this.title += aliases.map(x => `<sup>[${x}]</sup>`).join(' ');
this.#switch = new Gtk.Switch({
valign: Gtk.Align.CENTER,
action_name: 'kal.collection.update-ignored',
active: active
});
this.add_suffix(this.#switch);
}
set active(val)
{
this.#switch.active = val;
}
get active()
{
return this.#switch.active;
}
get path()
{
return this.#path;
}
};
class IgnoredPage extends Adw.PreferencesPage {
static {
GObject.registerClass(this);
this.install_action('kal.collection.update-ignored', null,
obj => obj.updateIgnored());
}
#col_group;
#settings;
#rows = [];
constructor(settings)
{
super({
title: _('Ignored collections'),
icon_name: 'view-list-symbolic'
});
this.#settings = settings;
this.#col_group =
new Adw.PreferencesGroup({
title: _('Ignored collections'),
description: _('Ignored collections will never be locked by this extensions.')
});
this.add(this.#col_group);
this.refreshCollections();
}
async refreshCollections()
{
try {
this.#rows.forEach(r => this.remove(r));
this.#rows = [];
const service =
await Secret.Service.get(Secret.ServiceFlags.LOAD_COLLECTIONS, null);
const collections = service.get_collections();
const known_aliases = [ 'default', 'login', 'session' ];
const path_to_aliases = {};
for (let i = 0; i < known_aliases.length; ++i) {
const alias = known_aliases[i];
try {
const col = await Secret.Collection.for_alias(service,
alias,
Secret.CollectionFlags.NONE,
null);
if (col) {
const path = col.get_object_path();
if (path_to_aliases[path])
path_to_aliases[path].push(alias);
else
path_to_aliases[path] = [alias];
}
}
catch (e) {
logError(e);
}
}
const ignored_collections =
this.#settings.get_value('ignored-collections').get_objv();
for (let i = 0; i < collections.length; ++i) {
const col = collections[i];
const path = col.get_object_path();
// never allow locking the 'session' collection, GNOME Keyring doesn't like it
const is_session = path_to_aliases[path]?.includes('session');
if (is_session)
continue;
const ignored = ignored_collections.includes(path);
const row = new CollectionRow(col, ignored, path_to_aliases[path]);
this.#col_group.add(row);
this.#rows.push(row);
}
}
catch (e) {
logError(e);
}
}
updateIgnored()
{
const ignored = this.#rows.filter(r => r.active).map(r => r.path);
this.#settings.set_value('ignored-collections',
GLib.Variant.new_objv(ignored));
}
};
class GeneralPage extends Adw.PreferencesPage {
static {
GObject.registerClass(this);
}
#check_spin;
#hide_switch;
#lock_spin;
#settings;
constructor(settings)
{
super({
title: _('General settings'),
icon_name: 'preferences-other-symbolic'
});
this.#settings = settings;
let indicator_group = new Adw.PreferencesGroup({
title: _('Indicator')
});
this.add(indicator_group);
let hide_row = new Adw.ActionRow({
title: _('Hide indicator if locked'),
tooltip_text: _('Keep the indicator icon hidden while the keyring is locked.')
});
indicator_group.add(hide_row);
this.#hide_switch = new Gtk.Switch({
valign: Gtk.Align.CENTER
});
hide_row.add_suffix(this.#hide_switch);
this.#settings.bind('hide-locked',
this.#hide_switch, 'active',
Gio.SettingsBindFlags.DEFAULT);
let timer_group = new Adw.PreferencesGroup({
title: _('Timers')
});
this.add(timer_group);
let check_row = new Adw.ActionRow({
title: _('Check interval (seconds)'),
tooltip_text: _('The keyring is checked periodically, to detect if it is unlocked.'),
});
timer_group.add(check_row);
this.#check_spin = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 1,
upper: 3600,
page_increment: 120,
step_increment: 30,
}),
width_chars: 6,
valign: Gtk.Align.CENTER
});
check_row.add_suffix(this.#check_spin);
this.#settings.bind('check-interval',
this.#check_spin, 'value',
Gio.SettingsBindFlags.DEFAULT);
let lock_row = new Adw.ActionRow({
title: _('Lock delay (seconds)'),
tooltip_text: _('How long the keyring is allowed to stay unlocked.'),
});
timer_group.add(lock_row);
this.#lock_spin = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({
lower: 0,
upper: 86400,
page_increment: 300,
step_increment: 60,
}),
width_chars: 6,
valign: Gtk.Align.CENTER
});
lock_row.add_suffix(this.#lock_spin);
this.#settings.bind('lock-delay',
this.#lock_spin, 'value',
Gio.SettingsBindFlags.DEFAULT);
}
};
export default
class KeyringAutolockPreferences extends ExtensionPreferences {
fillPreferencesWindow(window)
{
const settings = this.getSettings();
window.add(new GeneralPage(settings));
window.add(new IgnoredPage(settings));
}
};