-
Notifications
You must be signed in to change notification settings - Fork 34
/
extension.js
60 lines (49 loc) · 1.57 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
const Main = imports.ui.main;
const GLib = imports.gi.GLib;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Convenience = Me.imports.convenience;
const Format = Me.imports.formatter;
var settings;
function init() {
settings = Convenience.getSettings();
}
function overrider(lbl) {
var FORMAT = settings.get_string("override-string");
var now = GLib.DateTime.new_now_local();
var desired = Format.format(FORMAT, now);
var t = lbl.get_text();
if (t != desired) {
last = t;
lbl.set_text(desired);
}
}
var lbl, signalHandlerID, last = "";
function enable() {
var sA = Main.panel._statusArea;
if (!sA) { sA = Main.panel.statusArea; }
if (!sA || !sA.dateMenu || !sA.dateMenu.actor) {
print("Looks like Shell has changed where things live again; aborting.");
return;
}
sA.dateMenu.actor.first_child.get_children().forEach(function(w) {
// assume that the text label is the first StLabel we find.
// This is dodgy behaviour but there's no reliable way to
// work out which it is.
w.set_style("text-align: center;");
if (w.get_text && !lbl) { lbl = w; }
});
if (!lbl) {
print("Looks like Shell has changed where things live again; aborting.");
return;
}
signalHandlerID = lbl.connect("notify::text", overrider);
last = lbl.get_text();
overrider(lbl);
}
function disable() {
if (lbl && signalHandlerID) {
lbl.disconnect(signalHandlerID);
lbl.set_text(last);
}
}