From 95b0c2d3fef9d46790938214e19f945b496a9223 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Fri, 23 May 2025 23:10:33 +0800 Subject: dashboard: add weather --- modules/dashboard/Dash.qml | 10 ++--- modules/dashboard/dash/Weather.qml | 77 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 modules/dashboard/dash/Weather.qml (limited to 'modules/dashboard') diff --git a/modules/dashboard/Dash.qml b/modules/dashboard/Dash.qml index c9923c7..5e619a3 100644 --- a/modules/dashboard/Dash.qml +++ b/modules/dashboard/Dash.qml @@ -11,20 +11,20 @@ GridLayout { columnSpacing: Appearance.spacing.normal Rect { + Layout.column: 2 Layout.columnSpan: 3 User {} } Rect { - // text: "toggles" - - Layout.column: 3 + // Layout.column: 3 + Layout.row: 0 Layout.columnSpan: 2 - Layout.preferredWidth: 250 + Layout.preferredWidth: DashboardConfig.sizes.weatherWidth Layout.fillHeight: true - Item {} + Weather {} } Rect { diff --git a/modules/dashboard/dash/Weather.qml b/modules/dashboard/dash/Weather.qml new file mode 100644 index 0000000..05c0174 --- /dev/null +++ b/modules/dashboard/dash/Weather.qml @@ -0,0 +1,77 @@ +import "root:/widgets" +import "root:/services" +import "root:/config" +import "root:/utils" +import Quickshell.Io +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); + } + } + } + + MaterialIcon { + id: icon + + anchors.verticalCenter: parent.verticalCenter + anchors.left: parent.left + + animate: true + text: root.icon + color: Colours.palette.m3secondary + font.pointSize: root.parent.height / 2 || 1 + } + + Column { + id: info + + anchors.verticalCenter: parent.verticalCenter + anchors.left: icon.right + anchors.leftMargin: Appearance.spacing.large + + spacing: Appearance.spacing.small + + StyledText { + anchors.horizontalCenter: parent.horizontalCenter + + animate: true + text: `${root.temperature}°C` + color: Colours.palette.m3primary + font.pointSize: Appearance.font.size.extraLarge + font.weight: 500 + } + + StyledText { + anchors.horizontalCenter: parent.horizontalCenter + + animate: true + text: root.description + + elide: Text.ElideRight + width: Math.min(implicitWidth, root.parent.width - icon.implicitWidth - info.anchors.leftMargin - Appearance.padding.large * 2) + } + } +} -- cgit v1.2.3-freya