From 54d8ca450f68c6958479397b598182c9d15c0285 Mon Sep 17 00:00:00 2001 From: bbedward Date: Tue, 5 Aug 2025 07:34:46 -0400 Subject: [PATCH] weather auto location option --- Common/Prefs.qml | 8 ++++++++ Modules/Settings/TimeWeatherTab.qml | 11 +++++++++++ Services/WeatherService.qml | 28 +++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Common/Prefs.qml b/Common/Prefs.qml index 1c0fcd9a..83cebd70 100644 --- a/Common/Prefs.qml +++ b/Common/Prefs.qml @@ -25,6 +25,7 @@ Singleton { property string profileImage: "" property string weatherLocation: "New York, NY" property string weatherCoordinates: "40.7128,-74.0060" + property bool useAutoLocation: false property bool showLauncherButton: true property bool showWorkspaceSwitcher: true property bool showFocusedWindow: true @@ -149,6 +150,7 @@ Singleton { profileImage = settings.profileImage !== undefined ? settings.profileImage : ""; weatherLocation = settings.weatherLocation !== undefined ? settings.weatherLocation : "New York, NY"; weatherCoordinates = settings.weatherCoordinates !== undefined ? settings.weatherCoordinates : "40.7128,-74.0060"; + useAutoLocation = settings.useAutoLocation !== undefined ? settings.useAutoLocation : false; showLauncherButton = settings.showLauncherButton !== undefined ? settings.showLauncherButton : true; showWorkspaceSwitcher = settings.showWorkspaceSwitcher !== undefined ? settings.showWorkspaceSwitcher : true; showFocusedWindow = settings.showFocusedWindow !== undefined ? settings.showFocusedWindow : true; @@ -230,6 +232,7 @@ Singleton { "profileImage": profileImage, "weatherLocation": weatherLocation, "weatherCoordinates": weatherCoordinates, + "useAutoLocation": useAutoLocation, "showLauncherButton": showLauncherButton, "showWorkspaceSwitcher": showWorkspaceSwitcher, "showFocusedWindow": showFocusedWindow, @@ -568,6 +571,11 @@ Singleton { saveSettings(); } + function setAutoLocation(enabled) { + useAutoLocation = enabled; + saveSettings(); + } + // Network preference setter function setNetworkPreference(preference) { networkPreference = preference; diff --git a/Modules/Settings/TimeWeatherTab.qml b/Modules/Settings/TimeWeatherTab.qml index d4687f06..3c6eaeb4 100644 --- a/Modules/Settings/TimeWeatherTab.qml +++ b/Modules/Settings/TimeWeatherTab.qml @@ -111,9 +111,20 @@ ScrollView { } } + DankToggle { + width: parent.width + text: "Auto Location" + description: "Allow wttr.in to determine location based on IP address" + checked: Prefs.useAutoLocation + onToggled: (checked) => { + return Prefs.setAutoLocation(checked); + } + } + Column { width: parent.width spacing: Theme.spacingXS + visible: !Prefs.useAutoLocation StyledText { text: "Location" diff --git a/Services/WeatherService.qml b/Services/WeatherService.qml index 8fbef230..e8a1f3d0 100644 --- a/Services/WeatherService.qml +++ b/Services/WeatherService.qml @@ -92,9 +92,15 @@ Singleton { } function getWeatherUrl() { + if (Prefs.useAutoLocation) { + const url = "wttr.in/?format=j1" + console.log("Using auto location, URL:", url) + return url + } + const location = Prefs.weatherCoordinates || "40.7128,-74.0060" const url = `wttr.in/${encodeURIComponent(location)}?format=j1` - console.log("Using location:", location, "URL:", url) + console.log("Using manual location:", location, "URL:", url) return url } @@ -310,5 +316,25 @@ Singleton { const currentWeather = Object.assign({}, root.weather) root.weather = currentWeather }) + + Prefs.useAutoLocationChanged.connect(() => { + console.log("Auto location setting changed, force refreshing weather") + root.weather = { + available: false, + loading: true, + temp: 0, + tempF: 0, + city: "", + wCode: "113", + humidity: 0, + wind: "", + sunrise: "06:00", + sunset: "18:00", + uv: 0, + pressure: 0 + } + root.lastFetchTime = 0 + root.forceRefresh() + }) } } \ No newline at end of file