-
Notifications
You must be signed in to change notification settings - Fork 3
/
extension.js
57 lines (46 loc) · 1.43 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
/* eslint-disable no-undef */
const Lang = imports.lang
const Main = imports.ui.main
const ExtensionUtils = imports.misc.extensionUtils
const Gettext = imports.gettext
/* eslint-enable no-undef */
const myUuid = 'Fuzzy_Clock@dallagi'
const Me = ExtensionUtils.getCurrentExtension()
Gettext.textdomain(myUuid)
const _ = Gettext.gettext
const FuzzyTime = Me.imports.lib.fuzzyTime.FuzzyTime
class FuzzyClock {
constructor () {
this.clockLabel = this._clockLabel()
}
enable () {
global.log('Enabling fuzzy clock.')
this.signalID = this.clockLabel.connect('notify::text', Lang.bind(this, this.setText))
this.setText()
}
disable () {
global.log('Disabling fuzzy clock.')
this.clockLabel.disconnect(this.signalID)
this.clockLabel.set_text(this.originalText)
}
setText () {
const currentText = this.clockLabel.get_text()
const fuzzyTime = new FuzzyTime(_).toString()
if (fuzzyTime === currentText) {
return
}
global.log('Updating fuzzy time.')
this.originalText = currentText
this.clockLabel.set_text(fuzzyTime)
}
_clockLabel () {
const statusArea = Main.panel.statusArea
return statusArea.dateMenu.label_actor
}
}
function init (meta) { // eslint-disable-line no-unused-vars
const localeDir = meta.dir.get_child('locale')
global.log(myUuid + ' localeDir: ' + localeDir.get_path())
Gettext.bindtextdomain(myUuid, localeDir.get_path())
return new FuzzyClock()
}