summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-05-28 22:03:05 +0800
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-05-28 22:03:05 +0800
commitb6a34cbc47fcef2f0b8b828314290f4e1270dae0 (patch)
treebed54ff73413ae6c66820adc3afe60379c29f06c
parentdrawers: change anim durations (diff)
downloadcaelestia-shell-b6a34cbc47fcef2f0b8b828314290f4e1270dae0.tar.gz
caelestia-shell-b6a34cbc47fcef2f0b8b828314290f4e1270dae0.tar.bz2
caelestia-shell-b6a34cbc47fcef2f0b8b828314290f4e1270dae0.zip
internal: move weather into service
Also fix not escaping city properly
-rw-r--r--modules/dashboard/dash/Weather.qml28
-rw-r--r--services/Weather.qml32
2 files changed, 38 insertions, 22 deletions
diff --git a/modules/dashboard/dash/Weather.qml b/modules/dashboard/dash/Weather.qml
index 99947f7..489444f 100644
--- a/modules/dashboard/dash/Weather.qml
+++ b/modules/dashboard/dash/Weather.qml
@@ -8,29 +8,13 @@ import QtQuick
Item {
id: root
- property string icon
- property string description
- property real temperature
-
anchors.centerIn: parent
implicitWidth: icon.implicitWidth + info.implicitWidth + info.anchors.leftMargin
- onVisibleChanged: wttrProc.running = true
-
- Process {
- id: wttrProc
-
- running: true
- command: ["fish", "-c", `curl "https://wttr.in/$(curl ipinfo.io | jq -r '.city' | string replace ' ' '%20')?format=j1" | jq -c '.current_condition[0] | {code: .weatherCode, desc: .weatherDesc[0].value, temp: .temp_C}'`]
- stdout: SplitParser {
- onRead: data => {
- const json = JSON.parse(data);
- root.icon = Icons.getWeatherIcon(json.code);
- root.description = json.desc;
- root.temperature = parseFloat(json.temp);
- }
- }
+ onVisibleChanged: {
+ if (visible)
+ Weather.reload();
}
MaterialIcon {
@@ -40,7 +24,7 @@ Item {
anchors.left: parent.left
animate: true
- text: root.icon || "cloud_alert"
+ text: Weather.icon || "cloud_alert"
color: Colours.palette.m3secondary
font.pointSize: Appearance.font.size.extraLarge * 2
font.variableAxes: ({
@@ -61,7 +45,7 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
animate: true
- text: `${root.temperature}°C`
+ text: `${Weather.temperature}°C`
color: Colours.palette.m3primary
font.pointSize: Appearance.font.size.extraLarge
font.weight: 500
@@ -71,7 +55,7 @@ Item {
anchors.horizontalCenter: parent.horizontalCenter
animate: true
- text: root.description || qsTr("No weather")
+ text: Weather.description || qsTr("No weather")
elide: Text.ElideRight
width: Math.min(implicitWidth, root.parent.width - icon.implicitWidth - info.anchors.leftMargin - Appearance.padding.large * 2)
diff --git a/services/Weather.qml b/services/Weather.qml
new file mode 100644
index 0000000..13503f9
--- /dev/null
+++ b/services/Weather.qml
@@ -0,0 +1,32 @@
+pragma Singleton
+
+import "root:/utils"
+import Quickshell
+import Quickshell.Io
+
+Singleton {
+ id: root
+
+ property string icon
+ property string description
+ property real temperature
+
+ function reload(): void {
+ wttrProc.running = true;
+ }
+
+ Process {
+ id: wttrProc
+
+ running: true
+ command: ["fish", "-c", `curl "https://wttr.in/$(curl ipinfo.io | jq -r '.city' | string replace -a ' ' '%20')?format=j1" | jq -c '.current_condition[0] | {code: .weatherCode, desc: .weatherDesc[0].value, temp: .temp_C}'`]
+ stdout: SplitParser {
+ onRead: data => {
+ const json = JSON.parse(data);
+ root.icon = Icons.getWeatherIcon(json.code);
+ root.description = json.desc;
+ root.temperature = parseFloat(json.temp);
+ }
+ }
+ }
+}