Location Timer: Make GeoClue connection cancellable

This commit is contained in:
Romain Vigier
2022-08-16 01:26:00 +02:00
parent 3a0d9036d3
commit 3233c9322a
+6 -2
View File
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2020-2022 Romain Vigier <contact AT romainvigier.fr> // SPDX-FileCopyrightText: 2020-2022 Romain Vigier <contact AT romainvigier.fr>
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
const { Geoclue, GLib } = imports.gi; const { Geoclue, Gio, GLib } = imports.gi;
const { extensionUtils } = imports.misc; const { extensionUtils } = imports.misc;
const Signals = imports.signals; const Signals = imports.signals;
@@ -28,6 +28,7 @@ const { Time } = Me.imports.enums.Time;
var TimerLocation = class { var TimerLocation = class {
#suntimes; #suntimes;
#cancellable = null;
#previouslyDaytime = null; #previouslyDaytime = null;
#geoclue = null; #geoclue = null;
#geoclueConnection = null; #geoclueConnection = null;
@@ -46,6 +47,7 @@ var TimerLocation = class {
enable() { enable() {
console.debug('Enabling Location Timer...'); console.debug('Enabling Location Timer...');
this.#cancellable = new Gio.Cancellable();
this.#connectToGeoclue(); this.#connectToGeoclue();
this.#watchForTimeChange(); this.#watchForTimeChange();
this.#regularlyUpdateSuntimes(); this.#regularlyUpdateSuntimes();
@@ -57,6 +59,8 @@ var TimerLocation = class {
this.#stopRegularlyUpdatingSuntimes(); this.#stopRegularlyUpdatingSuntimes();
this.#stopWatchingForTimeChange(); this.#stopWatchingForTimeChange();
this.#disconnectFromGeoclue(); this.#disconnectFromGeoclue();
this.#cancellable.cancel();
this.#cancellable = null;
console.debug('Location Timer disabled.'); console.debug('Location Timer disabled.');
} }
@@ -71,7 +75,7 @@ var TimerLocation = class {
Geoclue.Simple.new( Geoclue.Simple.new(
'org.gnome.Shell', 'org.gnome.Shell',
Geoclue.AccuracyLevel.CITY, Geoclue.AccuracyLevel.CITY,
null, this.#cancellable,
this.#onGeoclueReady.bind(this) this.#onGeoclueReady.bind(this)
); );
} }