Location: fighting with a FileView issue?
This commit is contained in:
parent
ca8523ec1a
commit
f398f27741
1 changed files with 28 additions and 19 deletions
|
|
@ -10,7 +10,7 @@ Singleton {
|
||||||
|
|
||||||
property string locationFile: Quickshell.env("NOCTALIA_WEATHER_FILE") || (Settings.cacheDir + "location.json")
|
property string locationFile: Quickshell.env("NOCTALIA_WEATHER_FILE") || (Settings.cacheDir + "location.json")
|
||||||
property int weatherUpdateFrequency: 30 * 60 // 30 minutes expressed in seconds
|
property int weatherUpdateFrequency: 30 * 60 // 30 minutes expressed in seconds
|
||||||
property var data: adapter // Used to access via Location.data.xxx.yyy
|
property var data: adapter // Used to access via Location.data.xxx
|
||||||
property bool isFetchingWeather: false
|
property bool isFetchingWeather: false
|
||||||
|
|
||||||
FileView {
|
FileView {
|
||||||
|
|
@ -26,9 +26,9 @@ Singleton {
|
||||||
JsonAdapter {
|
JsonAdapter {
|
||||||
id: adapter
|
id: adapter
|
||||||
|
|
||||||
property string lastLocationName: ""
|
property string latitude: ""
|
||||||
property real latitude: 0
|
property string longitude: ""
|
||||||
property real longitude: 0
|
property string name: ""
|
||||||
property int weatherLastFetch: 0
|
property int weatherLastFetch: 0
|
||||||
property var weather: null
|
property var weather: null
|
||||||
}
|
}
|
||||||
|
|
@ -56,9 +56,9 @@ Singleton {
|
||||||
function resetWeather() {
|
function resetWeather() {
|
||||||
console.log("[Location] Resetting weather data")
|
console.log("[Location] Resetting weather data")
|
||||||
|
|
||||||
data.lastLocationName = ""
|
data.latitude = ""
|
||||||
data.latitude = 0
|
data.longitude = ""
|
||||||
data.longitude = 0
|
data.name = ""
|
||||||
data.weatherLastFetch = 0
|
data.weatherLastFetch = 0
|
||||||
data.weather = null
|
data.weather = null
|
||||||
|
|
||||||
|
|
@ -73,13 +73,17 @@ Singleton {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.latitude === 0) {
|
if (data.latitude === "") {
|
||||||
console.warn("[Location] Why is my latitude zero")
|
console.warn("[Location] Why is my latitude empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((data.weatherLastFetch === "") || (data.weather === null) || data.latitude === 0 || data.longitude === 0
|
if (
|
||||||
|| (data.lastLocationName !== Settings.data.location.name)
|
(data.weatherLastFetch === "") ||
|
||||||
|| (Time.timestamp >= data.weatherLastFetch + weatherUpdateFrequency)) {
|
(data.weather === null) ||
|
||||||
|
(data.latitude === "") ||
|
||||||
|
(data.longitude === "") ||
|
||||||
|
(data.name !== Settings.data.location.name)
|
||||||
|
|| (Time.timestamp >= data.weatherLastFetch + weatherUpdateFrequency)) {
|
||||||
getFreshWeather()
|
getFreshWeather()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -87,17 +91,22 @@ Singleton {
|
||||||
// --------------------------------
|
// --------------------------------
|
||||||
function getFreshWeather() {
|
function getFreshWeather() {
|
||||||
isFetchingWeather = true
|
isFetchingWeather = true
|
||||||
if (data.latitude === 0 || data.longitude === 0 || (data.lastLocationName !== Settings.data.location.name)) {
|
if (
|
||||||
|
(data.latitude === "") ||
|
||||||
|
(data.longitude === "") ||
|
||||||
|
(data.name !== Settings.data.location.name)) {
|
||||||
|
|
||||||
_geocodeLocation(Settings.data.location.name, function (latitude, longitude) {
|
_geocodeLocation(Settings.data.location.name, function (latitude, longitude) {
|
||||||
console.log("[Location] Geocoded " + Settings.data.location.name + " to: " + latitude + " / " + longitude)
|
console.log("[Location] Geocoded " + Settings.data.location.name + " to: " + latitude + " / " + longitude)
|
||||||
|
|
||||||
// Save location name
|
// Save location name
|
||||||
data.lastLocationName = Settings.data.location.name
|
data.name = Settings.data.location.name
|
||||||
|
|
||||||
// Save GPS coordinates
|
// Save GPS coordinates
|
||||||
data.latitude = latitude
|
data.latitude = latitude.toString()
|
||||||
data.longitude = longitude
|
data.longitude = longitude.toString()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
_fetchWeather(latitude, longitude, errorCallback)
|
_fetchWeather(latitude, longitude, errorCallback)
|
||||||
}, errorCallback)
|
}, errorCallback)
|
||||||
|
|
@ -150,8 +159,8 @@ Singleton {
|
||||||
// Save data
|
// Save data
|
||||||
data.weather = weatherData
|
data.weather = weatherData
|
||||||
data.weatherLastFetch = Time.timestamp
|
data.weatherLastFetch = Time.timestamp
|
||||||
data.latitude = weatherData.latitude
|
data.latitude = weatherData.latitude.toString()
|
||||||
data.longitude = weatherData.longitude
|
data.longitude = weatherData.longitude.toString()
|
||||||
|
|
||||||
isFetchingWeather = false
|
isFetchingWeather = false
|
||||||
console.log("[Location] Cached weather to disk")
|
console.log("[Location] Cached weather to disk")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue