Location source: Make offset a setting

This commit is contained in:
Romain Vigier
2022-09-08 09:42:46 +02:00
parent 016e1703cf
commit 6cff754db8
2 changed files with 23 additions and 2 deletions
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
SPDX-FileCopyrightText: 2021 Romain Vigier <contact AT romainvigier.fr>
SPDX-FileCopyrightText: 2021-2022 Romain Vigier <contact AT romainvigier.fr>
SPDX-License-Identifier: GPL-3.0-or-later
-->
<schemalist gettext-domain="nightthemeswitcher@romainvigier.fr">
@@ -83,5 +83,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
<key name="location-sunset" type="d">
<default>20</default>
</key>
<key name="offset" type="d">
<default>0.4</default>
</key>
</schema>
</schemalist>
+19 -1
View File
@@ -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;