-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathextension.js
60 lines (50 loc) · 1.66 KB
/
extension.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
import * as modsList from './src/modsList.js'
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
export default class extends Extension {
_refresh_mod(name) {
if (!this.available_mods[name]) return
let enabled, settings = false
const value = this.settings.get_value(name)
switch (value.get_type_string()) {
case "s":
if (this.mods[name]) { //disable
this.mods[name].disable()
delete this.mods[name]
}
settings = this.settings.get_enum(name)
enabled = true
break
default:
enabled = this.settings.get_boolean(name)
}
if (enabled) { // enable
if (this.mods[name]) return
const mod = new this.available_mods[name](settings)
mod.enable()
this.mods[name] = mod
} else if (this.mods[name]) { //disable
this.mods[name].disable()
delete this.mods[name]
}
}
enable() {
this.available_mods = modsList.get()
this.mods = {}
this.settings = this.getSettings()
Object.keys(this.available_mods).forEach(name => {
this.settings.connect('changed::' + name, () => {
this._refresh_mod(name)
});
this._refresh_mod(name)
})
}
disable() {
for (const key in this.mods) {
if (!this.mods.hasOwnProperty(key)) continue;
this.mods[key].disable()
}
delete this.available_mods
delete this.mods
delete this.settings
}
}