internal: move weather into service
Also fix not escaping city properly
This commit is contained in:
parent
d48cd777f7
commit
b6a34cbc47
2 changed files with 38 additions and 22 deletions
|
|
@ -8,29 +8,13 @@ import QtQuick
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property string icon
|
|
||||||
property string description
|
|
||||||
property real temperature
|
|
||||||
|
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
|
||||||
implicitWidth: icon.implicitWidth + info.implicitWidth + info.anchors.leftMargin
|
implicitWidth: icon.implicitWidth + info.implicitWidth + info.anchors.leftMargin
|
||||||
|
|
||||||
onVisibleChanged: wttrProc.running = true
|
onVisibleChanged: {
|
||||||
|
if (visible)
|
||||||
Process {
|
Weather.reload();
|
||||||
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 {
|
MaterialIcon {
|
||||||
|
|
@ -40,7 +24,7 @@ Item {
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
|
||||||
animate: true
|
animate: true
|
||||||
text: root.icon || "cloud_alert"
|
text: Weather.icon || "cloud_alert"
|
||||||
color: Colours.palette.m3secondary
|
color: Colours.palette.m3secondary
|
||||||
font.pointSize: Appearance.font.size.extraLarge * 2
|
font.pointSize: Appearance.font.size.extraLarge * 2
|
||||||
font.variableAxes: ({
|
font.variableAxes: ({
|
||||||
|
|
@ -61,7 +45,7 @@ Item {
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
|
||||||
animate: true
|
animate: true
|
||||||
text: `${root.temperature}°C`
|
text: `${Weather.temperature}°C`
|
||||||
color: Colours.palette.m3primary
|
color: Colours.palette.m3primary
|
||||||
font.pointSize: Appearance.font.size.extraLarge
|
font.pointSize: Appearance.font.size.extraLarge
|
||||||
font.weight: 500
|
font.weight: 500
|
||||||
|
|
@ -71,7 +55,7 @@ Item {
|
||||||
anchors.horizontalCenter: parent.horizontalCenter
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
|
||||||
animate: true
|
animate: true
|
||||||
text: root.description || qsTr("No weather")
|
text: Weather.description || qsTr("No weather")
|
||||||
|
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
width: Math.min(implicitWidth, root.parent.width - icon.implicitWidth - info.anchors.leftMargin - Appearance.padding.large * 2)
|
width: Math.min(implicitWidth, root.parent.width - icon.implicitWidth - info.anchors.leftMargin - Appearance.padding.large * 2)
|
||||||
|
|
|
||||||
32
services/Weather.qml
Normal file
32
services/Weather.qml
Normal file
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue