feat: enhance weather card colors & refactor shellstate & settings

This commit is contained in:
2026-03-12 01:15:28 +01:00
parent e56e607110
commit dc7c0839a6
8 changed files with 65 additions and 28 deletions
@@ -112,7 +112,7 @@ UBox {
UToggle { UToggle {
id: wifiSwitch id: wifiSwitch
checked: SettingsService.wifiEnabled checked: ShellState.wifiEnabled
onToggled: (checked) => { onToggled: (checked) => {
return NetworkService.setWifiEnabled(checked); return NetworkService.setWifiEnabled(checked);
} }
@@ -122,7 +122,7 @@ UBox {
UIconButton { UIconButton {
iconName: "refresh" iconName: "refresh"
baseSize: Style.baseWidgetSize * 0.8 baseSize: Style.baseWidgetSize * 0.8
enabled: SettingsService.wifiEnabled && !NetworkService.scanning enabled: ShellState.wifiEnabled && !NetworkService.scanning
onClicked: NetworkService.scan() onClicked: NetworkService.scan()
colorFg: Colors.mGreen colorFg: Colors.mGreen
} }
@@ -113,7 +113,7 @@ UBox {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
iconName: weatherReady ? LocationService.weatherSymbolFromCode(LocationService.data.weather.current_weather.weathercode, LocationService.data.weather.current_weather.is_day) : "weather-cloud-off" 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 iconSize: Style.fontSizeXXXL * 1.75
color: Colors.mPrimary color: weatherReady ? LocationService.weatherColorFromCode(LocationService.data.weather.current_weather.weathercode) : Colors.mPrimary
} }
ColumnLayout { ColumnLayout {
@@ -198,7 +198,7 @@ UBox {
Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
iconName: LocationService.weatherSymbolFromCode(LocationService.data.weather.daily.weathercode[index]) iconName: LocationService.weatherSymbolFromCode(LocationService.data.weather.daily.weathercode[index])
iconSize: Style.fontSizeXXL * 1.6 iconSize: Style.fontSizeXXL * 1.6
color: Colors.mPrimary color: LocationService.weatherColorFromCode(LocationService.data.weather.daily.weathercode[index])
} }
UText { UText {
@@ -3,8 +3,8 @@ import QtQuick.Controls
import QtQuick.Layouts import QtQuick.Layouts
import Quickshell import Quickshell
import Quickshell.Wayland import Quickshell.Wayland
import qs.Constants
import qs.Components import qs.Components
import qs.Constants
import qs.Services import qs.Services
import qs.Utils import qs.Utils
@@ -62,7 +62,7 @@ ColumnLayout {
// WiFi disabled state // WiFi disabled state
ColumnLayout { ColumnLayout {
visible: !SettingsService.wifiEnabled visible: !ShellState.wifiEnabled
anchors.fill: parent anchors.fill: parent
spacing: Style.marginS spacing: Style.marginS
@@ -99,7 +99,7 @@ ColumnLayout {
// Scanning state // Scanning state
ColumnLayout { 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 anchors.fill: parent
spacing: Style.marginL spacing: Style.marginL
@@ -129,7 +129,7 @@ ColumnLayout {
// Networks list container // Networks list container
UScrollView { 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 anchors.fill: parent
horizontalPolicy: ScrollBar.AlwaysOff horizontalPolicy: ScrollBar.AlwaysOff
verticalPolicy: ScrollBar.AsNeeded verticalPolicy: ScrollBar.AsNeeded
@@ -143,7 +143,7 @@ ColumnLayout {
// Network list // Network list
Repeater { Repeater {
model: { model: {
if (!SettingsService.wifiEnabled) if (!ShellState.wifiEnabled)
return []; return [];
const nets = Object.values(NetworkService.networks); const nets = Object.values(NetworkService.networks);
@@ -519,7 +519,7 @@ ColumnLayout {
// Empty state when no networks // Empty state when no networks
ColumnLayout { 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 anchors.fill: parent
spacing: Style.marginL spacing: Style.marginL
@@ -7,6 +7,8 @@ pragma Singleton
// Location and weather service with decoupled geocoding and weather fetching. // Location and weather service with decoupled geocoding and weather fetching.
Singleton { Singleton {
//console.log(JSON.stringify(weatherData))
id: root id: root
property string locationFile: Paths.cacheDir + "location.json" property string locationFile: Paths.cacheDir + "location.json"
@@ -145,8 +147,6 @@ Singleton {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.readyState === XMLHttpRequest.DONE) {
//console.log(JSON.stringify(weatherData))
if (xhr.status === 200) { if (xhr.status === 200) {
try { try {
var weatherData = JSON.parse(xhr.responseText); var weatherData = JSON.parse(xhr.responseText);
@@ -244,6 +244,46 @@ Singleton {
return "Unknown"; 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) { function celsiusToFahrenheit(celsius) {
return 32 + celsius * 1.8; return 32 + celsius * 1.8;
@@ -85,12 +85,12 @@ Singleton {
} }
function setWifiEnabled(enabled) { function setWifiEnabled(enabled) {
SettingsService.wifiEnabled = enabled ShellState.wifiEnabled = enabled
wifiStateEnableProcess.running = true wifiStateEnableProcess.running = true
} }
function scan() { function scan() {
if (!SettingsService.wifiEnabled) if (!ShellState.wifiEnabled)
return return
if (scanning) { if (scanning) {
@@ -236,8 +236,8 @@ Singleton {
onStreamFinished: { onStreamFinished: {
const enabled = text.trim() === "enabled" const enabled = text.trim() === "enabled"
Logger.i("Network", "Wi-Fi adapter was detect as enabled:", enabled) Logger.i("Network", "Wi-Fi adapter was detect as enabled:", enabled)
if (SettingsService.wifiEnabled !== enabled) { if (ShellState.wifiEnabled !== enabled) {
SettingsService.wifiEnabled = enabled ShellState.wifiEnabled = enabled
} }
} }
} }
@@ -247,7 +247,7 @@ Singleton {
Process { Process {
id: wifiStateEnableProcess id: wifiStateEnableProcess
running: false running: false
command: ["nmcli", "radio", "wifi", SettingsService.wifiEnabled ? "on" : "off"] command: ["nmcli", "radio", "wifi", ShellState.wifiEnabled ? "on" : "off"]
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
@@ -12,7 +12,6 @@ Singleton {
property alias ipAliases: adapter.ipAliases property alias ipAliases: adapter.ipAliases
property alias location: adapter.location property alias location: adapter.location
property alias backgroundPath: adapter.backgroundPath property alias backgroundPath: adapter.backgroundPath
property alias wifiEnabled: adapter.wifiEnabled
property alias cycleWallpapers: cycleSettings.wallpapers property alias cycleWallpapers: cycleSettings.wallpapers
property alias cycleShuffle: cycleSettings.shuffle property alias cycleShuffle: cycleSettings.shuffle
property alias cycleInterval: cycleSettings.interval property alias cycleInterval: cycleSettings.interval
@@ -37,7 +36,6 @@ Singleton {
} }
property string location: "New York" property string location: "New York"
property string backgroundPath: "" property string backgroundPath: ""
property bool wifiEnabled: true
property JsonObject cycle: JsonObject { property JsonObject cycle: JsonObject {
id: cycleSettings id: cycleSettings
@@ -12,9 +12,10 @@ Singleton {
property bool isLoaded: false property bool isLoaded: false
property alias notificationsState: adapter.notificationsState property alias notificationsState: adapter.notificationsState
property alias lyricsState: adapter.lyricsState property alias lyricsState: adapter.lyricsState
property alias sunsetState: adapter.sunsetState property alias sunsetEnabled: adapter.sunsetEnabled
property alias leftSiderbarTab: adapter.leftSiderbarTab property alias leftSiderbarTab: adapter.leftSiderbarTab
property alias rightSiderbarTab: adapter.rightSiderbarTab property alias rightSiderbarTab: adapter.rightSiderbarTab
property alias wifiEnabled: adapter.wifiEnabled
function save() { function save() {
saveTimer.restart(); saveTimer.restart();
@@ -22,9 +23,10 @@ Singleton {
onNotificationsStateChanged: save() onNotificationsStateChanged: save()
onLyricsStateChanged: save() onLyricsStateChanged: save()
onSunsetStateChanged: save() onSunsetEnabledChanged: save()
onLeftSiderbarTabChanged: save() onLeftSiderbarTabChanged: save()
onRightSiderbarTabChanged: save() onRightSiderbarTabChanged: save()
onWifiEnabledChanged: save()
Component.onCompleted: { Component.onCompleted: {
stateFileView.path = stateFile; stateFileView.path = stateFile;
} }
@@ -52,11 +54,10 @@ Singleton {
property var lyricsState: ({ property var lyricsState: ({
"showLyricsBar": false "showLyricsBar": false
}) })
property var sunsetState: ({ property bool sunsetEnabled: true
"enabled": true
})
property string leftSiderbarTab: "bluetooth" property string leftSiderbarTab: "bluetooth"
property string rightSiderbarTab: "notes" property string rightSiderbarTab: "notes"
property bool wifiEnabled: true
} }
} }
@@ -11,12 +11,10 @@ Singleton {
property double _latitude: -1 property double _latitude: -1
property double _longitude: -1 property double _longitude: -1
property int temperature: 0 property int temperature: 0
readonly property bool isEnabled: ShellState.sunsetState.enabled || false readonly property bool isEnabled: ShellState.sunsetEnabled
function toggleSunset() { function toggleSunset() {
ShellState.sunsetState = { ShellState.sunsetEnabled = !root.isEnabled;
"enabled": !root.isEnabled
};
} }
function setLat(lat) { function setLat(lat) {