From 23daca0b574cb1f311124dc78b988d929d4d9466 Mon Sep 17 00:00:00 2001 From: bbedward Date: Tue, 21 Jul 2026 23:34:12 -0400 Subject: [PATCH] location: prevent calls when weather auto-locate is disabled port 1.5 (cherry picked from commit fe561f2b5d42c6718cc91c12556b6651eb55c23b) --- quickshell/Services/DMSService.qml | 2 +- quickshell/Services/LocationService.qml | 46 +++++++++++++++++++++---- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/quickshell/Services/DMSService.qml b/quickshell/Services/DMSService.qml index 331023837..a159fa96c 100644 --- a/quickshell/Services/DMSService.qml +++ b/quickshell/Services/DMSService.qml @@ -69,7 +69,7 @@ Singleton { property bool screensaverInhibited: false property var screensaverInhibitors: [] - property var activeSubscriptions: ["network", "network.credentials", "loginctl", "freedesktop", "freedesktop.screensaver", "gamma", "theme.auto", "wallpaper", "bluetooth", "bluetooth.pairing", "brightness", "wlroutput", "evdev", "browser", "dbus", "clipboard", "location", "sysupdate"] + property var activeSubscriptions: ["network", "network.credentials", "loginctl", "freedesktop", "freedesktop.screensaver", "gamma", "theme.auto", "wallpaper", "bluetooth", "bluetooth.pairing", "brightness", "wlroutput", "evdev", "browser", "dbus", "clipboard", "sysupdate"] Component.onCompleted: { if (socketPath && socketPath.length > 0) { diff --git a/quickshell/Services/LocationService.qml b/quickshell/Services/LocationService.qml index e6e8ac56b..dff268911 100644 --- a/quickshell/Services/LocationService.qml +++ b/quickshell/Services/LocationService.qml @@ -3,10 +3,13 @@ pragma ComponentBehavior: Bound import QtQuick import Quickshell +import qs.Common +import qs.Services Singleton { id: root + readonly property bool wantsLocation: SettingsData.weatherEnabled && SettingsData.useAutoLocation readonly property bool locationAvailable: DMSService.isConnected && DMSService.capabilities.includes("location") readonly property bool valid: latitude !== 0 || longitude !== 0 @@ -15,19 +18,46 @@ Singleton { signal locationChanged(var data) - onLocationAvailableChanged: { - if (locationAvailable && !valid) - getState(); + onWantsLocationChanged: { + if (wantsLocation) { + ensureSubscription(); + } else if (DMSService.activeSubscriptions.includes("location")) { + DMSService.removeSubscription("location"); + } } + onLocationAvailableChanged: ensureSubscription() + + Component.onCompleted: ensureSubscription() + Connections { target: DMSService - function onLocationStateUpdate(data) { - if (!locationAvailable) - return; - handleStateUpdate(data); + function onConnectionStateChanged() { + if (DMSService.isConnected) + root.ensureSubscription(); } + + function onLocationStateUpdate(data) { + if (!root.wantsLocation) + return; + root.handleStateUpdate(data); + } + } + + function ensureSubscription() { + if (!wantsLocation) + return; + if (!locationAvailable) + return; + if (DMSService.activeSubscriptions.includes("location")) + return; + if (DMSService.activeSubscriptions.includes("all")) + return; + + DMSService.addSubscription("location"); + if (!valid) + getState(); } function handleStateUpdate(data) { @@ -42,6 +72,8 @@ Singleton { } function getState() { + if (!wantsLocation) + return; if (!locationAvailable) return;