-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
74 lines (58 loc) · 1.67 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
const St = imports.gi.St;
const Main = imports.ui.main;
const Lang = imports.lang;
const Util = imports.misc.util;
const PanelMenu = imports.ui.panelMenu;
const Mainloop = imports.mainloop;
const GLib = imports.gi.GLib;
const Clutter = imports.gi.Clutter;
const WgIndicator = new Lang.Class({
Name: 'WgIndicator',
Extends: PanelMenu.Button,
_init: function() {
this.parent(0.0, "WG Indicator", false);
this.buttonText = new St.Label({
text: _("Loading..."),
y_align: Clutter.ActorAlign.CENTER
});
this.actor.add_actor(this.buttonText);
this._refresh();
},
_checkWG: function() {
let [res, out, err, exit] = GLib.spawn_sync(null, ["/bin/bash", "-c", "ip a | grep wg0"], null, GLib.SpawnFlags.SEARCH_PATH, null);
return exit;
},
_refresh: function() {
this._refreshUI(this._checkWG());
if (this._timeout) {
Mainloop.source_remove(this._timeout);
this._timeout = null;
}
this._timeout = Mainloop.timeout_add_seconds(2, Lang.bind(this, this._refresh));
},
_refreshUI: function(data) {
var text;
if (data == 256) {
text = "wg0 down";
} else if (data == 0) {
text = "wg0 up";
} else {
text = "wg0 error";
}
this.buttonText.set_text(text);
}
});
let twMenu;
function init() {
}
function enable() {
twMenu = new WgIndicator;
Main.panel.addToStatusArea('wg-indicator', twMenu);
}
function disable() {
if (twMenu && twMenu._timeout) {
Mainloop.source_remove(twMenu._timeout);
}
twMenu.destroy();
twMenu = null;
}