Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cinnamon Dynamic Wallpaper v.1.3 #473

Merged
merged 5 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cinnamon-dynamic-wallpaper@TobiZog/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Version 1.3
- Adding option to stretch the image over multiple displays

# Version 1.2
- Compatibility with Cinnamon 4.8 and higher
- Notification on first start
Expand Down
11 changes: 6 additions & 5 deletions cinnamon-dynamic-wallpaper@TobiZog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Based on a location, this extension calculates the periods of a day and switches
- Image configuration assistent with simple one-click setup for image choose
- Online location estimation or offline with manual latitude and longitude input
- Offline sun angles estimation
- Image stretching over multiple displays or repeat image for every display

### Tested Cinnamon versions
- 4.8 (Mint 20.1)
Expand All @@ -28,16 +29,16 @@ Based on a location, this extension calculates the periods of a day and switches
- Image Configurator UI was written with `Glade`

## Installation
### From the repo
1. Download the Repository
2. Extract the files
3. Copy the folder `cinnamon-dynamic-wallpaper@TobiZog` to `~/.local/share/cinnamon/extensions/`

### From Built-in Extension Manager
1. Open "Extensions" in Linux Mint or any other distribution with Cinnamon as Desktop Environment
2. Click on "Download"
3. Search and download it

### From the repo
1. Download the Repository
2. Extract the files
3. Copy the folder `cinnamon-dynamic-wallpaper@TobiZog` to `~/.local/share/cinnamon/extensions/`

