1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-30 00:12:50 -05:00

weather: fix fahrenheit conversion

This commit is contained in:
bbedward
2025-11-21 22:07:44 -05:00
parent c0ae3ef58b
commit bcfa508da5
3 changed files with 88 additions and 85 deletions

View File

@@ -2,19 +2,16 @@ import QtQuick
import QtQuick.Effects import QtQuick.Effects
import Quickshell import Quickshell
import Quickshell.Wayland import Quickshell.Wayland
import Quickshell.Widgets
import Quickshell.Io
import qs.Common import qs.Common
import qs.Widgets import qs.Widgets
import qs.Modules
import qs.Services import qs.Services
Variants { Variants {
model: { model: {
if (SessionData.isGreeterMode) { if (SessionData.isGreeterMode) {
return Quickshell.screens return Quickshell.screens;
} }
return SettingsData.getFilteredScreens("wallpaper") return SettingsData.getFilteredScreens("wallpaper");
} }
PanelWindow { PanelWindow {
@@ -50,9 +47,9 @@ Variants {
target: SessionData target: SessionData
function onIsLightModeChanged() { function onIsLightModeChanged() {
if (SessionData.perModeWallpaper) { if (SessionData.perModeWallpaper) {
var newSource = SessionData.getMonitorWallpaper(modelData.name) || "" var newSource = SessionData.getMonitorWallpaper(modelData.name) || "";
if (newSource !== root.source) { if (newSource !== root.source) {
root.source = newSource root.source = newSource;
} }
} }
} }
@@ -61,32 +58,32 @@ Variants {
function getFillMode(modeName) { function getFillMode(modeName) {
switch (modeName) { switch (modeName) {
case "Stretch": case "Stretch":
return Image.Stretch return Image.Stretch;
case "Fit": case "Fit":
case "PreserveAspectFit": case "PreserveAspectFit":
return Image.PreserveAspectFit return Image.PreserveAspectFit;
case "Fill": case "Fill":
case "PreserveAspectCrop": case "PreserveAspectCrop":
return Image.PreserveAspectCrop return Image.PreserveAspectCrop;
case "Tile": case "Tile":
return Image.Tile return Image.Tile;
case "TileVertically": case "TileVertically":
return Image.TileVertically return Image.TileVertically;
case "TileHorizontally": case "TileHorizontally":
return Image.TileHorizontally return Image.TileHorizontally;
case "Pad": case "Pad":
return Image.Pad return Image.Pad;
default: default:
return Image.PreserveAspectCrop return Image.PreserveAspectCrop;
} }
} }
Component.onCompleted: { Component.onCompleted: {
if (source) { if (source) {
const formattedSource = source.startsWith("file://") ? source : "file://" + source const formattedSource = source.startsWith("file://") ? source : "file://" + source;
setWallpaperImmediate(formattedSource) setWallpaperImmediate(formattedSource);
} }
isInitialized = true isInitialized = true;
} }
property bool isInitialized: false property bool isInitialized: false
@@ -94,55 +91,54 @@ Variants {
readonly property bool transitioning: transitionAnimation.running readonly property bool transitioning: transitionAnimation.running
onSourceChanged: { onSourceChanged: {
const isColor = source.startsWith("#") const isColor = source.startsWith("#");
if (!source) { if (!source) {
setWallpaperImmediate("") setWallpaperImmediate("");
} else if (isColor) { } else if (isColor) {
setWallpaperImmediate("") setWallpaperImmediate("");
} else { } else {
if (!isInitialized || !currentWallpaper.source) { if (!isInitialized || !currentWallpaper.source) {
setWallpaperImmediate(source.startsWith("file://") ? source : "file://" + source) setWallpaperImmediate(source.startsWith("file://") ? source : "file://" + source);
isInitialized = true isInitialized = true;
} else if (CompositorService.isNiri && SessionData.isSwitchingMode) { } else if (CompositorService.isNiri && SessionData.isSwitchingMode) {
setWallpaperImmediate(source.startsWith("file://") ? source : "file://" + source) setWallpaperImmediate(source.startsWith("file://") ? source : "file://" + source);
} else { } else {
changeWallpaper(source.startsWith("file://") ? source : "file://" + source) changeWallpaper(source.startsWith("file://") ? source : "file://" + source);
} }
} }
} }
function setWallpaperImmediate(newSource) { function setWallpaperImmediate(newSource) {
transitionAnimation.stop() transitionAnimation.stop();
root.transitionProgress = 0.0 root.transitionProgress = 0.0;
currentWallpaper.source = newSource currentWallpaper.source = newSource;
nextWallpaper.source = "" nextWallpaper.source = "";
currentWallpaper.opacity = 1 currentWallpaper.opacity = 1;
nextWallpaper.opacity = 0 nextWallpaper.opacity = 0;
} }
function changeWallpaper(newPath) { function changeWallpaper(newPath) {
if (newPath === currentWallpaper.source) if (newPath === currentWallpaper.source)
return return;
if (!newPath || newPath.startsWith("#")) if (!newPath || newPath.startsWith("#"))
return return;
if (root.transitioning) { if (root.transitioning) {
transitionAnimation.stop() transitionAnimation.stop();
root.transitionProgress = 0 root.transitionProgress = 0;
currentWallpaper.source = nextWallpaper.source currentWallpaper.source = nextWallpaper.source;
nextWallpaper.source = "" nextWallpaper.source = "";
} }
if (!currentWallpaper.source) { if (!currentWallpaper.source) {
setWallpaperImmediate(newPath) setWallpaperImmediate(newPath);
return return;
} }
nextWallpaper.source = newPath nextWallpaper.source = newPath;
if (nextWallpaper.status === Image.Ready) { if (nextWallpaper.status === Image.Ready) {
transitionAnimation.start() transitionAnimation.start();
} }
} }
@@ -179,10 +175,9 @@ Variants {
onStatusChanged: { onStatusChanged: {
if (status !== Image.Ready) if (status !== Image.Ready)
return return;
if (!root.transitioning) { if (!root.transitioning) {
transitionAnimation.start() transitionAnimation.start();
} }
} }
} }
@@ -222,14 +217,14 @@ Variants {
easing.type: Easing.InOutCubic easing.type: Easing.InOutCubic
onFinished: { onFinished: {
Qt.callLater(() => { Qt.callLater(() => {
if (nextWallpaper.source && nextWallpaper.status === Image.Ready && !nextWallpaper.source.toString().startsWith("#")) { if (nextWallpaper.source && nextWallpaper.status === Image.Ready && !nextWallpaper.source.toString().startsWith("#")) {
currentWallpaper.source = nextWallpaper.source currentWallpaper.source = nextWallpaper.source;
} }
nextWallpaper.source = "" nextWallpaper.source = "";
currentWallpaper.opacity = 1 currentWallpaper.opacity = 1;
nextWallpaper.opacity = 0 nextWallpaper.opacity = 0;
root.transitionProgress = 0.0 root.transitionProgress = 0.0;
}) });
} }
} }
} }

View File

@@ -1,9 +1,4 @@
import QtQuick import QtQuick
import QtQuick.Effects
import Quickshell
import Quickshell.Io
import Quickshell.Wayland
import Quickshell.Widgets
import qs.Common import qs.Common
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
@@ -42,7 +37,7 @@ DankPopout {
onShouldBeVisibleChanged: { onShouldBeVisibleChanged: {
if (shouldBeVisible) { if (shouldBeVisible) {
if (SystemUpdateService.updateCount === 0 && !SystemUpdateService.isChecking) { if (SystemUpdateService.updateCount === 0 && !SystemUpdateService.isChecking) {
SystemUpdateService.checkForUpdates() SystemUpdateService.checkForUpdates();
} }
} }
} }
@@ -57,19 +52,23 @@ DankPopout {
smooth: true smooth: true
Repeater { Repeater {
model: [{ model: [
{
"margin": -3, "margin": -3,
"color": Qt.rgba(0, 0, 0, 0.05), "color": Qt.rgba(0, 0, 0, 0.05),
"z": -3 "z": -3
}, { },
{
"margin": -2, "margin": -2,
"color": Qt.rgba(0, 0, 0, 0.08), "color": Qt.rgba(0, 0, 0, 0.08),
"z": -2 "z": -2
}, { },
{
"margin": 0, "margin": 0,
"color": Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12), "color": Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.12),
"z": -1 "z": -1
}] }
]
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
anchors.margins: modelData.margin anchors.margins: modelData.margin
@@ -109,14 +108,18 @@ DankPopout {
StyledText { StyledText {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: { text: {
if (SystemUpdateService.isChecking) return "Checking..."; if (SystemUpdateService.isChecking)
if (SystemUpdateService.hasError) return "Error"; return "Checking...";
if (SystemUpdateService.updateCount === 0) return "Up to date"; if (SystemUpdateService.hasError)
return "Error";
if (SystemUpdateService.updateCount === 0)
return "Up to date";
return SystemUpdateService.updateCount + " updates"; return SystemUpdateService.updateCount + " updates";
} }
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
color: { color: {
if (SystemUpdateService.hasError) return Theme.error; if (SystemUpdateService.hasError)
return Theme.error;
return Theme.surfaceText; return Theme.surfaceText;
} }
} }
@@ -131,7 +134,7 @@ DankPopout {
enabled: !SystemUpdateService.isChecking enabled: !SystemUpdateService.isChecking
opacity: enabled ? 1.0 : 0.5 opacity: enabled ? 1.0 : 0.5
onClicked: { onClicked: {
SystemUpdateService.checkForUpdates() SystemUpdateService.checkForUpdates();
} }
RotationAnimation { RotationAnimation {
@@ -145,7 +148,7 @@ DankPopout {
onRunningChanged: { onRunningChanged: {
if (!running) { if (!running) {
checkForUpdatesButton.rotation = 0 checkForUpdatesButton.rotation = 0;
} }
} }
} }
@@ -156,9 +159,9 @@ DankPopout {
Rectangle { Rectangle {
width: parent.width width: parent.width
height: { height: {
let usedHeight = 40 + Theme.spacingL let usedHeight = 40 + Theme.spacingL;
usedHeight += 48 + Theme.spacingL usedHeight += 48 + Theme.spacingL;
return parent.height - usedHeight return parent.height - usedHeight;
} }
radius: Theme.cornerRadius radius: Theme.cornerRadius
color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.1) color: Qt.rgba(Theme.surfaceVariant.r, Theme.surfaceVariant.g, Theme.surfaceVariant.b, 0.1)
@@ -190,7 +193,8 @@ DankPopout {
} }
font.pixelSize: Theme.fontSizeMedium font.pixelSize: Theme.fontSizeMedium
color: { color: {
if (SystemUpdateService.hasError) return Theme.errorText; if (SystemUpdateService.hasError)
return Theme.errorText;
return Theme.surfaceText; return Theme.surfaceText;
} }
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
@@ -246,7 +250,9 @@ DankPopout {
} }
Behavior on color { Behavior on color {
ColorAnimation { duration: Theme.shortDuration } ColorAnimation {
duration: Theme.shortDuration
}
} }
MouseArea { MouseArea {
@@ -274,7 +280,9 @@ DankPopout {
opacity: SystemUpdateService.updateCount > 0 ? 1.0 : 0.5 opacity: SystemUpdateService.updateCount > 0 ? 1.0 : 0.5
Behavior on color { Behavior on color {
ColorAnimation { duration: Theme.shortDuration } ColorAnimation {
duration: Theme.shortDuration
}
} }
Row { Row {
@@ -304,13 +312,12 @@ DankPopout {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
enabled: SystemUpdateService.updateCount > 0 enabled: SystemUpdateService.updateCount > 0
onClicked: { onClicked: {
SystemUpdateService.runUpdates() SystemUpdateService.runUpdates();
systemUpdatePopout.close() systemUpdatePopout.close();
} }
} }
} }
Rectangle { Rectangle {
width: (parent.width - Theme.spacingM) / 2 width: (parent.width - Theme.spacingM) / 2
height: parent.height height: parent.height
@@ -318,7 +325,9 @@ DankPopout {
color: closeMouseArea.containsMouse ? Theme.errorPressed : Theme.secondaryHover color: closeMouseArea.containsMouse ? Theme.errorPressed : Theme.secondaryHover
Behavior on color { Behavior on color {
ColorAnimation { duration: Theme.shortDuration } ColorAnimation {
duration: Theme.shortDuration
}
} }
Row { Row {
@@ -347,13 +356,12 @@ DankPopout {
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
systemUpdatePopout.close() systemUpdatePopout.close();
} }
} }
} }
} }
} }
} }
} }
} }

