From c71029487a02add3ac61fb529d8e2ed21c557ec2 Mon Sep 17 00:00:00 2001 From: quadbyte Date: Mon, 11 Aug 2025 21:35:51 -0400 Subject: [PATCH] Better weather --- Modules/SidePanel/WeatherCard.qml | 23 +++++++++++++++++------ Services/Location.qml | 12 ++++++++++-- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Modules/SidePanel/WeatherCard.qml b/Modules/SidePanel/WeatherCard.qml index 5a1a29e..48965b7 100644 --- a/Modules/SidePanel/WeatherCard.qml +++ b/Modules/SidePanel/WeatherCard.qml @@ -21,9 +21,10 @@ NBox { anchors.margins: Style.marginMedium * scaling spacing: Style.marginMedium * scaling + RowLayout { spacing: Style.marginSmall * scaling - Text { + NText { text: Location.weatherSymbolFromCode(Location.data.weather.current_weather.weathercode) font.family: "Material Symbols Outlined" font.pointSize: Style.fontSizeXXL * 1.25 * scaling @@ -37,13 +38,21 @@ NBox { font.pointSize: Style.fontSizeLarge * scaling } NText { - text: "(" + Location.data. weather.timezone_abbreviation + ")" + text: `(${Location.data.weather.timezone_abbreviation})` font.pointSize: Style.fontSizeTiny * scaling + visible: Location.data.weather } } NText { - text: "26°C" + text: { + var temp = Location.data.weather.current_weather.temperature + if (Settings.data.location.useFahrenheit) { + temp = Location.celsiusToFahrenheit(temp) + } + temp = Math.round(temp) + return `${temp}°` + } font.pointSize: Style.fontSizeXL * scaling font.weight: Style.fontWeightBold } @@ -60,9 +69,9 @@ NBox { Layout.fillWidth: true spacing: Style.marginMedium * scaling Repeater { - model: 5 + model: Location.data.weather.daily.time delegate: ColumnLayout { - spacing: 2 * scaling + spacing: Style.spacingSmall * scaling NText { text: Qt.formatDateTime(new Date(Location.data.weather.daily.time[index]), "ddd") font.weight: Style.fontWeightBold @@ -70,6 +79,7 @@ NBox { NText { text: Location.weatherSymbolFromCode(Location.data.weather.daily.weathercode[index]) font.family: "Material Symbols Outlined" + font.pointSize: Style.fontSizeLarge * scaling font.weight: Style.fontWeightBold color: Colors.textSecondary } @@ -83,8 +93,9 @@ NBox { } max = Math.round(max) min = Math.round(min) - return `${max}° / ${min}°` + return `${max}°/${min}°` } + font.pointSize: Style.fontSizeSmall * scaling color: Colors.textSecondary } } diff --git a/Services/Location.qml b/Services/Location.qml index 7692723..c33ca76 100644 --- a/Services/Location.qml +++ b/Services/Location.qml @@ -11,6 +11,7 @@ Singleton { property string locationFile: Quickshell.env("NOCTALIA_WEATHER_FILE") || (Settings.cacheDir + "location.json") property int weatherUpdateFrequency: 30 * 60 // 30 minutes expressed in seconds property var data: adapter // Used to access via Location.data.xxx.yyy + property bool isFetchingWeather: false FileView { path: locationFile @@ -63,6 +64,10 @@ Singleton { // -------------------------------- function updateWeather() { + if (isFetchingWeather) { + return + } + if ((data.weatherLastFetch === "") || (Time.timestamp >= data.weatherLastFetch + weatherUpdateFrequency)) { getFreshWeather() } @@ -70,10 +75,11 @@ Singleton { // -------------------------------- function getFreshWeather() { + isFetchingWeather = true if (data.latitude === "" || data.longitude === "") { console.log("Geocoding location") _geocodeLocation(Settings.data.location.name, function (lat, lon) { - console.log("Geocoded " + Settings.data.location.name + " to : " + lat + " / " + lon) + console.log("Geocoded " + Settings.data.location.name + " to: " + lat + " / " + lon) // Save GPS coordinates data.latitude = lat @@ -128,6 +134,7 @@ Singleton { // Save to json data.weather = weatherData data.weatherLastFetch = Time.timestamp + isFetchingWeather = false console.log("Cached weather to disk") } catch (e) { errorCallback("Failed to parse weather data.") @@ -144,9 +151,10 @@ Singleton { // -------------------------------- function errorCallback(message) { console.error(message) + isFetchingWeather = false } - // -------------------------------- + // -------------------------------- function weatherSymbolFromCode(code) { if (code === 0) return "sunny"