This commit is contained in:
2023-08-25 19:26:10 +02:00
parent 5ca5b76d7c
commit 78a925ff8a
4 changed files with 40 additions and 25 deletions

View File

@@ -34,7 +34,7 @@ const PATH = DIRECTORY.path;
let extension;
// Time and date of the last location update
let lastLocationUpdate = new Date()
let lastLocationUpdate = -1
// The last calculated suntime of the day
let lastDayTime = suntimes.DAYPERIOD.NONE
@@ -69,13 +69,14 @@ CinnamonDynamicWallpaperExtension.prototype = {
// Location estimation
this.bindSettings("sw_auto_location", "autolocation", this.settingsUpdated)
this.bindSettings("sc_location_refresh_time", "locationRefreshTime", this.settingsUpdated)
this.bindSettings("etr_last_update", "etrLastUpdate")
this.bindSettings("etr_latitude", "latitude", this.settingsUpdated)
this.bindSettings("etr_longitude", "longitude", this.settingsUpdated)
// Time periods
this.bindSettings("tv_times", "tvTimes")
/** Debugging */
// Logs
this.bindSettings("tv_logs", "tvLogs")
@@ -149,7 +150,11 @@ CinnamonDynamicWallpaperExtension.prototype = {
if (looping) {
this.setImageToTime()
if (lastLocationUpdate < new Date().getTime() - this.locationRefreshTime * 1000) {
// Update the location, if the user choose "autoLocation" and the timer has expired
if ((lastLocationUpdate == -1 ||
lastLocationUpdate.getTime() < new Date().getTime() - this.locationRefreshTime * 60000) &&
this.autolocation)
{
this.updateLocation()
lastLocationUpdate = new Date()
}
@@ -210,6 +215,8 @@ CinnamonDynamicWallpaperExtension.prototype = {
},
/******************** Other functions ********************/
/**
* Changes the desktop background image
*
@@ -283,17 +290,16 @@ CinnamonDynamicWallpaperExtension.prototype = {
* Callback for changes in preferences
*/
updateLocation: function () {
// Update the update information
lastLocationUpdate = new Date()
if (this.autolocation) {
let loc = location.estimateLocation()
this.latitude = loc["latitude"]
this.longitude = loc["longitude"]
} else {
this.latitude = this.latitude
this.longitude = this.longitude
}
// Update the update information
lastLocationUpdate = new Date()
this.etrLastUpdate = lastLocationUpdate.getHours() + ":" + lastLocationUpdate.getMinutes()
}
this.writeToLogs("Location updated")
},
@@ -342,4 +348,4 @@ function enable() {
*/
function disable() {
looping = false
}
}

View File

@@ -12,6 +12,7 @@ IMAGE_DIR = PROJECT_DIR + "images/"
IMAGE_EXTRACT_DIR = IMAGE_DIR + "extracted/"
IMAGE_SETS_DIR = IMAGE_DIR + "included_image_sets/"
IMAGE_SELECTED_DIR = IMAGE_DIR + "selected/"
IMAGE_DEFAULT_DIR = IMAGE_DIR + "default/"
class WindowHandler:
@@ -148,20 +149,19 @@ class WindowHandler:
for i, val in enumerate(self.pref_vars):
# Set the preview image
self.changePreviewImage(i, IMAGE_SELECTED_DIR + pref_data[val]['value'])
if pref_data[val]['value'] != None:
# Set the preview image
self.changePreviewImage(i, IMAGE_SELECTED_DIR + pref_data[val]['value'])
# Set the ComboBox selection
if pref_data["etr_choosen_image_set"]["value"] == "custom":
self.image_source = Source.EXTRACT
# Set the ComboBox selection
if pref_data["etr_choosen_image_set"]["value"] == "custom":
self.image_source = Source.EXTRACT
for j, set in enumerate(choosable_images):
if set == pref_data[val]["value"]:
self.cb_previews[i].set_active(j)
else:
self.image_source = Source.SET
#except:
# pass
for j, set in enumerate(choosable_images):
if set == pref_data[val]["value"]:
self.cb_previews[i].set_active(j)
else:
self.image_source = Source.SET
def writeToSettings(self):
@@ -182,7 +182,9 @@ class WindowHandler:
pref_data["etr_choosen_image_set"]["value"] = "custom"
for i, val in enumerate(self.pref_vars):
pref_data[val]['value'] = self.cb_previews[i].get_active_text()
image_name = self.cb_previews[i].get_active_text()
pref_data[val]['value'] = image_name
# Write the settings
@@ -219,7 +221,7 @@ class WindowHandler:
self.image_source = Source.EXTRACT
self.wipeImages(Source.EXTRACT)
os.system("heif-convert " + imageURI + " " + IMAGE_EXTRACT_DIR + "/" + filename + ".jpg")
os.system("heif-convert " + imageURI + " " + IMAGE_EXTRACT_DIR + filename + ".jpg")
self.createExtracted()

View File

@@ -52,6 +52,7 @@
"keys": [
"sw_auto_location",
"sc_location_refresh_time",
"etr_last_update",
"etr_latitude",
"etr_longitude"
]
@@ -134,6 +135,12 @@
"description": "Interval time to refresh the location via network (min)",
"dependency": "sw_auto_location"
},
"etr_last_update": {
"type": "entry",
"description": "Last location update",
"default": "",
"dependency": "sw_auto_location"
},
"etr_latitude": {
"type": "entry",
"default": "",

View File

@@ -2,7 +2,7 @@
"uuid": "cinnamon-dynamic-wallpaper@TobiZog",
"name": "Cinnamon Dynamic Wallpaper",
"description": "Cinnamon extension for dynamic desktop backgrounds based on time and location",
"version": "1.3",
"version": "1.4",
"multiversion": true,
"cinnamon-version": [
"4.8",