mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2025-12-06 06:36:15 +00:00
Weather: fixed polling + improved WeatherCard with a NBusyIndicator if not ready yet
This commit is contained in:
@@ -6,7 +6,7 @@ import Quickshell.Wayland
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
// LazyLoader for WiFi menu
|
||||
// Loader for WiFi menu
|
||||
NLoader {
|
||||
id: root
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
@@ -8,6 +9,7 @@ NBox {
|
||||
id: root
|
||||
|
||||
readonly property real scaling: Scaling.scale(screen)
|
||||
readonly property bool weatherReady: (Location.data.weather !== null)
|
||||
|
||||
Layout.fillWidth: true
|
||||
// Height driven by content
|
||||
@@ -24,11 +26,12 @@ NBox {
|
||||
RowLayout {
|
||||
spacing: Style.marginSmall * scaling
|
||||
NText {
|
||||
text: Location.weatherSymbolFromCode(Location.data.weather.current_weather.weathercode)
|
||||
text: weatherReady ? Location.weatherSymbolFromCode(Location.data.weather.current_weather.weathercode) : ""
|
||||
font.family: "Material Symbols Outlined"
|
||||
font.pointSize: Style.fontSizeXXL * 1.25 * scaling
|
||||
color: Colors.accentSecondary
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
RowLayout {
|
||||
NText {
|
||||
@@ -37,14 +40,18 @@ NBox {
|
||||
font.pointSize: Style.fontSizeXL * scaling
|
||||
}
|
||||
NText {
|
||||
text: `(${Location.data.weather.timezone_abbreviation})`
|
||||
text: weatherReady ? `(${Location.data.weather.timezone_abbreviation})` : ""
|
||||
font.pointSize: Style.fontSizeSmall * scaling
|
||||
visible: Location.data.weather
|
||||
}
|
||||
}
|
||||
|
||||
NText {
|
||||
visible: weatherReady
|
||||
text: {
|
||||
if (!weatherReady) {
|
||||
return ""
|
||||
}
|
||||
var temp = Location.data.weather.current_weather.temperature
|
||||
if (Settings.data.location.useFahrenheit) {
|
||||
temp = Location.celsiusToFahrenheit(temp)
|
||||
@@ -59,15 +66,17 @@ NBox {
|
||||
}
|
||||
|
||||
NDivider {
|
||||
visible: weatherReady
|
||||
Layout.fillWidth: true
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
visible: weatherReady
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
spacing: Style.marginLarge* scaling
|
||||
spacing: Style.marginLarge * scaling
|
||||
Repeater {
|
||||
model: Location.data.weather.daily.time
|
||||
model: weatherReady ? Location.data.weather.daily.time : []
|
||||
delegate: ColumnLayout {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
spacing: Style.spacingSmall * scaling
|
||||
@@ -99,5 +108,12 @@ NBox {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RowLayout {
|
||||
visible: !weatherReady
|
||||
Layout.fillWidth: true
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
NBusyIndicator {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,9 +41,11 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
// Every minute check if we need to fetch new weather
|
||||
Timer {
|
||||
id: updateTimer
|
||||
interval: 60 * 1000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
updateWeather()
|
||||
@@ -51,7 +53,9 @@ Singleton {
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
function init() {// does nothing but ensure the singleton is created
|
||||
function init() {
|
||||
// does nothing but ensure the singleton is created
|
||||
// do not remove
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
@@ -60,11 +64,15 @@ Singleton {
|
||||
data.longitude = ""
|
||||
data.weatherLastFetch = 0
|
||||
data.weather = null
|
||||
|
||||
// Try to fetch immediately
|
||||
updateWeather();
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
function updateWeather() {
|
||||
if (isFetchingWeather) {
|
||||
console.warn("Weather is still fetching")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user