From 6cff754db81060a72928e6721589661c71f5117b Mon Sep 17 00:00:00 2001 From: Romain Vigier Date: Thu, 8 Sep 2022 09:41:40 +0200 Subject: [PATCH] Location source: Make offset a setting --- ....extensions.nightthemeswitcher.gschema.xml | 5 ++++- src/modules/SourceLocation.js | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml b/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml index 2629bc3..f43d8f6 100644 --- a/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml +++ b/src/data/org.gnome.shell.extensions.nightthemeswitcher.gschema.xml @@ -1,6 +1,6 @@ @@ -83,5 +83,8 @@ SPDX-License-Identifier: GPL-3.0-or-later 20 + + 0.4 + diff --git a/src/modules/SourceLocation.js b/src/modules/SourceLocation.js index 766fec3..5ca945a 100644 --- a/src/modules/SourceLocation.js +++ b/src/modules/SourceLocation.js @@ -36,6 +36,7 @@ var SourceLocation = class extends Source { #geoclueConnection = null; #timeChangeTimer = null; #regularlyUpdateSuntimesTimer = null; + #settingsConnections = []; constructor() { super(); @@ -46,6 +47,7 @@ var SourceLocation = class extends Source { super.enable(); debug.message('Enabling Location source...'); this.#cancellable = new Gio.Cancellable(); + this.#connectSettings(); this.#connectToGeoclue(); this.#watchForTimeChange(); this.#regularlyUpdateSuntimes(); @@ -58,6 +60,7 @@ var SourceLocation = class extends Source { this.#stopRegularlyUpdatingSuntimes(); this.#stopWatchingForTimeChange(); this.#disconnectFromGeoclue(); + this.#disconnectSettings(); this.#cancellable.cancel(); this.#cancellable = null; debug.message('Location source disabled.'); @@ -70,6 +73,21 @@ var SourceLocation = class extends Source { } + #connectSettings() { + debug.message('Connecting Location source to settings...'); + this.#settingsConnections.push({ + settings: this.#settings, + id: this.#settings.connect('changed::offset', this.#updateSuntimes.bind(this)), + }); + } + + #disconnectSettings() { + this.#settingsConnections.forEach(({ settings, id }) => settings.disconnect(id)); + this.#settingsConnections = []; + debug.message('Disconnected Location source from settings.'); + } + + #connectToGeoclue() { debug.message('Connecting to GeoClue...'); Geoclue.Simple.new( @@ -163,7 +181,7 @@ var SourceLocation = class extends Source { const timeSunrise = solarNoon - haSunrise * 4 / 1440; const timeSunset = solarNoon + haSunrise * 4 / 1440; - const offset = 0.4; + const offset = this.#settings.get_double('offset'); const sunrise = timeSunrise * 24 + offset; const sunset = timeSunset * 24 - offset;