From 3852e8394342275116aff26da1b107f87bf6b480 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Mon, 30 Jul 2018 00:29:02 +0200 Subject: [PATCH 1/5] first HistoryElement cache implementation --- randomwallpaper@iflow.space/elements.js | 14 +++++++- randomwallpaper@iflow.space/extension.js | 42 +++++++++++++++++++----- randomwallpaper@iflow.space/prefs.js | 1 + 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/randomwallpaper@iflow.space/elements.js b/randomwallpaper@iflow.space/elements.js index ca539ff..cb22c37 100644 --- a/randomwallpaper@iflow.space/elements.js +++ b/randomwallpaper@iflow.space/elements.js @@ -149,7 +149,12 @@ var HistoryElement = new Lang.Class({ } } }) - } + }, + + setIndex: function(index) { + this.prefixLabel.set_text(String(index)); + }, + }); var CurrentImageElement = new Lang.Class({ @@ -289,5 +294,12 @@ var HistorySection = new Lang.Class({ this.actor.add_actor(this.box); }, + /** + * Clears the history section without destroying the child actors. + */ + clearSection: function() { + this.box.remove_all_children(); + } + }); diff --git a/randomwallpaper@iflow.space/extension.js b/randomwallpaper@iflow.space/extension.js index ff0947c..5efb29d 100644 --- a/randomwallpaper@iflow.space/extension.js +++ b/randomwallpaper@iflow.space/extension.js @@ -77,6 +77,11 @@ var RandomWallpaperEntry = new Lang.Class({ Name: "RandomWallpaperEntry", logger: null, + /** + * Cache HistoryElements for performance of long histories. + */ + _historySectionCache: {}, + _init: function (menuAlignment, nameText) { this.parent(menuAlignment, nameText); this.logger = new LoggerModule.Logger('RWG3', 'RandomWallpaperEntry'); @@ -184,28 +189,38 @@ var RandomWallpaperEntry = new Lang.Class({ setHistoryList: function () { this.setCurrentBackgroundElement(); - this.historySection.removeAll(); - let historyController = wallpaperController.getHistoryController(); let history = historyController.history; + this.historySection.clearSection(); if (history.length <= 1) { this.clearHistoryList(); return; } + let existingHistoryElements = []; for (let i = 1; i < history.length; i++) { - let historyid = history[i].id; - let tmp = new CustomElements.HistoryElement(history[i], i); + let historyID = history[i].id; + let tmp; - tmp.actor.connect('key-focus-in', onEnter); - tmp.actor.connect('key-focus-out', onLeave); - tmp.actor.connect('enter-event', onEnter); + if (!(historyID in this._historySectionCache)) { + tmp = new CustomElements.HistoryElement(history[i], i); - tmp.connect('activate', onSelect); + tmp.actor.connect('key-focus-in', onEnter); + tmp.actor.connect('key-focus-out', onLeave); + tmp.actor.connect('enter-event', onEnter); - this.historySection.addMenuItem(tmp); + tmp.connect('activate', onSelect); + this._historySectionCache[historyID] = tmp; + } else { + tmp = this._historySectionCache[historyID]; + tmp.setIndex(i); + } + + existingHistoryElements.push(historyID) + this.historySection.addMenuItem(tmp, i-1); } + this._cleanupHistoryCache(existingHistoryElements); function onLeave(actor) { wallpaperController.resetWallpaper(); @@ -221,7 +236,16 @@ var RandomWallpaperEntry = new Lang.Class({ }, + _cleanupHistoryCache: function(existingIDs) { + let destroyIDs = Object.keys(this._historySectionCache).filter((i) => existingIDs.indexOf(i) === -1); + + destroyIDs.map(id => { + delete this._historySectionCache[id]; + }); + }, + clearHistoryList: function () { + this._cleanupHistoryCache([]); this.historySection.removeAll(); let empty = new PopupMenu.PopupMenuItem('No recent wallpaper ...', { diff --git a/randomwallpaper@iflow.space/prefs.js b/randomwallpaper@iflow.space/prefs.js index 54d577a..7466d5a 100644 --- a/randomwallpaper@iflow.space/prefs.js +++ b/randomwallpaper@iflow.space/prefs.js @@ -249,6 +249,7 @@ var RandomWallpaperSettings = new Lang.Class({ let text = newWallpaperButton.get_label(); newWallpaperButton.set_label("Loading ..."); + this._wallpaperController.update(); this._wallpaperController.fetchNewWallpaper(()=>{ this._wallpaperController.update(); newWallpaperButton.set_label(text); From e9d7097f197a72bae2f7efb95aea101c5e5aed3f Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Fri, 3 Aug 2018 17:28:31 +0200 Subject: [PATCH 2/5] enhance history cache --- randomwallpaper@iflow.space/elements.js | 82 +++++++++++++++++++++--- randomwallpaper@iflow.space/extension.js | 50 +-------------- 2 files changed, 76 insertions(+), 56 deletions(-) diff --git a/randomwallpaper@iflow.space/elements.js b/randomwallpaper@iflow.space/elements.js index cb22c37..fa22e7c 100644 --- a/randomwallpaper@iflow.space/elements.js +++ b/randomwallpaper@iflow.space/elements.js @@ -246,7 +246,11 @@ var StatusElement = new Lang.Class({ time: 1, transition: 'easeInOutSine', onComplete: function () { - Tweener.addTween(_this, _this.loadingTweenOut); + try { + Tweener.addTween(_this, _this.loadingTweenOut); + } catch (e) { + // swollow (not really important) + } } }; @@ -256,7 +260,11 @@ var StatusElement = new Lang.Class({ transition: 'easeInOutSine', onComplete: function () { if (_this.isLoading) { - Tweener.addTween(_this, _this.loadingTweenIn); + try { + Tweener.addTween(_this, _this.loadingTweenIn); + } catch (e) { + // swollow (not really important) + } } else { return false; } @@ -283,6 +291,13 @@ var HistorySection = new Lang.Class({ Name: 'HistorySection', Extends: PopupMenu.PopupMenuSection, + /** + * Cache HistoryElements for performance of long histories. + */ + _historySectionCache: {}, + + _historyCache: [], + _init: function () { this.parent(); @@ -294,12 +309,63 @@ var HistorySection = new Lang.Class({ this.actor.add_actor(this.box); }, - /** - * Clears the history section without destroying the child actors. - */ - clearSection: function() { - this.box.remove_all_children(); - } + updateList: function(history, onEnter, onLeave, onSelect) { + if (this._historyCache.length <= 1) { + this.removeAll(); // remove empty history element + } + + let existingHistoryElements = []; + + for (let i = 1; i < history.length; i++) { + let historyID = history[i].id; + let tmp; + + if (!(historyID in this._historySectionCache)) { + tmp = new HistoryElement(history[i], i); + + tmp.actor.connect('key-focus-in', onEnter); + tmp.actor.connect('key-focus-out', onLeave); + tmp.actor.connect('enter-event', onEnter); + + tmp.connect('activate', onSelect); + this._historySectionCache[historyID] = tmp; + + this.addMenuItem(tmp, i-1); + } else { + tmp = this._historySectionCache[historyID]; + tmp.setIndex(i); + } + + existingHistoryElements.push(historyID); + } + + this._cleanupHistoryCache(existingHistoryElements); + this._historyCache = history; + }, + + _cleanupHistoryCache: function(existingIDs) { + let destroyIDs = Object.keys(this._historySectionCache).filter((i) => existingIDs.indexOf(i) === -1); + + destroyIDs.map(id => { + this._historySectionCache[id].destroy(); + delete this._historySectionCache[id]; + }); + }, + + clear() { + this._cleanupHistoryCache([]); + this.removeAll(); + this.addMenuItem( + new PopupMenu.PopupMenuItem('No recent wallpaper ...', { + activate: false, + hover: false, + style_class: 'rwg-recent-lable', + can_focus: false + }) + ); + + this._historyCache = []; + }, }); diff --git a/randomwallpaper@iflow.space/extension.js b/randomwallpaper@iflow.space/extension.js index d6a9607..5525928 100644 --- a/randomwallpaper@iflow.space/extension.js +++ b/randomwallpaper@iflow.space/extension.js @@ -77,11 +77,6 @@ var RandomWallpaperEntry = new Lang.Class({ Name: "RandomWallpaperEntry", logger: null, - /** - * Cache HistoryElements for performance of long histories. - */ - _historySectionCache: {}, - _init: function (menuAlignment, nameText) { this.parent(menuAlignment, nameText); this.logger = new LoggerModule.Logger('RWG3', 'RandomWallpaperEntry'); @@ -191,37 +186,12 @@ var RandomWallpaperEntry = new Lang.Class({ let historyController = wallpaperController.getHistoryController(); let history = historyController.history; - this.historySection.clearSection(); if (history.length <= 1) { this.clearHistoryList(); return; } - let existingHistoryElements = []; - for (let i = 1; i < history.length; i++) { - let historyID = history[i].id; - let tmp; - - if (!(historyID in this._historySectionCache)) { - tmp = new CustomElements.HistoryElement(history[i], i); - - tmp.actor.connect('key-focus-in', onEnter); - tmp.actor.connect('key-focus-out', onLeave); - tmp.actor.connect('enter-event', onEnter); - - tmp.connect('activate', onSelect); - this._historySectionCache[historyID] = tmp; - } else { - tmp = this._historySectionCache[historyID]; - tmp.setIndex(i); - } - - existingHistoryElements.push(historyID) - this.historySection.addMenuItem(tmp, i-1); - } - this._cleanupHistoryCache(existingHistoryElements); - function onLeave(actor) { wallpaperController.resetWallpaper(); } @@ -234,27 +204,11 @@ var RandomWallpaperEntry = new Lang.Class({ wallpaperController.setWallpaper(actor.historyEntry.id); } - }, - - _cleanupHistoryCache: function(existingIDs) { - let destroyIDs = Object.keys(this._historySectionCache).filter((i) => existingIDs.indexOf(i) === -1); - - destroyIDs.map(id => { - delete this._historySectionCache[id]; - }); + this.historySection.updateList(history, onEnter, onLeave, onSelect); }, clearHistoryList: function () { - this._cleanupHistoryCache([]); - this.historySection.removeAll(); - - let empty = new PopupMenu.PopupMenuItem('No recent wallpaper ...', { - activate: false, - hover: false, - style_class: 'rwg-recent-lable', - can_focus: false - }); - this.historySection.addMenuItem(empty); + this.historySection.clear(); }, }); From c10515737fedb986d3aeaf99f81d14e07bacfc65 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Sat, 4 Aug 2018 20:01:31 +0200 Subject: [PATCH 3/5] fix css percentage warning --- randomwallpaper@iflow.space/stylesheet.css | 1 - 1 file changed, 1 deletion(-) diff --git a/randomwallpaper@iflow.space/stylesheet.css b/randomwallpaper@iflow.space/stylesheet.css index b7a96be..e99f9fb 100644 --- a/randomwallpaper@iflow.space/stylesheet.css +++ b/randomwallpaper@iflow.space/stylesheet.css @@ -32,7 +32,6 @@ } .rwg-recent-lable { - width: 100%; font-size: 90%; text-align: left; border: 0; From 4bb40e6a21437bedc10c07181687923dc3c074a0 Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Sat, 4 Aug 2018 20:54:28 +0200 Subject: [PATCH 4/5] fix syntax for older gnome versions --- randomwallpaper@iflow.space/elements.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/randomwallpaper@iflow.space/elements.js b/randomwallpaper@iflow.space/elements.js index fa22e7c..cd6e44f 100644 --- a/randomwallpaper@iflow.space/elements.js +++ b/randomwallpaper@iflow.space/elements.js @@ -352,7 +352,7 @@ var HistorySection = new Lang.Class({ }); }, - clear() { + clear: function() { this._cleanupHistoryCache([]); this.removeAll(); this.addMenuItem( From 555635010190ded45881190279d3d34710e2026d Mon Sep 17 00:00:00 2001 From: Wolfgang Rumpler Date: Fri, 5 Oct 2018 12:17:59 +0200 Subject: [PATCH 5/5] bump version number and enable gnome 3.30 support --- randomwallpaper@iflow.space/metadata.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/randomwallpaper@iflow.space/metadata.json b/randomwallpaper@iflow.space/metadata.json index 5237c5e..1c2c552 100644 --- a/randomwallpaper@iflow.space/metadata.json +++ b/randomwallpaper@iflow.space/metadata.json @@ -4,13 +4,14 @@ "3.22", "3.24", "3.26", - "3.28" + "3.28", + "3.30" ], "uuid": "randomwallpaper@iflow.space", "settings-schema": "org.gnome.shell.extensions.space.iflow.randomwallpaper", "name": "Random Wallpaper", "description": "Fetches a random wallpaper from an online source and sets it as desktop background. \nThe desktop background can be updated periodically or manually.", - "version": 11, - "semantic-version": "2.2.2", + "version": 12, + "semantic-version": "2.3.0", "url": "https://github.com/ifl0w/RandomWallpaperGnome3" }