feat: dashboard show on hover, media and weather tabs added
This commit is contained in:
+28
-7
@@ -3,25 +3,36 @@ pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import ZShell
|
||||
import ZShell.Internal
|
||||
import ZShell.Config
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
readonly property var cachedCities: new Map()
|
||||
property var cc
|
||||
property string city
|
||||
readonly property string description: cc?.weatherDesc ?? qsTr("No weather")
|
||||
readonly property string feelsLike: formatTemp(cc?.feelsLikeC)
|
||||
property list<var> forecast
|
||||
property list<var> hourlyForecast
|
||||
readonly property int humidity: cc?.humidity ?? 0
|
||||
readonly property string icon: cc ? Icons.getWeatherIcon(cc.weatherCode) : "cloud_alert"
|
||||
property string loc
|
||||
readonly property string sunrise: cc ? Qt.formatDateTime(new Date(cc.sunrise), Config.services.useTwelveHourClock ? "h:mm A" : "h:mm") : "--:--"
|
||||
readonly property string sunset: cc ? Qt.formatDateTime(new Date(cc.sunset), Config.services.useTwelveHourClock ? "h:mm A" : "h:mm") : "--:--"
|
||||
readonly property string temp: formatTemp(cc?.tempC)
|
||||
readonly property real windSpeed: cc?.windSpeed ?? 0
|
||||
readonly property CircularBuffer precipitationForecast: precipitationBuffer
|
||||
|
||||
property var cc
|
||||
property string city
|
||||
property list<var> forecast
|
||||
property list<var> hourlyForecast
|
||||
readonly property int currentHourIndex: {
|
||||
const now = new Date();
|
||||
for (let i = 0; i < hourlyForecast.length; i++) {
|
||||
if (new Date(hourlyForecast[i].timestamp.replace("T", " ")) >= now)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
property string loc
|
||||
|
||||
function fetchCityFromCoords(coords: string): void {
|
||||
if (cachedCities.has(coords)) {
|
||||
@@ -112,11 +123,12 @@ Singleton {
|
||||
forecast = forecastList;
|
||||
|
||||
const hourlyList = [];
|
||||
const now = new Date();
|
||||
const startOfToday = new Date();
|
||||
startOfToday.setHours(0, 0, 0, 0);
|
||||
for (let i = 0; i < json.hourly.time.length; i++) {
|
||||
const time = new Date(json.hourly.time[i].replace("T", " "));
|
||||
|
||||
if (time < now)
|
||||
if (time < startOfToday)
|
||||
continue;
|
||||
|
||||
hourlyList.push({
|
||||
@@ -129,6 +141,10 @@ Singleton {
|
||||
});
|
||||
}
|
||||
hourlyForecast = hourlyList;
|
||||
precipitationBuffer.clear();
|
||||
|
||||
for (const hour of hourlyList)
|
||||
precipitationBuffer.push(hour.precipChance);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -258,6 +274,11 @@ Singleton {
|
||||
|
||||
onLocChanged: fetchWeatherData()
|
||||
|
||||
CircularBuffer {
|
||||
id: precipitationBuffer
|
||||
capacity: 24
|
||||
}
|
||||
|
||||
Connections {
|
||||
function onWeatherLocationChanged(): void {
|
||||
root.reload();
|
||||
|
||||
Reference in New Issue
Block a user