Night Light Timer: Reduce D-Bus calls

This commit is contained in:
Romain Vigier
2022-08-16 01:26:00 +02:00
parent 0a18075787
commit 3a0d9036d3
+6 -5
View File
@@ -34,7 +34,7 @@ var TimerNightlight = class {
#colorDbusProxy = null;
#settingsConnections = [];
#nightlightStateConnection = null;
#previousNightlightActive = null;
#previousNightlightState = null;
constructor() {
this.#settings = extensionUtils.getSettings(utils.getSettingsSchema('time'));
@@ -124,10 +124,11 @@ var TimerNightlight = class {
}
#onNightlightStateChanged(_sender, _dbusProperties) {
if (this.#isNightlightActive() !== this.#previousNightlightActive) {
console.debug(`Night Light has become ${this.#isNightlightActive() ? '' : 'in'}active.`);
this.#previousNightlightActive = this.#isNightlightActive();
this.emit('time-changed', this.time);
const newState = this.#isNightlightActive();
if (newState !== this.#previousNightlightState) {
console.debug(`Night Light has become ${newState ? '' : 'in'}active.`);
this.#previousNightlightState = newState;
this.emit('time-changed', newState ? Time.NIGHT : Time.DAY);
}
}