feat: enhance weather card colors & refactor shellstate & settings
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user