summaryrefslogtreecommitdiff
path: root/modules/dashboard/dash/Weather.qml
blob: 3c48aeeaacbb3d35ae9e9a747d659c1c21a56f71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 || "cloud_alert"
        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 || qsTr("No weather")

            elide: Text.ElideRight
            width: Math.min(implicitWidth, root.parent.width - icon.implicitWidth - info.anchors.leftMargin - Appearance.padding.large * 2)
        }
    }
}