Location source: Make offset a setting
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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
|
SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
-->
|
-->
|
||||||
<schemalist gettext-domain="nightthemeswitcher@romainvigier.fr">
|
<schemalist gettext-domain="nightthemeswitcher@romainvigier.fr">
|
||||||
@@ -83,5 +83,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
<key name="location-sunset" type="d">
|
<key name="location-sunset" type="d">
|
||||||
<default>20</default>
|
<default>20</default>
|
||||||
</key>
|
</key>
|
||||||
|
<key name="offset" type="d">
|
||||||
|
<default>0.4</default>
|
||||||
|
</key>
|
||||||
</schema>
|
</schema>
|
||||||
</schemalist>
|
</schemalist>
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ var SourceLocation = class extends Source {
|
|||||||
#geoclueConnection = null;
|
#geoclueConnection = null;
|
||||||
#timeChangeTimer = null;
|
#timeChangeTimer = null;
|
||||||
#regularlyUpdateSuntimesTimer = null;
|
#regularlyUpdateSuntimesTimer = null;
|
||||||
|
#settingsConnections = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@@ -46,6 +47,7 @@ var SourceLocation = class extends Source {
|
|||||||
super.enable();
|
super.enable();
|
||||||
debug.message('Enabling Location source...');
|
debug.message('Enabling Location source...');
|
||||||
this.#cancellable = new Gio.Cancellable();
|
this.#cancellable = new Gio.Cancellable();
|
||||||
|
this.#connectSettings();
|
||||||
this.#connectToGeoclue();
|
this.#connectToGeoclue();
|
||||||
this.#watchForTimeChange();
|
this.#watchForTimeChange();
|
||||||
this.#regularlyUpdateSuntimes();
|
this.#regularlyUpdateSuntimes();
|
||||||
@@ -58,6 +60,7 @@ var SourceLocation = class extends Source {
|
|||||||
this.#stopRegularlyUpdatingSuntimes();
|
this.#stopRegularlyUpdatingSuntimes();
|
||||||
this.#stopWatchingForTimeChange();
|
this.#stopWatchingForTimeChange();
|
||||||
this.#disconnectFromGeoclue();
|
this.#disconnectFromGeoclue();
|
||||||
|
this.#disconnectSettings();
|
||||||
this.#cancellable.cancel();
|
this.#cancellable.cancel();
|
||||||
this.#cancellable = null;
|
this.#cancellable = null;
|
||||||
debug.message('Location source disabled.');
|
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() {
|
#connectToGeoclue() {
|
||||||
debug.message('Connecting to GeoClue...');
|
debug.message('Connecting to GeoClue...');
|
||||||
Geoclue.Simple.new(
|
Geoclue.Simple.new(
|
||||||
@@ -163,7 +181,7 @@ var SourceLocation = class extends Source {
|
|||||||
const timeSunrise = solarNoon - haSunrise * 4 / 1440;
|
const timeSunrise = solarNoon - haSunrise * 4 / 1440;
|
||||||
const timeSunset = 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 sunrise = timeSunrise * 24 + offset;
|
||||||
const sunset = timeSunset * 24 - offset;
|
const sunset = timeSunset * 24 - offset;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user