## How to use it
1. Active the Extension via Cinnamon Extension Manager
2. Open the settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,38 @@ CinnamonDynamicWallpaperExtension.prototype = {
*
* @param {string} uuid Universally Unique Identifier
*/
_init: function(uuid) {
_init: function (uuid) {
this.settings = new Settings.ExtensionSettings(this, uuid);

this.bindSettings("sw_auto_location", "autolocation", this.updateLocation)
this.bindSettings("sc_location_refresh_time", "locationRefreshTime")
this.bindSettings("etr_latitude", "latitude", this.updateLocation)
this.bindSettings("etr_longitude", "longitude", this.updateLocation)
this.bindSettings("etr_img_morning_twilight", "img_morning_twilight", this.setImageToTime)
this.bindSettings("etr_img_sunrise", "img_sunrise", this.setImageToTime)
this.bindSettings("etr_img_morning", "img_morning", this.setImageToTime)
this.bindSettings("etr_img_noon", "img_noon", this.setImageToTime)
this.bindSettings("etr_img_afternoon", "img_afternoon", this.setImageToTime)
this.bindSettings("etr_img_evening", "img_evening", this.setImageToTime)
this.bindSettings("etr_img_sunset", "img_sunset", this.setImageToTime)
this.bindSettings("etr_img_night_twilight", "img_night_twilight", this.setImageToTime)
this.bindSettings("etr_img_night", "img_night", this.setImageToTime)
// Image set
this.bindSettings("sw_image_stretch", "imageStretch", this.settingsUpdated)

// Location estimation
this.bindSettings("sw_auto_location", "autolocation", this.settingsUpdated)
this.bindSettings("sc_location_refresh_time", "locationRefreshTime", this.settingsUpdated)
this.bindSettings("etr_latitude", "latitude", this.settingsUpdated)
this.bindSettings("etr_longitude", "longitude", this.settingsUpdated)

// Time periods
this.bindSettings("tv_times", "tvTimes")


// Image Configurator
this.bindSettings("etr_img_morning_twilight", "img_morning_twilight", this.settingsUpdated)
this.bindSettings("etr_img_sunrise", "img_sunrise", this.settingsUpdated)
this.bindSettings("etr_img_morning", "img_morning", this.settingsUpdated)
this.bindSettings("etr_img_noon", "img_noon", this.settingsUpdated)
this.bindSettings("etr_img_afternoon", "img_afternoon", this.settingsUpdated)
this.bindSettings("etr_img_evening", "img_evening", this.settingsUpdated)
this.bindSettings("etr_img_sunset", "img_sunset", this.settingsUpdated)
this.bindSettings("etr_img_night_twilight", "img_night_twilight", this.settingsUpdated)
this.bindSettings("etr_img_night", "img_night", this.settingsUpdated)


// Check for the first startup
if (this.settings.getValue("first_start")) {
// Welcome notification
this.showNotification("Welcome to Cinnamon Dynamic Wallpaper",
"Check the preferences to choose a dynamic wallpaper", true)
this.showNotification("Welcome to Cinnamon Dynamic Wallpaper",
"Check the preferences to choose a dynamic wallpaper", true)

// Hide the notification on system restart
this.settings.setValue("first_start", false)
Expand All @@ -87,9 +96,9 @@ CinnamonDynamicWallpaperExtension.prototype = {

// Link the default wallpaper to the folder
for (let i = 1; i <= 9; i++) {
Util.spawnCommandLine("ln -s " +
DIRECTORY.path + "/images/included_image_sets/lakeside/" + i + ".jpg " +
DIRECTORY.path + "/images/selected/" + i + ".jpg");
Util.spawnCommandLine("ln -s " +
DIRECTORY.path + "/images/included_image_sets/lakeside/" + i + ".jpg " +
DIRECTORY.path + "/images/selected/" + i + ".jpg");
}
}

Expand Down Expand Up @@ -118,6 +127,18 @@ CinnamonDynamicWallpaperExtension.prototype = {
)
},


/**
* Handles changes in settings
*/
settingsUpdated: function () {
lastDayTime = suntimes.DAYPERIOD.NONE

this.updateLocation()
this.setImageToTime()
},


/**
* Displaying a desktop notification
*
Expand Down Expand Up @@ -162,9 +183,17 @@ CinnamonDynamicWallpaperExtension.prototype = {
*
* @param {jpg} imageURI The new desktop image
*/
changeWallpaper: function(imageURI) {
let gSetting = new Gio.Settings({schema: 'org.cinnamon.desktop.background'});
changeWallpaper: function (imageURI) {
let gSetting = new Gio.Settings({ schema: 'org.cinnamon.desktop.background' });
gSetting.set_string('picture-uri', imageURI);

if (this.imageStretch) {
gSetting.set_string('picture-options', 'spanned')
}
else {
gSetting.set_string('picture-options', 'zoom')
}

Gio.Settings.sync();
gSetting.apply();
},
Expand All @@ -173,13 +202,13 @@ CinnamonDynamicWallpaperExtension.prototype = {
/**
* Estimate the right image based on time period of the day
*/
setImageToTime: function() {
setImageToTime: function () {
let times = suntimes.calcTimePeriod(this.latitude, this.longitude)
let now = new Date()

let timesArray = [
times["morning_twilight"], times["sunrise"], times["morning"],
times["noon"], times["afternoon"], times["evening"],
times["noon"], times["afternoon"], times["evening"],
times["sunset"], times["night_twilight"], times["night"]
]

Expand All @@ -189,21 +218,21 @@ CinnamonDynamicWallpaperExtension.prototype = {
this.img_sunset, this.img_night_twilight, this.img_night
]

for(let i = 0; i < timesArray.length; i++) {
if(timesArray[i][0] <= now && now <= timesArray[i][1] && i != lastDayTime) {
for (let i = 0; i < timesArray.length; i++) {
if (timesArray[i][0] <= now && now <= timesArray[i][1] && i != lastDayTime) {
this.changeWallpaper("file://" + PATH + "/images/selected/" + imageSet[i])

lastDayTime = i
break
}
}


function convertToTimeString(time) {
return time.getHours().toString().padStart(2, "0") + ":" + time.getMinutes().toString().padStart(2, "0")
}

this.tvTimes =
this.tvTimes =
"Morning Twilight:\t\t" + convertToTimeString(timesArray[0][0]) + " - " + convertToTimeString(timesArray[0][1]) +
"\nSunrise:\t\t\t\t" + convertToTimeString(timesArray[1][0]) + " - " + convertToTimeString(timesArray[1][1]) +
"\nMorning:\t\t\t" + convertToTimeString(timesArray[2][0]) + " - " + convertToTimeString(timesArray[2][1]) +
Expand All @@ -229,9 +258,6 @@ CinnamonDynamicWallpaperExtension.prototype = {
this.longitude = this.longitude
}

// Refresh the image information, if it's necessary
this.setImageToTime()

// Update the update information
lastLocationUpdate = new Date()
},
Expand Down Expand Up @@ -261,17 +287,17 @@ CinnamonDynamicWallpaperExtension.prototype = {
* Callback for settings-schema
* Opens the external image configurator window
*/
openImageConfigurator: function() {
Util.spawnCommandLine("/usr/bin/env python3 " +
DIRECTORY.path + "/image-configurator/image-configurator.py");
openImageConfigurator: function () {
Util.spawnCommandLine("/usr/bin/env python3 " +
DIRECTORY.path + "/image-configurator/image-configurator.py");
},


/**
* Callback for settings-schema
* Opens the browser and navigates to the URL of the respository
*/
openRepoWebsite: function() {
openRepoWebsite: function () {
Util.spawnCommandLine("xdg-open https://github.com/TobiZog/cinnamon-dynamic-wallpaper");
},

Expand All @@ -280,7 +306,7 @@ CinnamonDynamicWallpaperExtension.prototype = {
* Callback for settings-schema
* Opens the browser and navigates to the URL of the Cinnamon Spices extension
*/
openSpicesWebsite: function() {
openSpicesWebsite: function () {
Util.spawnCommandLine("xdg-open https://cinnamon-spices.linuxmint.com/extensions/view/97")
},

Expand All @@ -289,7 +315,7 @@ CinnamonDynamicWallpaperExtension.prototype = {
* Callback for settings-schema
* Opens the browser and navigates to the GitHub issue page
*/
openIssueWebsite: function() {
openIssueWebsite: function () {
Util.spawnCommandLine("xdg-open https://github.com/TobiZog/cinnamon-dynamic-wallpaper/issues/new")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"title": "Image set",
"keys": [
"lb_image_configuration",
"btn_config_images"
"btn_config_images",
"sw_image_stretch"
]
},
"sec_location": {
Expand Down Expand Up @@ -88,6 +89,11 @@
"description": "Image Configurator",
"callback": "openImageConfigurator"
},
"sw_image_stretch": {
"type": "switch",
"description": "Expand image over all displays",
"default": true
},
"sw_auto_location": {
"type": "switch",
"default": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.2",
"version": "1.3",
"multiversion": true,
"cinnamon-version": [
"4.8",
Expand Down
Loading