-
Notifications
You must be signed in to change notification settings - Fork 3
/
extension.js
77 lines (62 loc) · 2.32 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Simple Toogle Button Extension
const TOGGLE_SCRIPT_PATH='.local/share/gnome-shell/extensions/[email protected]/scaletoggle.py' // relative to home
const { Clutter, GObject, St, Gio } = imports.gi;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const TOGGLE_ON_ICON = 'computer-symbolic';
const TOGGLE_OFF_ICON = 'video-display-symbolic';
const Indicator = GObject.registerClass(
class Indicator extends PanelMenu.Button {
_init () {
super._init(0.0, 'Scale Toggle Button');
this._icon = new St.Icon({
icon_name: 'video-display-symbolic',
style_class: 'system-status-icon',
});
this.add_child(this._icon);
this.connect('event', this._onClicked.bind(this));
}
_onClicked(actor, event) {
if ((event.type() !== Clutter.EventType.TOUCH_BEGIN && event.type() !== Clutter.EventType.BUTTON_PRESS)) {
// Some other non-clicky event happened; bail
return Clutter.EVENT_PROPAGATE;
}
// Hopefully, I can figure out how to do this with imports.gi.Gio.DBus/DBusProxy in the future or even better without dbus entirely.
let proc = Gio.Subprocess.new(['python3', TOGGLE_SCRIPT_PATH], Gio.SubprocessFlags.NONE);
proc.wait_check_async(null, (proc, result) => {
try {
if (proc.wait_check_finish(result)) {
log(`Successfully ran ${TOGGLE_SCRIPT_PATH}`);
} else {
log(`Failed running ${TOGGLE_SCRIPT_PATH}`);
}
} catch (e) {
logError(e);
}
});
if (this._icon.icon_name === TOGGLE_ON_ICON) {
this._icon.icon_name = TOGGLE_OFF_ICON;
log('Toggle has been turned off!');
} else {
this._icon.icon_name = TOGGLE_ON_ICON;
log('Toggle has been turned on!');
}
return Clutter.EVENT_PROPAGATE;
}
});
class Extension {
constructor(uuid) {
this._uuid = uuid;
}
enable() {
this._indicator = new Indicator();
Main.panel.addToStatusArea(this._uuid, this._indicator);
}
disable() {
this._indicator.destroy();
this._indicator = null;
}
}
function init(meta) {
return new Extension(meta.uuid);
}