View File

@@ -467,17 +467,17 @@ Singleton {
const currentUnits = data.current_units || {} const currentUnits = data.current_units || {}
const tempC = current.temperature_2m || 0 const tempC = current.temperature_2m || 0
const tempF = SettingsData.useFahrenheit ? tempC : (tempC * 9/5 + 32) const tempF = (tempC * 9/5 + 32)
const feelsLikeC = current.apparent_temperature || tempC const feelsLikeC = current.apparent_temperature || tempC
const feelsLikeF = SettingsData.useFahrenheit ? feelsLikeC : (feelsLikeC * 9/5 + 32) const feelsLikeF = (feelsLikeC * 9/5 + 32)
const forecast = [] const forecast = []
if (daily.time && daily.time.length > 0) { if (daily.time && daily.time.length > 0) {
for (let i = 0; i < Math.min(daily.time.length, 7); i++) { for (let i = 0; i < Math.min(daily.time.length, 7); i++) {
const tempMinC = daily.temperature_2m_min?.[i] || 0 const tempMinC = daily.temperature_2m_min?.[i] || 0
const tempMaxC = daily.temperature_2m_max?.[i] || 0 const tempMaxC = daily.temperature_2m_max?.[i] || 0
const tempMinF = SettingsData.useFahrenheit ? tempMinC : (tempMinC * 9/5 + 32) const tempMinF = (tempMinC * 9/5 + 32)
const tempMaxF = SettingsData.useFahrenheit ? tempMaxC : (tempMaxC * 9/5 + 32) const tempMaxF = (tempMaxC * 9/5 + 32)
forecast.push({ forecast.push({
"day": formatForecastDay(daily.time[i], i), "day": formatForecastDay(daily.time[i], i),