From 40b57c2df0b82735e5917db47eea1372e72983d1 Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Wed, 3 Sep 2025 13:50:16 +0200 Subject: [PATCH] Weather: change how default city is set --- Commons/Settings.qml | 3 ++- Modules/SettingsPanel/Tabs/TimeWeatherTab.qml | 7 ++++++- Modules/SidePanel/Cards/WeatherCard.qml | 4 +--- Services/LocationService.qml | 10 +++------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Commons/Settings.qml b/Commons/Settings.qml index cb10f6f..feebe5d 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -25,6 +25,7 @@ Singleton { property string defaultAvatar: Quickshell.env("HOME") + "/.face" property string defaultWallpapersDirectory: Quickshell.env("HOME") + "/Pictures/Wallpapers" property string defaultVideosDirectory: Quickshell.env("HOME") + "/Videos" + property string defaultLocation: "Tokyo" // Used to access via Settings.data.xxx.yyy readonly property alias data: adapter @@ -157,7 +158,7 @@ Singleton { // location property JsonObject location: JsonObject { - property string name: "Tokyo" + property string name: defaultLocation property bool useFahrenheit: false property bool reverseDayMonth: false property bool use12HourClock: false diff --git a/Modules/SettingsPanel/Tabs/TimeWeatherTab.qml b/Modules/SettingsPanel/Tabs/TimeWeatherTab.qml index bcf577c..2fa89dd 100644 --- a/Modules/SettingsPanel/Tabs/TimeWeatherTab.qml +++ b/Modules/SettingsPanel/Tabs/TimeWeatherTab.qml @@ -16,11 +16,16 @@ ColumnLayout { NTextInput { label: "Location name" description: "Choose a known location near you." - text: Settings.data.location.name || "Tokyo" + text: Settings.data.location.name || Settings.defaultLocation placeholderText: "Enter the location name" 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() diff --git a/Modules/SidePanel/Cards/WeatherCard.qml b/Modules/SidePanel/Cards/WeatherCard.qml index 03df3b3..3751478 100644 --- a/Modules/SidePanel/Cards/WeatherCard.qml +++ b/Modules/SidePanel/Cards/WeatherCard.qml @@ -37,10 +37,8 @@ NBox { spacing: Style.marginXXS * scaling NText { text: { - // Use the location name or fallback to default if empty - const locationName = Settings.data.location.name || "Tokyo" // Ensure the name is not too long if one had to specify the country - const chunks = locationName.split(",") + const chunks = Settings.data.location.name.split(",") return chunks[0] } font.pointSize: Style.fontSizeL * scaling diff --git a/Services/LocationService.qml b/Services/LocationService.qml index e5858fa..cfea5d7 100644 --- a/Services/LocationService.qml +++ b/Services/LocationService.qml @@ -136,17 +136,13 @@ Singleton { Logger.log("Location", "Location changed from", adapter.name, "to", Settings.data.location.name) } - // Ensure we always have a location name, fallback to default if empty - const locationName = Settings.data.location.name && Settings.data.location.name.trim( - ) !== "" ? Settings.data.location.name : "Tokyo" - if ((adapter.latitude === "") || (adapter.longitude === "") || locationChanged) { - _geocodeLocation(locationName, function (latitude, longitude, name, country) { - Logger.log("Location", "Geocoded", locationName, "to:", latitude, "/", longitude) + _geocodeLocation(Settings.data.location.name, function (latitude, longitude, name, country) { + Logger.log("Location", "Geocoded", Settings.data.location.name, "to:", latitude, "/", longitude) // Save location name - adapter.name = locationName + adapter.name = Settings.data.location.name // Save GPS coordinates adapter.latitude = latitude.toString()