nosignal-shell/services/Weather.qml
2 * r + 2 * t 0d7804f677 weather: use xmlhttprequest
Remove curl dependency

Also add buffer period so it doesnt spam api requests
2025-06-29 21:00:24 +10:00

38 lines
954 B
QML

pragma Singleton
import "root:/config"
import "root:/utils"
import Quickshell
import QtQuick
Singleton {
id: root
property string loc
property string icon
property string description
property real temperature
function reload(): void {
if (Config.dashboard.weatherLocation)
loc = Config.dashboard.weatherLocation;
else if (!loc || timer.elapsed() > 900)
Requests.get("https://ipinfo.io/json", text => {
loc = JSON.parse(text).loc ?? "";
timer.restart();
});
}
onLocChanged: Requests.get(`https://wttr.in/${loc}?format=j1`, text => {
const json = JSON.parse(text).current_condition[0];
icon = Icons.getWeatherIcon(json.weatherCode);
description = json.weatherDesc[0].value;
temperature = parseFloat(json.temp_C);
})
Component.onCompleted: reload()
ElapsedTimer {
id: timer
}
}