From 1d7299fa5c12fed7ea4eceff3d3e4c2ab1ab5b6a Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Sat, 22 Jul 2017 21:56:17 +0200 Subject: [PATCH] Implement feature request #5 --- randomwallpaper@iflow.space/prefs.js | 4 + .../schemas/gschemas.compiled | Bin 2208 -> 2264 bytes ...ns.space.iflow.randomwallpaper.gschema.xml | 6 + randomwallpaper@iflow.space/settings.ui | 106 ++++++++++--- .../wallpaperController.js | 139 +++++++++++------- 5 files changed, 186 insertions(+), 69 deletions(-) diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js index 4fbd998..b00abcc 100644 --- a/randomwallpaper@iflow.space/prefs.js +++ b/randomwallpaper@iflow.space/prefs.js @@ -120,6 +120,10 @@ const RandomWallpaperSettings = new Lang.Class({ this._builder.get_object('af-switch'), 'active', Gio.SettingsBindFlags.DEFAULT); + this._settings.bind('change-lock-screen', + this._builder.get_object('change-lock-screen'), + 'active', + Gio.SettingsBindFlags.DEFAULT); }, _toggleAfSliders: function () { diff --git a/randomwallpaper@iflow.space/schemas/gschemas.compiled b/randomwallpaper@iflow.space/schemas/gschemas.compiled index bfc7a7683682c8f1ab9d2569a510ac9935d25ca3..4ee17980ba7924e61a80556fd7ea79f716530f78 100644 GIT binary patch delta 846 zcmYjQOK1~O6uqM}Nt#sK3Z)e-LKiYaiMSDr=%R>0f{5rw1jTeZ`Cyxb`2>sF=|&M$ zh>oC$LN`KD5TpycELbTN#6l~?g(4I|h%McSyVi5Y4EW&8Idk5<@7;Ij&2&$*r*Sp+ ze5c5(OLx{ma#Rx;meX<*JQWksdPTM|7UGzcGeTYkMq9_{7*Eak{)C8|2)5MB+qD;p zl6*MO=ObO1*6|g$^r`p2Z-T!9-s9XCP^gpef8vFOMs&$Pw3^cVHjp9 zUnyGYv8s73?U=S@Rl+!Z#K?PYHC?b=v&4iE1J4}**J6j!_;5s>MqT1yPgAjif_g4~ zsFrt;8LTVWy`{3_R_%#)hMsqf@p8p;Ehp$y4-B?v(_>bp$dqs-@np%|ax@rFhaPFy zecp@|4%q-N0dMa4=UE4JH~jD5AAn+~vh=At;BSI|1JTEz=EvYQISD)){IkV)YBu*G z_%hIYArqdH8qGZ`H3$#5-x?Zc0`)E=+yy@XzCHaI`qaEm)8LmtbZw}4ooB!cv!`P3 jloKx2=|t!h_%;yLNX;4>;1%ljA3@C}R>936lPLZLlQ6Sl delta 793 zcmXw%OK1~e6oqeSCTWcJA=HAeilAgDbth;^(SVd#REi=LK{3{}6EICpCV?U~u0${k zaRf!XD7f)~qKKM}(4AcI*~rJtTh)uHuUi+; zkG?!U@?E)j9r+l38r4<@w<;IM$UXcO+WlegALZf>@2h6-uwOoNUfilwS)laIBnn@K3uIqY*ieDtUO%pXEAAqHfImTzaxy#?ae};wzd@~I5$jkM z@g%RiyL08A`iM2P9r!NPb7H?K7jr7dY#%U$8cY2}-4Ji!fl>S<`f=xdn2R@(dw3DG u#xK_Rr}4&%+1TsIP?|pLDb3The time that already elapsed. + + false + Change lock screen + Weather the gnome lock screen should also be set to the new wallpaper. + + 15 15 vertical + 10 True @@ -101,7 +102,7 @@ True False True - The source that is used to fetch random wallpapers. You can select between desktoppr.co (default) and an experimental version of wallheaven.cc. + The source that is used to fetch random wallpapers. You can select between desktoppr.co (default) and an experimental version of wallheaven.cc and unsplash.com. True 1 0 @@ -185,19 +186,6 @@ False True - 0 - - - - - True - False - 10 - 10 - - - False - False 1 @@ -285,15 +273,97 @@ - + True False - 10 - 10 + 0 + in + + + True + False + 10 + 10 + 10 + 10 + 10 + 2 + + + True + False + True + True + + + True + False + start + Change lock screen + + + 0 + 0 + + + + + True + False + True + Also change the gnome lock screen image to the new wallpaper. + True + True + 1 + 0 + + + + 0 + 1 + + + + + 0 + 0 + + + + + True + False + vertical + + + True + True + end + start + + + False + True + 0 + + + + + 1 + 0 + + + + + + + False - False + True 3 diff --git a/randomwallpaper@iflow.space/wallpaperController.js b/randomwallpaper@iflow.space/wallpaperController.js index a4c015c..86a0c7f 100644 --- a/randomwallpaper@iflow.space/wallpaperController.js +++ b/randomwallpaper@iflow.space/wallpaperController.js @@ -29,7 +29,7 @@ let WallpaperController = new Lang.Class({ imageSourceAdapter: null, _timer: null, - _autoFetch : { + _autoFetch: { active: false, duration: 30, }, @@ -39,7 +39,7 @@ let WallpaperController = new Lang.Class({ // functions will be called when loading a new wallpaper stopped. If an error occured then the error will be passed as parameter. _stopLoadingHooks: [], - _init: function(extensionMeta){ + _init: function (extensionMeta) { this.extensionMeta = extensionMeta; this.wallpaperlocation = this.extensionMeta.path + '/wallpapers/'; @@ -64,11 +64,11 @@ let WallpaperController = new Lang.Class({ this.logger = new LoggerModule.Logger('RWG3', 'WallpaperController'); }, - _updateHistory: function() { + _updateHistory: function () { this._historyController.load(); }, - _updateAutoFetching: function() { + _updateAutoFetching: function () { let duration = 0; duration += this._settings.get('minutes', 'int'); duration += this._settings.get('hours', 'int') * 60; @@ -84,37 +84,39 @@ let WallpaperController = new Lang.Class({ }, /* - forwards the request to the adapter - */ - _requestRandomImageFromAdapter: function(callback){ + forwards the request to the adapter + */ + _requestRandomImageFromAdapter: function (callback) { this.imageSourceAdapter = this._desktopperAdapter; switch (this._settings.get('source', 'enum')) { - case 0: - this.imageSourceAdapter = this._desktopperAdapter; - break; - case 1: - this.imageSourceAdapter = this._unsplashAdapter; - break; - case 2: - this.imageSourceAdapter = this._wallheavenAdapter; - break; - default: - this.imageSourceAdapter = this._desktopperAdapter; - break; + case 0: + this.imageSourceAdapter = this._desktopperAdapter; + break; + case 1: + this.imageSourceAdapter = this._unsplashAdapter; + break; + case 2: + this.imageSourceAdapter = this._wallheavenAdapter; + break; + default: + this.imageSourceAdapter = this._desktopperAdapter; + break; } this.imageSourceAdapter.requestRandomImage(callback); }, - /* - copy file from uri to local wallpaper direcotry and calls - the given callback with the name and the full filepath of - the written file as parameter. - */ - _fetchFile: function(uri, callback){ + /** + * copy file from uri to local wallpaper directory and calls the given callback with the name and the full filepath + * of the written file as parameter. + * @param uri + * @param callback + * @private + */ + _fetchFile: function (uri, callback) { //extract the name from the url and let date = new Date(); - let name = date.getTime()+'_'+this.imageSourceAdapter.fileName(uri); // timestamp ensures uniqueness + let name = date.getTime() + '_' + this.imageSourceAdapter.fileName(uri); // timestamp ensures uniqueness let output_file = Gio.file_new_for_path(this.wallpaperlocation + String(name)); let output_stream = output_file.create(0, null); @@ -132,56 +134,91 @@ let WallpaperController = new Lang.Class({ }); }, - _setBackground: function(path, callback){ + /** + * Sets the wallpaper and the lockscreen when enabled to the given path. Executes the callback on success. + * @param path + * @param callback + * @private + */ + _setBackground: function (path, callback) { let background_setting = new Gio.Settings({schema: "org.gnome.desktop.background"}); + path = "file://" + path; - /* - inspired from: - https://bitbucket.org/LukasKnuth/backslide/src/7e36a49fc5e1439fa9ed21e39b09b61eca8df41a/backslide@codeisland.org/settings.js?at=master - */ - // Set: - if (background_setting.is_writable("picture-uri")){ - // Set a new Background-Image (should show up immediately): - if (background_setting.set_string("picture-uri", "file://"+path) ){ - Gio.Settings.sync(); // Necessary: http://stackoverflow.com/questions/9985140 + this._setPictureUriOfSettingsObject(background_setting, path, () => { + if (this._settings.get('change-lock-screen', 'boolean')) { + let screensaver_setting = new Gio.Settings({schema: "org.gnome.desktop.screensaver"}); + + this._setPictureUriOfSettingsObject(screensaver_setting, path, () => { + // call callback if given + if (callback) { + callback(); + } + }); + } else { // call callback if given if (callback) { callback(); } + } + }); + }, + + /** + * Set the picture-uri property of the given settings object to the path. + * Precondition: the settings object has to be a valid Gio settings object with the picture-uri property. + * @param settings + * @param path + * @param callback + * @private + */ + _setPictureUriOfSettingsObject: function(settings, path, callback) { + /* + inspired from: + https://bitbucket.org/LukasKnuth/backslide/src/7e36a49fc5e1439fa9ed21e39b09b61eca8df41a/backslide@codeisland.org/settings.js?at=master + */ + if (settings.is_writable("picture-uri")) { + // Set a new Background-Image (should show up immediately): + if (settings.set_string("picture-uri", path)) { + Gio.Settings.sync(); // Necessary: http://stackoverflow.com/questions/9985140 + + // call callback if given + if (callback) { + callback(); + } + } else { // TODO: error handling } } else { // TODO: error handling } - }, - _getCurrentWallpaper: function() { + _getCurrentWallpaper: function () { let background_setting = new Gio.Settings({schema: "org.gnome.desktop.background"}); return background_setting.get_string("picture-uri").replace(/^(file:\/\/)/, ""); }, - setWallpaper: function(historyId) { + setWallpaper: function (historyId) { let historyElement = this._historyController.get(historyId); - if(this._historyController.promoteToActive(historyElement.id)) { + if (this._historyController.promoteToActive(historyElement.id)) { this._setBackground(historyElement.path); this.currentWallpaper = this._getCurrentWallpaper(); } else { - this.logger.warn("The history id ("+historyElement.id+") could not be found.") + this.logger.warn("The history id (" + historyElement.id + ") could not be found.") // TODO: Error handling history id not found. } }, - fetchNewWallpaper: function(callback) { + fetchNewWallpaper: function (callback) { this._startLoadingHooks.forEach((element) => { element(); }); this._timer.begin(); // reset timer this._requestRandomImageFromAdapter((historyElement) => { - this.logger.info("Requesting image: "+historyElement.source.imageUrl); + this.logger.info("Requesting image: " + historyElement.source.imageUrl); this._fetchFile(historyElement.source.imageUrl, (historyId, path) => { historyElement.path = path; @@ -203,7 +240,7 @@ let WallpaperController = new Lang.Class({ }); }, - _backgroundTimout: function(delay) { + _backgroundTimout: function (delay) { if (this.timeout) { return; } @@ -222,37 +259,37 @@ let WallpaperController = new Lang.Class({ }); }, - previewWallpaper: function(historyid, delay) { + previewWallpaper: function (historyid, delay) { this.previewId = historyid; this._resetWallpaper = false; this._backgroundTimout(delay); }, - resetWallpaper: function() { + resetWallpaper: function () { this._resetWallpaper = true; this._backgroundTimout(); }, - getHistoryController: function() { + getHistoryController: function () { return this._historyController; }, - deleteHistory: function() { + deleteHistory: function () { this._historyController.clear(); }, - menuShowHook: function() { + menuShowHook: function () { this.currentWallpaper = this._getCurrentWallpaper(); }, - registerStartLoadingHook: function(fn) { + registerStartLoadingHook: function (fn) { if (typeof fn === "function") { this._startLoadingHooks.push(fn) } }, - registerStopLoadingHook: function(fn) { + registerStopLoadingHook: function (fn) { if (typeof fn === "function") { this._stopLoadingHooks.push(fn) }