From 748bfa9358b52c6d1d92899112fc522896548206 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sun, 24 Aug 2025 20:42:43 +1000 Subject: weather: use city instead of lat/long Also lazy load --- services/Weather.qml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/services/Weather.qml b/services/Weather.qml index 02458c2..f3147a8 100644 --- a/services/Weather.qml +++ b/services/Weather.qml @@ -8,7 +8,7 @@ import QtQuick Singleton { id: root - property string loc + property string city property var cc property var forecast readonly property string icon: cc ? Icons.getWeatherIcon(cc.weatherCode) : "cloud_alert" @@ -19,22 +19,20 @@ Singleton { function reload(): void { if (Config.services.weatherLocation) - loc = Config.services.weatherLocation; - else if (!loc || timer.elapsed() > 900) + city = Config.services.weatherLocation; + else if (!city || timer.elapsed() > 900) Requests.get("https://ipinfo.io/json", text => { - loc = JSON.parse(text).loc ?? ""; + city = JSON.parse(text).city ?? ""; timer.restart(); }); } - onLocChanged: Requests.get(`https://wttr.in/${loc}?format=j1`, text => { + onCityChanged: Requests.get(`https://wttr.in/${city}?format=j1`, text => { const json = JSON.parse(text); cc = json.current_condition[0]; forecast = json.weather; }) - Component.onCompleted: reload() - ElapsedTimer { id: timer } -- cgit v1.2.3-freya