From f4719e598e183d52ebab8b39ed25c11113c4c068 Mon Sep 17 00:00:00 2001 From: Lemmy Date: Wed, 1 Apr 2026 18:00:46 -0400 Subject: [PATCH] feat(location): removed the Tokyo default location, improved flow with the new auto-locate. --- Assets/settings-default.json | 2 +- Assets/settings-search-index.json | 21 ++++--- Commons/Settings.qml | 3 +- .../Settings/Tabs/Region/LocationSubTab.qml | 56 +++++++++---------- Services/Location/LocationService.qml | 7 ++- 5 files changed, 45 insertions(+), 44 deletions(-) diff --git a/Assets/settings-default.json b/Assets/settings-default.json index c0a00188e..3196ac10c 100644 --- a/Assets/settings-default.json +++ b/Assets/settings-default.json @@ -159,7 +159,7 @@ "settingsPanelSideBarCardStyle": false }, "location": { - "name": "Tokyo", + "name": "", "weatherEnabled": true, "weatherShowEffects": true, "useFahrenheit": false, diff --git a/Assets/settings-search-index.json b/Assets/settings-search-index.json index e1d0eeefe..f0e14de84 100644 --- a/Assets/settings-search-index.json +++ b/Assets/settings-search-index.json @@ -2183,15 +2183,6 @@ "subTab": 0, "subTabLabel": "common.location" }, - { - "labelKey": "panels.location.location-search-label", - "descriptionKey": "panels.location.location-search-description", - "widget": "NTextInput", - "tab": 17, - "tabLabel": "panels.region.title", - "subTab": 0, - "subTabLabel": "common.location" - }, { "labelKey": "panels.location.auto-locate-label", "descriptionKey": "panels.location.auto-locate-description", @@ -2201,6 +2192,18 @@ "subTab": 0, "subTabLabel": "common.location" }, + { + "labelKey": "panels.location.location-search-label", + "descriptionKey": "panels.location.location-search-description", + "widget": "NTextInput", + "tab": 17, + "tabLabel": "panels.region.title", + "subTab": 0, + "subTabLabel": "common.location", + "visibleWhen": [ + "!Settings.data.location.autoLocate" + ] + }, { "labelKey": "panels.location.weather-enabled-label", "descriptionKey": "panels.location.weather-enabled-description", diff --git a/Commons/Settings.qml b/Commons/Settings.qml index cfb575d2b..ab74f2ac3 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -32,7 +32,6 @@ Singleton { readonly property string cacheDir: ensureTrailingSlash(Quickshell.env("NOCTALIA_CACHE_DIR") || (Quickshell.env("XDG_CACHE_HOME") || Quickshell.env("HOME") + "/.cache") + "/" + shellName + "/") readonly property string settingsFile: Quickshell.env("NOCTALIA_SETTINGS_FILE") || (configDir + "settings.json") - readonly property string defaultLocation: "Tokyo" readonly property string defaultAvatar: Quickshell.env("HOME") + "/.face" readonly property string defaultVideosDirectory: Quickshell.env("HOME") + "/Videos" readonly property string defaultWallpapersDirectory: Quickshell.env("HOME") + "/Pictures/Wallpapers" @@ -340,7 +339,7 @@ Singleton { // location property JsonObject location: JsonObject { - property string name: defaultLocation + property string name: "" property bool weatherEnabled: true property bool weatherShowEffects: true property bool useFahrenheit: false diff --git a/Modules/Panels/Settings/Tabs/Region/LocationSubTab.qml b/Modules/Panels/Settings/Tabs/Region/LocationSubTab.qml index cc0894581..bac42536a 100644 --- a/Modules/Panels/Settings/Tabs/Region/LocationSubTab.qml +++ b/Modules/Panels/Settings/Tabs/Region/LocationSubTab.qml @@ -51,21 +51,38 @@ ColumnLayout { Layout.fillWidth: true spacing: Style.marginS - NTextInput { - Layout.maximumWidth: root.width / 2 + // Auto-locate + RowLayout { + Layout.fillWidth: true + spacing: Style.marginM + NToggle { + Layout.fillWidth: true + label: I18n.tr("panels.location.auto-locate-label") + description: I18n.tr("panels.location.auto-locate-description") + checked: Settings.data.location.autoLocate + onToggled: checked => Settings.data.location.autoLocate = checked + defaultValue: Settings.getDefaultValue("location.autoLocate") + } + + NButton { + text: I18n.tr("panels.location.geolocate-now-button") + icon: "current-location" + enabled: !LocationService.isFetchingWeather + onClicked: LocationService.geolocateAndApply() + } + } + + NTextInput { + visible: !Settings.data.location.autoLocate + Layout.maximumWidth: root.width / 2 label: I18n.tr("panels.location.location-search-label") description: I18n.tr("panels.location.location-search-description") - text: Settings.data.location.name || Settings.defaultLocation + text: Settings.data.location.name placeholderText: I18n.tr("panels.location.location-search-placeholder") onEditingFinished: { // Verify the location has really changed to avoid extra resets var newLocation = text.trim(); - // If empty, set to default location - if (newLocation === "") { - newLocation = Settings.defaultLocation; - text = Settings.defaultLocation; // Update the input field to show the default - } if (newLocation != Settings.data.location.name) { Settings.data.location.name = newLocation; LocationService.resetWeather(); @@ -80,28 +97,7 @@ ColumnLayout { }) : "" pointSize: Style.fontSizeS color: Color.mOnSurfaceVariant - } - } - - // Auto-locate - RowLayout { - Layout.fillWidth: true - spacing: Style.marginM - - NToggle { - Layout.fillWidth: true - label: I18n.tr("panels.location.auto-locate-label") - description: I18n.tr("panels.location.auto-locate-description") - checked: Settings.data.location.autoLocate - onToggled: checked => Settings.data.location.autoLocate = checked - defaultValue: Settings.getDefaultValue("location.autoLocate") - } - - NButton { - text: I18n.tr("panels.location.geolocate-now-button") - icon: "current-location" - enabled: !LocationService.isFetchingWeather - onClicked: LocationService.geolocateAndApply() + font.italic: true } } diff --git a/Services/Location/LocationService.qml b/Services/Location/LocationService.qml index 9b40c16a4..03b453425 100644 --- a/Services/Location/LocationService.qml +++ b/Services/Location/LocationService.qml @@ -137,7 +137,6 @@ Singleton { } if (isFetchingWeather) { - Logger.w("Location", "Location update already in progress"); return; } @@ -176,7 +175,6 @@ Singleton { } if (isFetchingWeather) { - Logger.w("Location", "Weather is still fetching"); return; } @@ -194,6 +192,11 @@ Singleton { // Query geocoding API to convert location name to coordinates function geocodeLocation(locationName, callback, errorCallback) { + if (locationName === "") { + isFetchingWeather = false; + return; + } + Logger.d("Location", "Geocoding location name"); var geoUrl = "https://api.noctalia.dev/geocode?city=" + encodeURIComponent(locationName); var xhr = new XMLHttpRequest();