-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathsettings.js
51 lines (42 loc) · 1.25 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
const INTERVAL_KEY = 'interval';
const HIDE_INDICATOR_KEY = 'hide-indicator';
const DEVICES_KEY = 'devices';
export class SettingsController {
constructor(settings) {
this._settings = settings;
}
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);
}
setDevices(devices) {
this._settings.set_strv(DEVICES_KEY, devices.map((device) => JSON.stringify({
name: device.name,
mac: device.mac,
icon: device.icon,
isActive: device.isActive,
})));
}
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);
}
}
}