weather: use city instead of lat/long

Also lazy load
This commit is contained in:
2 * r + 2 * t 2025-08-24 20:42:43 +10:00
parent 61884c07a7
commit 748bfa9358

View file

@ -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
}