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

greeter: fix weather setting

fixes #921
This commit is contained in:
bbedward
2025-12-08 13:45:26 -05:00
parent 52fcd3ad98
commit f9d8a7d22b
2 changed files with 60 additions and 36 deletions

View File

@@ -4,6 +4,7 @@ import QtQuick.Controls
import QtQuick.Effects import QtQuick.Effects
import QtQuick.Layouts import QtQuick.Layouts
import Quickshell import Quickshell
import Quickshell.Hyprland
import Quickshell.Io import Quickshell.Io
import Quickshell.Services.Greetd import Quickshell.Services.Greetd
import Quickshell.Services.Pam import Quickshell.Services.Pam
@@ -35,19 +36,40 @@ Item {
randomFact = Facts.getRandomFact() randomFact = Facts.getRandomFact()
} }
property bool weatherInitialized: false
function initWeatherService() {
if (weatherInitialized)
return
if (!GreetdSettings.settingsLoaded)
return
if (!GreetdSettings.weatherEnabled)
return
weatherInitialized = true
WeatherService.addRef()
WeatherService.forceRefresh()
}
Connections {
target: GreetdSettings
function onSettingsLoadedChanged() {
if (GreetdSettings.settingsLoaded)
initWeatherService()
}
}
Component.onCompleted: { Component.onCompleted: {
pickRandomFact() pickRandomFact()
WeatherService.addRef() initWeatherService()
if (isPrimaryScreen) { if (isPrimaryScreen) {
sessionListProc.running = true sessionListProc.running = true
applyLastSuccessfulUser() applyLastSuccessfulUser()
} }
if (CompositorService.isHyprland) { if (CompositorService.isHyprland)
updateHyprlandLayout() updateHyprlandLayout()
hyprlandLayoutUpdateTimer.start()
}
} }
function applyLastSuccessfulUser() { function applyLastSuccessfulUser() {
@@ -61,10 +83,8 @@ Item {
} }
Component.onDestruction: { Component.onDestruction: {
if (weatherInitialized)
WeatherService.removeRef() WeatherService.removeRef()
if (CompositorService.isHyprland) {
hyprlandLayoutUpdateTimer.stop()
}
} }
function updateHyprlandLayout() { function updateHyprlandLayout() {
@@ -106,14 +126,15 @@ Item {
} }
} }
Timer { Connections {
id: hyprlandLayoutUpdateTimer target: CompositorService.isHyprland ? Hyprland : null
interval: 1000 enabled: CompositorService.isHyprland
running: false
repeat: true
onTriggered: updateHyprlandLayout()
}
function onRawEvent(event) {
if (event.name === "activelayout")
updateHyprlandLayout()
}
}
Connections { Connections {
target: GreetdMemory target: GreetdMemory
@@ -750,13 +771,13 @@ Item {
visible: { visible: {
const keyboardVisible = (CompositorService.isNiri && NiriService.keyboardLayoutNames.length > 1) || const keyboardVisible = (CompositorService.isNiri && NiriService.keyboardLayoutNames.length > 1) ||
(CompositorService.isHyprland && hyprlandLayoutCount > 1) (CompositorService.isHyprland && hyprlandLayoutCount > 1)
return keyboardVisible && WeatherService.weather.available return keyboardVisible && GreetdSettings.weatherEnabled && WeatherService.weather.available
} }
} }
Row { Row {
spacing: 6 spacing: 6
visible: WeatherService.weather.available visible: GreetdSettings.weatherEnabled && WeatherService.weather.available
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
DankIcon { DankIcon {
@@ -780,7 +801,7 @@ Item {
height: 24 height: 24
color: Qt.rgba(255, 255, 255, 0.2) color: Qt.rgba(255, 255, 255, 0.2)
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
visible: WeatherService.weather.available && (NetworkService.networkStatus !== "disconnected" || BluetoothService.enabled || (AudioService.sink && AudioService.sink.audio) || BatteryService.batteryAvailable) visible: GreetdSettings.weatherEnabled && WeatherService.weather.available && (NetworkService.networkStatus !== "disconnected" || BluetoothService.enabled || (AudioService.sink && AudioService.sink.audio) || BatteryService.batteryAvailable)
} }
Row { Row {

View File

@@ -5,6 +5,7 @@ import QtQuick
import Quickshell import Quickshell
import Quickshell.Io import Quickshell.Io
import qs.Common import qs.Common
import qs.Modules.Greetd
import "../Common/suncalc.js" as SunCalc import "../Common/suncalc.js" as SunCalc
Singleton { Singleton {
@@ -509,10 +510,15 @@ Singleton {
} }
function updateLocation() { function updateLocation() {
if (SettingsData.useAutoLocation) { const useAuto = SessionData.isGreeterMode ? GreetdSettings.useAutoLocation : SettingsData.useAutoLocation;
const coords = SessionData.isGreeterMode ? GreetdSettings.weatherCoordinates : SettingsData.weatherCoordinates;
const cityName = SessionData.isGreeterMode ? GreetdSettings.weatherLocation : SettingsData.weatherLocation;
if (useAuto) {
getLocationFromIP(); getLocationFromIP();
} else { return;
const coords = SettingsData.weatherCoordinates; }
if (coords) { if (coords) {
const parts = coords.split(","); const parts = coords.split(",");
if (parts.length === 2) { if (parts.length === 2) {
@@ -525,12 +531,9 @@ Singleton {
} }
} }
const cityName = SettingsData.weatherLocation; if (cityName)
if (cityName) {
getLocationFromCity(cityName); getLocationFromCity(cityName);
} }
}
}
function getLocationFromCoords(lat, lon) { function getLocationFromCoords(lat, lon) {
const url = "https://nominatim.openstreetmap.org/reverse?lat=" + lat + "&lon=" + lon + "&format=json&addressdetails=1&accept-language=en"; const url = "https://nominatim.openstreetmap.org/reverse?lat=" + lat + "&lon=" + lon + "&format=json&addressdetails=1&accept-language=en";
@@ -867,7 +870,7 @@ Singleton {
Timer { Timer {
id: updateTimer id: updateTimer
interval: nextInterval() interval: nextInterval()
running: root.refCount > 0 && SettingsData.weatherEnabled running: root.refCount > 0 && SettingsData.weatherEnabled && !SessionData.isGreeterMode
repeat: true repeat: true
triggeredOnStart: true triggeredOnStart: true
onTriggered: { onTriggered: {