dashboard: add weather

This commit is contained in:
2 * r + 2 * t 2025-05-23 23:10:33 +08:00
parent 219d794bf8
commit 95b0c2d3fe
4 changed files with 138 additions and 59 deletions

View file

@ -17,5 +17,6 @@ Singleton {
readonly property int mediaProgressSweep: 180 readonly property int mediaProgressSweep: 180
readonly property int mediaProgressThickness: 8 readonly property int mediaProgressThickness: 8
readonly property int resourceProgessThickness: 10 readonly property int resourceProgessThickness: 10
readonly property int weatherWidth: 250
} }
} }

View file

@ -11,20 +11,20 @@ GridLayout {
columnSpacing: Appearance.spacing.normal columnSpacing: Appearance.spacing.normal
Rect { Rect {
Layout.column: 2
Layout.columnSpan: 3 Layout.columnSpan: 3
User {} User {}
} }
Rect { Rect {
// text: "toggles" // Layout.column: 3
Layout.row: 0
Layout.column: 3
Layout.columnSpan: 2 Layout.columnSpan: 2
Layout.preferredWidth: 250 Layout.preferredWidth: DashboardConfig.sizes.weatherWidth
Layout.fillHeight: true Layout.fillHeight: true
Item {} Weather {}
} }
Rect { Rect {

View file

@ -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)
}
}
}

View file

@ -52,59 +52,54 @@ Singleton {
}) })
readonly property var weatherIcons: ({ readonly property var weatherIcons: ({
warning: "󰼯", "113": "clear_day",
sunny: "󰖙", "116": "partly_cloudy_day",
clear: "󰖔", "119": "cloud",
partly_cloudy: "󰖕", "122": "cloud",
partly_cloudy_night: "󰼱", "143": "foggy",
cloudy: "󰖐", "176": "rainy",
overcast: "󰖕", "179": "rainy",
mist: "󰖑", "182": "rainy",
patchy_rain_nearby: "󰼳", "185": "rainy",
patchy_rain_possible: "󰼳", "200": "thunderstorm",
patchy_snow_possible: "󰼴", "227": "cloudy_snowing",
patchy_sleet_possible: "󰙿", "230": "snowing_heavy",
patchy_freezing_drizzle_possible: "󰙿", "248": "foggy",
thundery_outbreaks_possible: "󰙾", "260": "foggy",
blowing_snow: "󰼶", "263": "rainy",
blizzard: "󰼶", "266": "rainy",
fog: "󰖑", "281": "rainy",
freezing_fog: "󰖑", "284": "rainy",
patchy_light_drizzle: "󰼳", "293": "rainy",
light_drizzle: "󰼳", "296": "rainy",
freezing_drizzle: "󰙿", "299": "rainy",
heavy_freezing_drizzle: "󰙿", "302": "weather_hail",
patchy_light_rain: "󰼳", "305": "rainy",
light_rain: "󰼳", "308": "weather_hail",
moderate_rain_at_times: "󰖗", "311": "rainy",
moderate_rain: "󰼳", "314": "rainy",
heavy_rain_at_times: "󰖖", "317": "rainy",
heavy_rain: "󰖖", "320": "cloudy_snowing",
light_freezing_rain: "󰙿", "323": "cloudy_snowing",
moderate_or_heavy_freezing_rain: "󰙿", "326": "cloudy_snowing",
light_sleet: "󰙿", "329": "snowing_heavy",
moderate_or_heavy_sleet: "󰙿", "332": "snowing_heavy",
patchy_light_snow: "󰼴", "335": "snowing",
light_snow: "󰼴", "338": "snowing_heavy",
patchy_moderate_snow: "󰼴", "350": "rainy",
moderate_snow: "󰼶", "353": "rainy",
patchy_heavy_snow: "󰼶", "356": "rainy",
heavy_snow: "󰼶", "359": "weather_hail",
ice_pellets: "󰖒", "362": "rainy",
light_rain_shower: "󰖖", "365": "rainy",
moderate_or_heavy_rain_shower: "󰖖", "368": "cloudy_snowing",
torrential_rain_shower: "󰖖", "371": "snowing",
light_sleet_showers: "󰼵", "374": "rainy",
moderate_or_heavy_sleet_showers: "󰼵", "377": "rainy",
light_snow_showers: "󰼵", "386": "thunderstorm",
moderate_or_heavy_snow_showers: "󰼵", "389": "thunderstorm",
light_showers_of_ice_pellets: "󰖒", "392": "thunderstorm",
moderate_or_heavy_showers_of_ice_pellets: "󰖒", "395": "snowing"
patchy_light_rain_with_thunder: "󰙾",
moderate_or_heavy_rain_with_thunder: "󰙾",
moderate_or_heavy_rain_in_area_with_thunder: "󰙾",
patchy_light_snow_with_thunder: "󰼶",
moderate_or_heavy_snow_with_thunder: "󰼶"
}) })
readonly property var desktopEntrySubs: ({ readonly property var desktopEntrySubs: ({
@ -157,7 +152,7 @@ Singleton {
const categories = DesktopEntries.applications.values.find(app => app.id === name)?.categories; const categories = DesktopEntries.applications.values.find(app => app.id === name)?.categories;
if (categories) if (categories)
for (const [key, value] of Object.entries(this.categoryIcons)) for (const [key, value] of Object.entries(categoryIcons))
if (categories.includes(key)) if (categories.includes(key))
return value; return value;
return fallback; return fallback;
@ -185,6 +180,12 @@ Singleton {
return "bluetooth"; return "bluetooth";
} }
function getWeatherIcon(code: string): string {
if (weatherIcons.hasOwnProperty(code))
return weatherIcons[code];
return "air";
}
FileView { FileView {
path: "/etc/os-release" path: "/etc/os-release"
onLoaded: { onLoaded: {