/
applet.js
60 lines (51 loc) · 1.55 KB
/
applet.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
const Applet = imports.ui.applet;
const Util = imports.misc.util;
const PATH = "~/.local/share/cinnamon/applets/cats-lock@cinnamon.org";
const STATES = {
unlocked: {
desc: "Keyboard UNLOCKED. Click here to lock",
icon: "cat",
response: "disable keyboard",
},
locked: {
desc: "Keyboard LOCKED. Click here to unlock",
icon: "cat-locked",
response: "enable keyboard",
},
};
let self = null;
function CatsLock(orientation, panel_height, instance_id) {
this._init(orientation, panel_height, instance_id);
}
CatsLock.prototype = {
__proto__: Applet.IconApplet.prototype,
_init: function (orientation, panel_height, instance_id) {
Applet.IconApplet.prototype._init.call(
this,
orientation,
panel_height,
instance_id
);
self = this;
this.set_applet_icon_name(STATES.unlocked.icon);
this.set_applet_tooltip(_(STATES.unlocked.desc));
},
on_applet_clicked: function () {
Util.spawnCommandLineAsyncIO(
"sh " + PATH + "/cmd.sh",
function (stdOut, stdErr) {
if (stdOut.indexOf(STATES.locked.response) > -1) {
self.set_applet_icon_name(STATES.unlocked.icon);
self.set_applet_tooltip(_(STATES.unlocked.desc));
}
if (stdOut.indexOf(STATES.unlocked.response) > -1) {
self.set_applet_icon_name(STATES.locked.icon);
self.set_applet_tooltip(_(STATES.locked.desc));
}
}
);
},
};
function main(metadata, orientation, panel_height, instance_id) {
return new CatsLock(orientation, panel_height, instance_id);
}