From dc7c0839a6dd6e5d0ce225a3eb346d401ccf73d8 Mon Sep 17 00:00:00 2001 From: Uyanide Date: Thu, 12 Mar 2026 01:15:28 +0100 Subject: [PATCH] feat: enhance weather card colors & refactor shellstate & settings --- .../Sidebar/Modules/ConnectionCard.qml | 4 +- .../Modules/Sidebar/Modules/WeatherCard.qml | 4 +- .../Modules/Sidebar/Modules/WifiCard.qml | 12 ++--- .../quickshell/Services/LocationService.qml | 44 ++++++++++++++++++- .../quickshell/Services/NetworkService.qml | 10 ++--- .../quickshell/Services/SettingsService.qml | 2 - .../quickshell/Services/ShellState.qml | 11 ++--- .../quickshell/Services/SunsetService.qml | 6 +-- 8 files changed, 65 insertions(+), 28 deletions(-) diff --git a/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/ConnectionCard.qml b/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/ConnectionCard.qml index 11c1932..4593945 100644 --- a/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/ConnectionCard.qml +++ b/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/ConnectionCard.qml @@ -112,7 +112,7 @@ UBox { UToggle { id: wifiSwitch - checked: SettingsService.wifiEnabled + checked: ShellState.wifiEnabled onToggled: (checked) => { return NetworkService.setWifiEnabled(checked); } @@ -122,7 +122,7 @@ UBox { UIconButton { iconName: "refresh" baseSize: Style.baseWidgetSize * 0.8 - enabled: SettingsService.wifiEnabled && !NetworkService.scanning + enabled: ShellState.wifiEnabled && !NetworkService.scanning onClicked: NetworkService.scan() colorFg: Colors.mGreen } diff --git a/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/WeatherCard.qml b/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/WeatherCard.qml index 54daef2..d54f950 100644 --- a/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/WeatherCard.qml +++ b/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/WeatherCard.qml @@ -113,7 +113,7 @@ UBox { Layout.alignment: Qt.AlignVCenter iconName: weatherReady ? LocationService.weatherSymbolFromCode(LocationService.data.weather.current_weather.weathercode, LocationService.data.weather.current_weather.is_day) : "weather-cloud-off" iconSize: Style.fontSizeXXXL * 1.75 - color: Colors.mPrimary + color: weatherReady ? LocationService.weatherColorFromCode(LocationService.data.weather.current_weather.weathercode) : Colors.mPrimary } ColumnLayout { @@ -198,7 +198,7 @@ UBox { Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter iconName: LocationService.weatherSymbolFromCode(LocationService.data.weather.daily.weathercode[index]) iconSize: Style.fontSizeXXL * 1.6 - color: Colors.mPrimary + color: LocationService.weatherColorFromCode(LocationService.data.weather.daily.weathercode[index]) } UText { diff --git a/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/WifiCard.qml b/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/WifiCard.qml index 85f992a..1ec73eb 100644 --- a/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/WifiCard.qml +++ b/config/quickshell/.config/quickshell/Modules/Sidebar/Modules/WifiCard.qml @@ -3,8 +3,8 @@ import QtQuick.Controls import QtQuick.Layouts import Quickshell import Quickshell.Wayland -import qs.Constants import qs.Components +import qs.Constants import qs.Services import qs.Utils @@ -62,7 +62,7 @@ ColumnLayout { // WiFi disabled state ColumnLayout { - visible: !SettingsService.wifiEnabled + visible: !ShellState.wifiEnabled anchors.fill: parent spacing: Style.marginS @@ -99,7 +99,7 @@ ColumnLayout { // Scanning state ColumnLayout { - visible: SettingsService.wifiEnabled && NetworkService.scanning && Object.keys(NetworkService.networks).length === 0 + visible: ShellState.wifiEnabled && NetworkService.scanning && Object.keys(NetworkService.networks).length === 0 anchors.fill: parent spacing: Style.marginL @@ -129,7 +129,7 @@ ColumnLayout { // Networks list container UScrollView { - visible: SettingsService.wifiEnabled && (!NetworkService.scanning || Object.keys(NetworkService.networks).length > 0) + visible: ShellState.wifiEnabled && (!NetworkService.scanning || Object.keys(NetworkService.networks).length > 0) anchors.fill: parent horizontalPolicy: ScrollBar.AlwaysOff verticalPolicy: ScrollBar.AsNeeded @@ -143,7 +143,7 @@ ColumnLayout { // Network list Repeater { model: { - if (!SettingsService.wifiEnabled) + if (!ShellState.wifiEnabled) return []; const nets = Object.values(NetworkService.networks); @@ -519,7 +519,7 @@ ColumnLayout { // Empty state when no networks ColumnLayout { - visible: SettingsService.wifiEnabled && !NetworkService.scanning && Object.keys(NetworkService.networks).length === 0 + visible: ShellState.wifiEnabled && !NetworkService.scanning && Object.keys(NetworkService.networks).length === 0 anchors.fill: parent spacing: Style.marginL diff --git a/config/quickshell/.config/quickshell/Services/LocationService.qml b/config/quickshell/.config/quickshell/Services/LocationService.qml index 4fcf433..1c8aed2 100644 --- a/config/quickshell/.config/quickshell/Services/LocationService.qml +++ b/config/quickshell/.config/quickshell/Services/LocationService.qml @@ -7,6 +7,8 @@ pragma Singleton // Location and weather service with decoupled geocoding and weather fetching. Singleton { + //console.log(JSON.stringify(weatherData)) + id: root property string locationFile: Paths.cacheDir + "location.json" @@ -145,8 +147,6 @@ Singleton { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE) { - //console.log(JSON.stringify(weatherData)) - if (xhr.status === 200) { try { var weatherData = JSON.parse(xhr.responseText); @@ -244,6 +244,46 @@ Singleton { return "Unknown"; } + function weatherColorFromCode(code) { + // Clear sky + if (code === 0) + return Colors.mYellow; + + // Mainly clear / Partly cloudy + if (code === 1 || code === 2) + return Colors.mSky; + + // Overcast + if (code === 3) + return Colors.mLavender; + + // Fog + if (code === 45 || code === 48) + return Colors.mCyan; + + // Drizzle / Rain / Rain showers + if ((code >= 51 && code <= 55) || (code >= 61 && code <= 65) || (code >= 80 && code <= 82)) + return Colors.mBlue; + + // Freezing drizzle / Freezing rain + if ((code >= 56 && code <= 57) || (code >= 66 && code <= 67)) + return Colors.mPurple; + + // Snow / Snow showers + if ((code >= 71 && code <= 77) || (code >= 85 && code <= 86)) + return Colors.mLavender; + + // Thunderstorm + if (code === 95) + return Colors.mOrange; + + // Thunderstorm with hail + if (code >= 96 && code <= 99) + return Colors.mRed; + + return Colors.mSky; + } + // -------------------------------- function celsiusToFahrenheit(celsius) { return 32 + celsius * 1.8; diff --git a/config/quickshell/.config/quickshell/Services/NetworkService.qml b/config/quickshell/.config/quickshell/Services/NetworkService.qml index 2b1c8ae..5a4c070 100644 --- a/config/quickshell/.config/quickshell/Services/NetworkService.qml +++ b/config/quickshell/.config/quickshell/Services/NetworkService.qml @@ -85,12 +85,12 @@ Singleton { } function setWifiEnabled(enabled) { - SettingsService.wifiEnabled = enabled + ShellState.wifiEnabled = enabled wifiStateEnableProcess.running = true } function scan() { - if (!SettingsService.wifiEnabled) + if (!ShellState.wifiEnabled) return if (scanning) { @@ -236,8 +236,8 @@ Singleton { onStreamFinished: { const enabled = text.trim() === "enabled" Logger.i("Network", "Wi-Fi adapter was detect as enabled:", enabled) - if (SettingsService.wifiEnabled !== enabled) { - SettingsService.wifiEnabled = enabled + if (ShellState.wifiEnabled !== enabled) { + ShellState.wifiEnabled = enabled } } } @@ -247,7 +247,7 @@ Singleton { Process { id: wifiStateEnableProcess running: false - command: ["nmcli", "radio", "wifi", SettingsService.wifiEnabled ? "on" : "off"] + command: ["nmcli", "radio", "wifi", ShellState.wifiEnabled ? "on" : "off"] stdout: StdioCollector { onStreamFinished: { diff --git a/config/quickshell/.config/quickshell/Services/SettingsService.qml b/config/quickshell/.config/quickshell/Services/SettingsService.qml index 40e1bd0..f587041 100644 --- a/config/quickshell/.config/quickshell/Services/SettingsService.qml +++ b/config/quickshell/.config/quickshell/Services/SettingsService.qml @@ -12,7 +12,6 @@ Singleton { property alias ipAliases: adapter.ipAliases property alias location: adapter.location property alias backgroundPath: adapter.backgroundPath - property alias wifiEnabled: adapter.wifiEnabled property alias cycleWallpapers: cycleSettings.wallpapers property alias cycleShuffle: cycleSettings.shuffle property alias cycleInterval: cycleSettings.interval @@ -37,7 +36,6 @@ Singleton { } property string location: "New York" property string backgroundPath: "" - property bool wifiEnabled: true property JsonObject cycle: JsonObject { id: cycleSettings diff --git a/config/quickshell/.config/quickshell/Services/ShellState.qml b/config/quickshell/.config/quickshell/Services/ShellState.qml index c267993..debe5a7 100644 --- a/config/quickshell/.config/quickshell/Services/ShellState.qml +++ b/config/quickshell/.config/quickshell/Services/ShellState.qml @@ -12,9 +12,10 @@ Singleton { property bool isLoaded: false property alias notificationsState: adapter.notificationsState property alias lyricsState: adapter.lyricsState - property alias sunsetState: adapter.sunsetState + property alias sunsetEnabled: adapter.sunsetEnabled property alias leftSiderbarTab: adapter.leftSiderbarTab property alias rightSiderbarTab: adapter.rightSiderbarTab + property alias wifiEnabled: adapter.wifiEnabled function save() { saveTimer.restart(); @@ -22,9 +23,10 @@ Singleton { onNotificationsStateChanged: save() onLyricsStateChanged: save() - onSunsetStateChanged: save() + onSunsetEnabledChanged: save() onLeftSiderbarTabChanged: save() onRightSiderbarTabChanged: save() + onWifiEnabledChanged: save() Component.onCompleted: { stateFileView.path = stateFile; } @@ -52,11 +54,10 @@ Singleton { property var lyricsState: ({ "showLyricsBar": false }) - property var sunsetState: ({ - "enabled": true - }) + property bool sunsetEnabled: true property string leftSiderbarTab: "bluetooth" property string rightSiderbarTab: "notes" + property bool wifiEnabled: true } } diff --git a/config/quickshell/.config/quickshell/Services/SunsetService.qml b/config/quickshell/.config/quickshell/Services/SunsetService.qml index ea368e6..ff45f91 100644 --- a/config/quickshell/.config/quickshell/Services/SunsetService.qml +++ b/config/quickshell/.config/quickshell/Services/SunsetService.qml @@ -11,12 +11,10 @@ Singleton { property double _latitude: -1 property double _longitude: -1 property int temperature: 0 - readonly property bool isEnabled: ShellState.sunsetState.enabled || false + readonly property bool isEnabled: ShellState.sunsetEnabled function toggleSunset() { - ShellState.sunsetState = { - "enabled": !root.isEnabled - }; + ShellState.sunsetEnabled = !root.isEnabled; } function setLat(lat) {