From b340033a06c32c5107c1ce44cf2c0378d5b3a3f3 Mon Sep 17 00:00:00 2001 From: Romain Vigier Date: Thu, 10 Feb 2022 11:48:03 +0100 Subject: [PATCH] Set color-scheme key when changing time --- src/modules/Timer.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/modules/Timer.js b/src/modules/Timer.js index 4083e48..392e7f6 100644 --- a/src/modules/Timer.js +++ b/src/modules/Timer.js @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2020, 2021 Romain Vigier +// SPDX-FileCopyrightText: 2020-2022 Romain Vigier // SPDX-License-Identifier: GPL-3.0-or-later const { Gio } = imports.gi; @@ -34,12 +34,13 @@ const { TimerOndemand } = Me.imports.modules.TimerOndemand; var Timer = class { constructor() { this._timeSettings = extensionUtils.getSettings(utils.getSettingsSchema('time')); + this._interfaceSettings = new Gio.Settings({ schema: 'org.gnome.desktop.interface' }); this._colorSettings = new Gio.Settings({ schema: 'org.gnome.settings-daemon.plugins.color' }); this._locationSettings = new Gio.Settings({ schema: 'org.gnome.system.location' }); this._sources = []; - this._previousTime = Time.UNKNOWN; this._settingsConnections = []; this._timeConnections = []; + this._previousTime = this._interfaceSettings.get_string('color-scheme') === 'prefer-dark' ? Time.NIGHT : Time.DAY; } enable() { @@ -64,6 +65,15 @@ var Timer = class { return this._previousTime; } + set time(time) { + if (time === this._previousTime) + return; + console.debug(`Time has changed to ${time}.`); + this._previousTime = time; + this._interfaceSettings.set_string('color-scheme', time === Time.NIGHT ? 'prefer-dark' : 'default'); + this.emit('time-changed', time); + } + _connectSettings() { console.debug('Connecting Timer to settings...'); @@ -87,6 +97,10 @@ var Timer = class { settings: this._timeSettings, id: this._timeSettings.connect('changed::time-source', this._onTimeSourceChanged.bind(this)), }); + this._settingsConnections.push({ + settings: this._interfaceSettings, + id: this._interfaceSettings.connect('changed::color-scheme', this._onColorSchemeChanged.bind(this)), + }); } _disconnectSettings() { @@ -151,11 +165,11 @@ var Timer = class { } _onTimeChanged(_source, newTime) { - if (newTime !== this._previousTime) { - console.debug(`Time has changed to ${newTime}.`); - this._previousTime = newTime; - this.emit('time-changed', newTime); - } + this.time = newTime; + } + + _onColorSchemeChanged() { + this.time = this._interfaceSettings.get_string('color-scheme') === 'prefer-dark' ? Time.NIGHT : Time.DAY; }