forked from eliapasquali/power-profile-switcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prefs.js
62 lines (48 loc) · 1.55 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
const { Adw, GLib, GObject, Gio } = imports.gi;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const PROFILE_CHOICES = [
'performance',
'balanced',
'power-saver'
];
function bindAdwComboRow(comboRow, settings, key, map_) {
const initValue = settings.get_string(key);
comboRow.selected = map_.indexOf(initValue);
settings.connect(
`changed::${key}`, () => {
const idx = map_.indexOf(settings.get_string(key));
comboRow.selected = idx;
}
);
comboRow.connect('notify::selected', () => {
const value = map_[comboRow.selected];
settings.set_string(key, value);
});
}
var General = GObject.registerClass({
GTypeName: 'GeneralPreferences',
Template: `file://${GLib.build_filenamev([Me.path, 'ui', 'general.ui'])}`,
InternalChildren: [
'ac_profile',
'bat_profile',
'threshold',
],
}, class General extends Adw.PreferencesPage {
constructor(settings) {
super({});
bindAdwComboRow(this._ac_profile, settings, 'ac', PROFILE_CHOICES);
bindAdwComboRow(this._bat_profile, settings, 'bat', PROFILE_CHOICES);
settings.bind(
'threshold',
this._threshold,
'value',
Gio.SettingsBindFlags.DEFAULT
);
}
});
function init() {}
function fillPreferencesWindow(window) {
const settings = ExtensionUtils.getSettings("org.gnome.shell.extensions.power-profile-switcher");
window.add(new General(settings));
}