diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-06-29 21:00:24 +1000 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-06-29 21:00:24 +1000 |
| commit | 0d7804f67723107f4e78beca8229d2fbb82ce4a3 (patch) | |
| tree | 6fc32ab28b0e8316030a826948a17eb23c4936de /services/Weather.qml | |
| parent | icons: add keyboard bluetooth device (diff) | |
| download | caelestia-shell-0d7804f67723107f4e78beca8229d2fbb82ce4a3.tar.gz caelestia-shell-0d7804f67723107f4e78beca8229d2fbb82ce4a3.tar.bz2 caelestia-shell-0d7804f67723107f4e78beca8229d2fbb82ce4a3.zip | |
weather: use xmlhttprequest
Remove curl dependency
Also add buffer period so it doesnt spam api requests
Diffstat (limited to 'services/Weather.qml')
| -rw-r--r-- | services/Weather.qml | 39 |
1 files changed, 14 insertions, 25 deletions
diff --git a/services/Weather.qml b/services/Weather.qml index 998fdb8..ad80e48 100644 --- a/services/Weather.qml +++ b/services/Weather.qml @@ -3,7 +3,6 @@ pragma Singleton import "root:/config" import "root:/utils" import Quickshell -import Quickshell.Io import QtQuick Singleton { @@ -17,33 +16,23 @@ Singleton { function reload(): void { if (Config.dashboard.weatherLocation) loc = Config.dashboard.weatherLocation; - else - ipProc.running = true; + else if (!loc || timer.elapsed() > 900) + Requests.get("https://ipinfo.io/json", text => { + loc = JSON.parse(text).loc ?? ""; + timer.restart(); + }); } - onLocChanged: wttrProc.running = true - Component.onCompleted: reload() - - Process { - id: ipProc + 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); + }) - command: ["curl", "ipinfo.io"] - stdout: StdioCollector { - onStreamFinished: root.loc = JSON.parse(text).loc ?? "" - } - } - - Process { - id: wttrProc + Component.onCompleted: reload() - command: ["curl", `https://wttr.in/${root.loc}?format=j1`] - stdout: StdioCollector { - onStreamFinished: { - const json = JSON.parse(text).current_condition[0]; - root.icon = Icons.getWeatherIcon(json.weatherCode); - root.description = json.weatherDesc[0].value; - root.temperature = parseFloat(json.temp_C); - } - } + ElapsedTimer { + id: timer } } |