mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2025-12-06 06:36:15 +00:00
Location: should fix edge case of location data being not ready on time
This commit is contained in:
@@ -26,7 +26,7 @@ Singleton {
|
||||
property string defaultAvatar: Quickshell.env("HOME") + "/.face"
|
||||
|
||||
// Used to access via Settings.data.xxx.yyy
|
||||
property alias data: adapter
|
||||
readonly property alias data: adapter
|
||||
|
||||
property bool isLoaded: false
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ ColumnLayout {
|
||||
|
||||
NToggle {
|
||||
label: "Automatic Scheduling"
|
||||
description: `Based on the sunset and sunrise time in <i>${LocationService.data.stableName}</i> - recommended.`
|
||||
description: `Based on the sunset and sunrise time in <i>${LocationService.stableName}</i> - recommended.`
|
||||
checked: Settings.data.nightLight.autoSchedule
|
||||
onToggled: checked => Settings.data.nightLight.autoSchedule = checked
|
||||
visible: Settings.data.nightLight.enabled
|
||||
|
||||
@@ -30,8 +30,8 @@ ColumnLayout {
|
||||
}
|
||||
|
||||
NText {
|
||||
visible: LocationService.data.coordinatesReady
|
||||
text: `${LocationService.data.stableName} (${LocationService.displayCoordinates})`
|
||||
visible: LocationService.coordinatesReady
|
||||
text: `${LocationService.stableName} (${LocationService.displayCoordinates})`
|
||||
font.pointSize: Style.fontSizeS * scaling
|
||||
color: Color.mOnSurfaceVariant
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
|
||||
@@ -13,7 +13,7 @@ Singleton {
|
||||
property string githubDataFile: Quickshell.env("NOCTALIA_GITHUB_FILE") || (Settings.cacheDir + "github.json")
|
||||
property int githubUpdateFrequency: 60 * 60 // 1 hour expressed in seconds
|
||||
property bool isFetchingData: false
|
||||
property alias data: adapter // Used to access via GitHubService.data.xxx.yyy
|
||||
readonly property alias data: adapter // Used to access via GitHubService.data.xxx.yyy
|
||||
|
||||
// Public properties for easy access
|
||||
property string latestVersion: "Unknown"
|
||||
|
||||
@@ -13,18 +13,27 @@ Singleton {
|
||||
property string locationFile: Quickshell.env("NOCTALIA_WEATHER_FILE") || (Settings.cacheDir + "location.json")
|
||||
property int weatherUpdateFrequency: 30 * 60 // 30 minutes expressed in seconds
|
||||
property bool isFetchingWeather: false
|
||||
property alias data: adapter // Used to access via LocationService.data.xxx
|
||||
|
||||
readonly property alias data: adapter // Used to access via LocationService.data.xxx from outside, best to use "adapter" inside the service.
|
||||
|
||||
// Stable UI properties - only updated when location is fully resolved
|
||||
property bool coordinatesReady: false
|
||||
property string stableLatitude: ""
|
||||
property string stableLongitude: ""
|
||||
property string stableName: ""
|
||||
|
||||
FileView {
|
||||
id: locationFileView
|
||||
path: locationFile
|
||||
onAdapterUpdated: saveTimer.start()
|
||||
onLoaded: {
|
||||
Logger.log("Location", "Loaded cached data")
|
||||
// Initialize stable properties on load
|
||||
if (adapter.latitude !== "" && adapter.longitude !== "" && adapter.weatherLastFetch > 0) {
|
||||
adapter.stableLatitude = adapter.latitude
|
||||
adapter.stableLongitude = adapter.longitude
|
||||
adapter.coordinatesReady = true
|
||||
root.stableLatitude = adapter.latitude
|
||||
root.stableLongitude = adapter.longitude
|
||||
root.coordinatesReady = true
|
||||
Logger.log("Location", "Coordinates ready")
|
||||
}
|
||||
updateWeather()
|
||||
}
|
||||
@@ -42,21 +51,17 @@ Singleton {
|
||||
property int weatherLastFetch: 0
|
||||
property var weather: null
|
||||
|
||||
// Stable UI properties - only updated when location is fully resolved
|
||||
property bool coordinatesReady: false
|
||||
property string stableLatitude: ""
|
||||
property string stableLongitude: ""
|
||||
property string stableName: ""
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Helper property for UI components (outside JsonAdapter to avoid binding loops)
|
||||
readonly property string displayCoordinates: {
|
||||
if (!data.coordinatesReady || data.stableLatitude === "" || data.stableLongitude === "") {
|
||||
if (!root.coordinatesReady || root.stableLatitude === "" || root.stableLongitude === "") {
|
||||
return ""
|
||||
}
|
||||
const lat = parseFloat(data.stableLatitude).toFixed(4)
|
||||
const lon = parseFloat(data.stableLongitude).toFixed(4)
|
||||
const lat = parseFloat(root.stableLatitude).toFixed(4)
|
||||
const lon = parseFloat(root.stableLongitude).toFixed(4)
|
||||
return `${lat}, ${lon}`
|
||||
}
|
||||
|
||||
@@ -90,19 +95,18 @@ Singleton {
|
||||
Logger.log("Location", "Resetting weather data")
|
||||
|
||||
// Mark as changing to prevent UI updates
|
||||
data.coordinatesReady = false
|
||||
root.coordinatesReady = false
|
||||
// Reset stable properties
|
||||
root.stableLatitude = ""
|
||||
root.stableLongitude = ""
|
||||
root.stableName = ""
|
||||
|
||||
// Reset core data
|
||||
data.latitude = ""
|
||||
data.longitude = ""
|
||||
data.name = ""
|
||||
data.weatherLastFetch = 0
|
||||
data.weather = null
|
||||
|
||||
// Reset stable properties
|
||||
data.stableLatitude = ""
|
||||
data.stableLongitude = ""
|
||||
data.stableName = ""
|
||||
adapter.latitude = ""
|
||||
adapter.longitude = ""
|
||||
adapter.name = ""
|
||||
adapter.weatherLastFetch = 0
|
||||
adapter.weather = null
|
||||
|
||||
// Try to fetch immediately
|
||||
updateWeather()
|
||||
@@ -115,9 +119,9 @@ Singleton {
|
||||
return
|
||||
}
|
||||
|
||||
if ((data.weatherLastFetch === "") || (data.weather === null) || (data.latitude === "") || (data.longitude === "")
|
||||
|| (data.name !== Settings.data.location.name)
|
||||
|| (Time.timestamp >= data.weatherLastFetch + weatherUpdateFrequency)) {
|
||||
if ((adapter.weatherLastFetch === "") || (adapter.weather === null) || (adapter.latitude === "") || (adapter.longitude === "")
|
||||
|| (adapter.name !== Settings.data.location.name)
|
||||
|| (Time.timestamp >= adapter.weatherLastFetch + weatherUpdateFrequency)) {
|
||||
getFreshWeather()
|
||||
}
|
||||
}
|
||||
@@ -129,28 +133,28 @@ Singleton {
|
||||
// Check if location name has changed
|
||||
const locationChanged = data.name !== Settings.data.location.name
|
||||
if (locationChanged) {
|
||||
data.coordinatesReady = false
|
||||
Logger.log("Location", "Location changed from", data.name, "to", Settings.data.location.name)
|
||||
root.coordinatesReady = false
|
||||
Logger.log("Location", "Location changed from", adapter.name, "to", Settings.data.location.name)
|
||||
}
|
||||
|
||||
if ((data.latitude === "") || (data.longitude === "") || locationChanged) {
|
||||
if ((adapter.latitude === "") || (adapter.longitude === "") || locationChanged) {
|
||||
|
||||
_geocodeLocation(Settings.data.location.name, function (latitude, longitude, name, country) {
|
||||
Logger.log("Location", "Geocoded", Settings.data.location.name, "to:", latitude, "/", longitude)
|
||||
|
||||
// Save location name
|
||||
data.name = Settings.data.location.name
|
||||
adapter.name = Settings.data.location.name
|
||||
|
||||
// Save GPS coordinates
|
||||
data.latitude = latitude.toString()
|
||||
data.longitude = longitude.toString()
|
||||
adapter.latitude = latitude.toString()
|
||||
adapter.longitude = longitude.toString()
|
||||
|
||||
data.stableName = `${name}, ${country}`
|
||||
root.stableName = `${name}, ${country}`
|
||||
|
||||
_fetchWeather(latitude, longitude, errorCallback)
|
||||
}, errorCallback)
|
||||
} else {
|
||||
_fetchWeather(data.latitude, data.longitude, errorCallback)
|
||||
_fetchWeather(adapter.latitude, adapter.longitude, errorCallback)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,9 +204,9 @@ Singleton {
|
||||
data.weatherLastFetch = Time.timestamp
|
||||
|
||||
// Update stable display values only when complete and successful
|
||||
data.stableLatitude = data.latitude = weatherData.latitude.toString()
|
||||
data.stableLongitude = data.longitude = weatherData.longitude.toString()
|
||||
data.coordinatesReady = true
|
||||
root.stableLatitude = data.latitude = weatherData.latitude.toString()
|
||||
root.stableLongitude = data.longitude = weatherData.longitude.toString()
|
||||
root.coordinatesReady = true
|
||||
|
||||
isFetchingWeather = false
|
||||
Logger.log("Location", "Cached weather to disk - stable coordinates updated")
|
||||
|
||||
@@ -31,7 +31,7 @@ Singleton {
|
||||
var cmd = ["wlsunset"]
|
||||
cmd.push("-t", `${params.nightTemp}`, "-T", `${params.dayTemp}`)
|
||||
if (params.autoSchedule) {
|
||||
cmd.push("-l", `${LocationService.data.stableLatitude}`, "-L", `${LocationService.data.stableLongitude}`)
|
||||
cmd.push("-l", `${LocationService.stableLatitude}`, "-L", `${LocationService.stableLongitude}`)
|
||||
} else {
|
||||
cmd.push("-S", params.manualSunrise)
|
||||
cmd.push("-s", params.manualSunset)
|
||||
@@ -55,9 +55,11 @@ Singleton {
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: LocationService.data
|
||||
target: LocationService
|
||||
function onCoordinatesReadyChanged() {
|
||||
apply()
|
||||
if (LocationService.coordinatesReady) {
|
||||
apply()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user