Weather: fixed polling + improved WeatherCard with a NBusyIndicator if not ready yet
This commit is contained in:
parent
03687f95f3
commit
4fc4c94a47
3 changed files with 30 additions and 6 deletions
|
|
@ -6,7 +6,7 @@ import Quickshell.Wayland
|
||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
// LazyLoader for WiFi menu
|
// Loader for WiFi menu
|
||||||
NLoader {
|
NLoader {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
|
import Quickshell
|
||||||
import qs.Services
|
import qs.Services
|
||||||
import qs.Widgets
|
import qs.Widgets
|
||||||
|
|
||||||
|
|
@ -8,6 +9,7 @@ NBox {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
readonly property real scaling: Scaling.scale(screen)
|
readonly property real scaling: Scaling.scale(screen)
|
||||||
|
readonly property bool weatherReady: (Location.data.weather !== null)
|
||||||
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
// Height driven by content
|
// Height driven by content
|
||||||
|
|
@ -24,11 +26,12 @@ NBox {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
spacing: Style.marginSmall * scaling
|
spacing: Style.marginSmall * scaling
|
||||||
NText {
|
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.family: "Material Symbols Outlined"
|
||||||
font.pointSize: Style.fontSizeXXL * 1.25 * scaling
|
font.pointSize: Style.fontSizeXXL * 1.25 * scaling
|
||||||
color: Colors.accentSecondary
|
color: Colors.accentSecondary
|
||||||
}
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
RowLayout {
|
RowLayout {
|
||||||
NText {
|
NText {
|
||||||
|
|
@ -37,14 +40,18 @@ NBox {
|
||||||
font.pointSize: Style.fontSizeXL * scaling
|
font.pointSize: Style.fontSizeXL * scaling
|
||||||
}
|
}
|
||||||
NText {
|
NText {
|
||||||
text: `(${Location.data.weather.timezone_abbreviation})`
|
text: weatherReady ? `(${Location.data.weather.timezone_abbreviation})` : ""
|
||||||
font.pointSize: Style.fontSizeSmall * scaling
|
font.pointSize: Style.fontSizeSmall * scaling
|
||||||
visible: Location.data.weather
|
visible: Location.data.weather
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NText {
|
NText {
|
||||||
|
visible: weatherReady
|
||||||
text: {
|
text: {
|
||||||
|
if (!weatherReady) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
var temp = Location.data.weather.current_weather.temperature
|
var temp = Location.data.weather.current_weather.temperature
|
||||||
if (Settings.data.location.useFahrenheit) {
|
if (Settings.data.location.useFahrenheit) {
|
||||||
temp = Location.celsiusToFahrenheit(temp)
|
temp = Location.celsiusToFahrenheit(temp)
|
||||||
|
|
@ -59,15 +66,17 @@ NBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
NDivider {
|
NDivider {
|
||||||
|
visible: weatherReady
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
}
|
}
|
||||||
|
|
||||||
RowLayout {
|
RowLayout {
|
||||||
|
visible: weatherReady
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
spacing: Style.marginLarge * scaling
|
spacing: Style.marginLarge * scaling
|
||||||
Repeater {
|
Repeater {
|
||||||
model: Location.data.weather.daily.time
|
model: weatherReady ? Location.data.weather.daily.time : []
|
||||||
delegate: ColumnLayout {
|
delegate: ColumnLayout {
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
spacing: Style.spacingSmall * scaling
|
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 {
|
Timer {
|
||||||
id: updateTimer
|
id: updateTimer
|
||||||
interval: 60 * 1000
|
interval: 60 * 1000
|
||||||
|
running: true
|
||||||
repeat: true
|
repeat: true
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
updateWeather()
|
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.longitude = ""
|
||||||
data.weatherLastFetch = 0
|
data.weatherLastFetch = 0
|
||||||
data.weather = null
|
data.weather = null
|
||||||
|
|
||||||
|
// Try to fetch immediately
|
||||||
|
updateWeather();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
function updateWeather() {
|
function updateWeather() {
|
||||||
if (isFetchingWeather) {
|
if (isFetchingWeather) {
|
||||||
|
console.warn("Weather is still fetching")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue