This repository has been archived by the owner on Mar 14, 2022. It is now read-only.
forked from MichalW/gnome-bluetooth-battery-indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.js
54 lines (43 loc) · 1.38 KB
/
settings.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
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const { SETTINGS_ID } = Me.imports.constants;
const INTERVAL_KEY = 'interval';
const HIDE_INDICATOR_KEY = 'hide-indicator';
const DEVICES_KEY = 'devices';
var SettingsController = class SettingsController {
constructor() {
this._settings = ExtensionUtils.getSettings(SETTINGS_ID);
}
getInterval() {
return this._settings.get_int(INTERVAL_KEY);
}
setInterval(interval) {
this._settings.set_int(INTERVAL_KEY, interval);
}
getHideIndicator() {
return this._settings.get_boolean(HIDE_INDICATOR_KEY);
}
setHideIndicator(value) {
this._settings.set_boolean(HIDE_INDICATOR_KEY, value);
}
getDevices() {
return this._settings.get_strv(DEVICES_KEY).map(JSON.parse);
}
getPairedDevices() {
return this.getDevices().filter(({ isPaired }) => isPaired);
}
setDevices(devices) {
this._settings.set_strv(DEVICES_KEY, devices.map(JSON.stringify));
}
setDevice(device) {
const devices = this.getDevices();
const indexOf = devices.findIndex(({ mac }) => device.mac === mac);
if (indexOf !== -1) {
devices[indexOf] = {
...devices[indexOf],
...device,
};
this.setDevices(devices);
}
}
}