From 3233c9322abd10cb787e2a83fb5cda3f59664869 Mon Sep 17 00:00:00 2001 From: Romain Vigier Date: Fri, 29 Jul 2022 08:41:38 +0200 Subject: [PATCH] Location Timer: Make GeoClue connection cancellable --- src/modules/TimerLocation.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/TimerLocation.js b/src/modules/TimerLocation.js index 8e45243..f9a5110 100644 --- a/src/modules/TimerLocation.js +++ b/src/modules/TimerLocation.js @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2020-2022 Romain Vigier // SPDX-License-Identifier: GPL-3.0-or-later -const { Geoclue, GLib } = imports.gi; +const { Geoclue, Gio, GLib } = imports.gi; const { extensionUtils } = imports.misc; const Signals = imports.signals; @@ -28,6 +28,7 @@ const { Time } = Me.imports.enums.Time; var TimerLocation = class { #suntimes; + #cancellable = null; #previouslyDaytime = null; #geoclue = null; #geoclueConnection = null; @@ -46,6 +47,7 @@ var TimerLocation = class { enable() { console.debug('Enabling Location Timer...'); + this.#cancellable = new Gio.Cancellable(); this.#connectToGeoclue(); this.#watchForTimeChange(); this.#regularlyUpdateSuntimes(); @@ -57,6 +59,8 @@ var TimerLocation = class { this.#stopRegularlyUpdatingSuntimes(); this.#stopWatchingForTimeChange(); this.#disconnectFromGeoclue(); + this.#cancellable.cancel(); + this.#cancellable = null; console.debug('Location Timer disabled.'); } @@ -71,7 +75,7 @@ var TimerLocation = class { Geoclue.Simple.new( 'org.gnome.Shell', Geoclue.AccuracyLevel.CITY, - null, + this.#cancellable, this.#onGeoclueReady.bind(this) ); }