forked from RensAlthuis/vertical-overview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
75 lines (62 loc) · 2.35 KB
/
util.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
63
64
65
66
67
68
69
70
71
72
73
74
75
import Gio from 'gi://Gio';
import {InjectionManager} from 'resource:///org/gnome/shell/extensions/extension.js';
const GioSSS = Gio.SettingsSchemaSource;
const _injectionManager = new InjectionManager();
export function overrideProto(proto, overrides) {
const backup = {};
for (var symbol in overrides) {
if (symbol.startsWith('after_')) {
const actualSymbol = symbol.slice('after_'.length);
const fn = proto[actualSymbol];
const afterFn = overrides[symbol]
proto[actualSymbol] = function() {
const args = Array.prototype.slice.call(arguments);
const res = fn.apply(this, args);
afterFn.apply(this, args);
return res;
};
backup[actualSymbol] = fn;
}
else {
backup[symbol] = proto[symbol];
const override = overrides[symbol]
if (symbol.startsWith('vfunc')) {
_injectionManager.overrideMethod(proto, /*'vfunc_' + */symbol,
(originalAllocate) => override);
}
else {
proto[symbol] = overrides[symbol];
}
}
}
return backup;
}
export function bindSetting(label, callback, executeOnBind = true, getSettings) {
let settings = global.vertical_overview.settings;
if (!settings) {
settings = global.vertical_overview.settings = {
object: getSettings('org.gnome.shell.extensions.vertical-overview'),
signals: {},
callbacks: {}
};
}
if (settings.signals[label])
settings.object.disconnectObject(settings.signals[label]);
const signal = global.vertical_overview.settings.object.connectObject('changed::' + label, callback);
global.vertical_overview.settings.signals[label] = signal;
settings.callbacks[label] = callback;
if (executeOnBind) callback(settings.object, label);
return signal;
}
export function unbindSetting(label, callback) {
let settings = global.vertical_overview.settings;
if (!settings || !settings.signals[label])
return;
if (callback)
callback(settings.object, label);
settings.object.disconnectObject(settings.signals[label]);
delete settings.signals[label];
if (settings.callbacks[label]) {
delete settings.callbacks[label];
}
}