nosignal-shell/services/Weather.qml
William (Liam) Snow IV b053130570
feat: fahrenheit option for weather (#189)
* Added Fahrenheit to Weather Service

* some fixes

Allow for hot reloading config opt
Add opt to example config

---------

Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
2025-07-03 14:08:25 +10:00

40 lines
1 KiB
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 string tempC: "0°C"
property string tempF: "0°F"
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;
tempC = `${parseFloat(json.temp_C)}°C`;
tempF = `${parseFloat(json.temp_F)}°F`;
})
Component.onCompleted: reload()
ElapsedTimer {
id: timer
}
}