-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathprefs.js
59 lines (51 loc) · 1.67 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
import Adw from 'gi://Adw';
import GLib from 'gi://GLib';
import GObject from 'gi://GObject';
import Gio from 'gi://Gio';
import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';
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: 'PowerProfileSwitcherPreferences',
Template: GLib.Uri.resolve_relative(import.meta.url, './ui/general.ui', GLib.UriFlags.NONE),
InternalChildren: [
'ac_profile',
'bat_profile',
'threshold',
],
}, class General extends Adw.PreferencesPage {
_init(settings, params = {}) {
super._init(params);
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
);
}
});
export default class PowerProfileSwitcherPreferences extends ExtensionPreferences {
fillPreferencesWindow(window) {
const settings = this.getSettings();
window.add(new General(settings));
}
}