Skip to content

Commit 741f6d9

Browse files
committed
remove unused & deprecated imports; prettify timer respawns;
1 parent abf4532 commit 741f6d9

File tree

2 files changed

+3
-15
lines changed

2 files changed

+3
-15
lines changed

extension.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const Lang = imports.lang;
2-
const UPower = imports.gi.UPowerGlib;
31
const BaseIndicator = imports.ui.status.power.Indicator;
42
const ExtensionUtils = imports.misc.extensionUtils;
53
const Panel = imports.ui.main.panel;
@@ -28,9 +26,7 @@ var TPIndicator = GObject.registerClass(
2826
super._init();
2927

3028
this.settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.tp_wattmeter');
31-
32-
// to detect changes FIXME: a better way?
33-
this.last_period_val = this.settings.get_double('period-sec');
29+
this.settings.connect('changed::period-sec', () => { this._spawn(); }); // restart timers on setting change
3430

3531
this.readings = [];
3632
this.last_value = 0.0;
@@ -71,13 +67,6 @@ var TPIndicator = GObject.registerClass(
7167
const power = parseFloat(this._read_file(POWER_NOW), 0) / 1000000;
7268
this.readings.push(power)
7369

74-
const period_now = this.settings.get_double('period-sec');
75-
if (period_now.toFixed(1) != this.last_period_val.toFixed(1)) {
76-
// period changed, re-spawn
77-
this._spawn();
78-
this.last_period_val = period_now;
79-
};
80-
8170
const avg_of = this.settings.get_int('avg-of');
8271
if (this.readings.length >= avg_of) {
8372
this.last_value = this.readings.reduce((acc, elem) => acc + elem, 0.0) / this.readings.length; // simple mean
@@ -94,12 +83,13 @@ var TPIndicator = GObject.registerClass(
9483
this.tm_measure = GLib.timeout_add(
9584
GLib.PRIORITY_DEFAULT,
9685
this.settings.get_double('period-sec') * 1000,
97-
Lang.bind(this, this._measure)
86+
this._measure.bind(this),
9887
);
9988
}
10089

10190
_stop() {
10291
GLib.source_remove(this.tm_measure);
92+
this.tm_measure = null;
10393
}
10494
}
10595
);

metadata.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
"url": "https://github.com/gistart/tp_wattmeter",
55
"description": "Shows battery power consumption of ThinkPad laptops. Now configurable!",
66
"shell-version": [
7-
"40",
8-
"41",
97
"42"
108
]
119
}

0 commit comments

Comments
 (0)