forked from dnohales/battery-percentage-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
40 lines (32 loc) · 964 Bytes
/
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
const Lang = imports.lang;
const Clutter = imports.gi.Clutter;
const St = imports.gi.St;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const Power = imports.ui.status.power;
let percentageText;
let signalId;
function init() {
}
function getPower() {
return Main.panel.statusArea["aggregateMenu"]._power;
}
function _onPowerChanged() {
if (this._proxy.IsPresent) {
percentageText.set_text("%d%%".format(this._proxy.Percentage));
percentageText.show();
} else {
percentageText.hide();
}
}
function enable() {
let power = getPower();
percentageText = new St.Label({ text: "", y_align: Clutter.ActorAlign.CENTER });
power.indicators.add_child(percentageText);
signalId = power._proxy.connect('g-properties-changed', Lang.bind(power, _onPowerChanged));
_onPowerChanged.call(power);
}
function disable() {
percentageText.destroy();
getPower()._proxy.disconnect(signalId);
}