diff --git a/.gitignore b/.gitignore index 9d6886d..f5e78c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .idea - # ready to deploy to gnome extensions random-wallpaper-gnome3.zip +randomwallpaper@iflow.space.zip # Temporary ui files **/*~ diff --git a/assets/screenshot.png b/assets/screenshot.png index 8b3b495..4ad9f45 100644 Binary files a/assets/screenshot.png and b/assets/screenshot.png differ diff --git a/build.sh b/build.sh index e178ac5..8bf2594 100755 --- a/build.sh +++ b/build.sh @@ -1,7 +1,7 @@ #!/bin/bash -BASEDIR='randomwallpaper@iflow.space' -ZIPNAME='random-wallpaper-gnome3.zip' +BASEDIR="randomwallpaper@iflow.space" +ZIPNAME="$BASEDIR.zip" rm $ZIPNAME rm $BASEDIR/schemas/gschemas.compiled diff --git a/debug.sh b/debug.sh index 2fdc876..9f8c254 100755 --- a/debug.sh +++ b/debug.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [[ $1 == 'prefs' ]]; then +if [ "$1" = "prefs" ]; then gnome-shell-extension-prefs randomwallpaper@iflow.space else journalctl -f /usr/bin/gnome-shell diff --git a/install.sh b/install.sh index be2a616..5bf814f 100755 --- a/install.sh +++ b/install.sh @@ -4,12 +4,12 @@ extensionFolder="randomwallpaper@iflow.space" sourcepath="$PWD/$extensionFolder" targetpath="/home/$USER/.local/share/gnome-shell/extensions" -if [[ $1 == 'uninstall' ]]; then +if [ "$1" = "uninstall" ]; then echo "# Removing $targetpath/$extensionFolder" rm "$targetpath/$extensionFolder" else echo "# Making extension directory" mkdir -p $targetpath echo "# Linking extension folder" - ln -s $sourcepath "$targetpath/$extensionFolder" + ln -s "$sourcepath" "$targetpath" fi diff --git a/randomwallpaper@iflow.space/elements.js b/randomwallpaper@iflow.space/elements.js index 4687f94..4558e5e 100644 --- a/randomwallpaper@iflow.space/elements.js +++ b/randomwallpaper@iflow.space/elements.js @@ -3,19 +3,30 @@ const PopupMenu = imports.ui.popupMenu; const St = imports.gi.St; const Tweener = imports.ui.tweener; const Util = imports.misc.util; +const GdkPixbuf = imports.gi.GdkPixbuf; +const Clutter = imports.gi.Clutter; +const Cogl = imports.gi.Cogl; + +// Filesystem +const Gio = imports.gi.Gio; const Self = imports.misc.extensionUtils.getCurrentExtension(); +const LoggerModule = Self.imports.logger; const Timer = Self.imports.timer; const HistoryElement = new Lang.Class({ Name: 'HistoryElement', Extends: PopupMenu.PopupSubMenuMenuItem, + logger: null, historyEntry: null, setAsWallpaperItem: null, + previewItem: null, + _previewActor: null, _init: function (historyEntry, index) { this.parent("", false); + this.logger = new LoggerModule.Logger('RWG3', 'HistoryElement'); let timestamp = historyEntry.timestamp; let date = new Date(timestamp); @@ -25,12 +36,12 @@ const HistoryElement = new Lang.Class({ let prefixText; if (index === 0) { - prefixtext = "Current Background"; + prefixText = "Current Background"; } else { - prefixtext = String(index) + '.'; + prefixText = String(index) + '.'; } this.prefixLabel = new St.Label({ - text: prefixtext, + text: prefixText, style_class: 'rwg-history-index' }); @@ -60,8 +71,9 @@ const HistoryElement = new Lang.Class({ this.actor.insert_child_above(this._container, this.prefixLabel); } - if (this.historyEntry.source && this.historyEntry.source !== null) { + this.menu.addMenuItem( new PopupMenu.PopupBaseMenuItem({can_focus: false, reactive: false})); // theme independent spacing + if (this.historyEntry.source && this.historyEntry.source !== null) { if (this.historyEntry.source.author !== null && this.historyEntry.source.authorUrl !== null) { this.authorItem = new PopupMenu.PopupMenuItem('Image By: ' + this.historyEntry.source.author); @@ -88,17 +100,53 @@ const HistoryElement = new Lang.Class({ }); this.menu.addMenuItem(this.imageUrlItem); - - this.setAsWallpaperItem = new PopupMenu.PopupMenuItem('Set As Wallpaper'); - this.setAsWallpaperItem.connect('activate', () => { - this.emit('activate'); - }); - - this.menu.addMenuItem(this.setAsWallpaperItem); } else { this.menu.addMenuItem(new PopupMenu.PopupMenuItem('Unknown source.')); } + this.setAsWallpaperItem = new PopupMenu.PopupMenuItem('Set As Wallpaper'); + this.setAsWallpaperItem.connect('activate', () => { + this.emit('activate'); + }); + + this.previewItem = new PopupMenu.PopupBaseMenuItem({can_focus: false, reactive: false}); + this.menu.addMenuItem(new PopupMenu.PopupBaseMenuItem({can_focus: false, reactive: false})); // theme independent spacing + this.menu.addMenuItem(this.setAsWallpaperItem); + this.menu.addMenuItem(this.previewItem); + this.menu.addMenuItem(new PopupMenu.PopupBaseMenuItem({can_focus: false, reactive: false})); // theme independent spacing + + /* + Load the image on first opening of the sub menu instead of during creation of the history list. + */ + this.menu.connect('open-state-changed', (self, open) => { + if (open) { + if (this._previewActor !== null) { + return; + } + + try { + let width = 250; // TODO: get width or add option in settings. + let pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(this.historyEntry.path, width, -1, true); + let height = pixbuf.get_height(); + + let image = new Clutter.Image(); + let pixelFormat = pixbuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888; + image.set_data( + pixbuf.get_pixels(), + pixelFormat, + width, + height, + pixbuf.get_rowstride() + ); + this._previewActor = new Clutter.Actor({height: height, width: width}); + this._previewActor.set_content(image); + + this.previewItem.actor.add_actor(this._previewActor); + } catch (exeption) { + this.logger.error(exeption); + } + } + }) } }); diff --git a/randomwallpaper@iflow.space/extension.js b/randomwallpaper@iflow.space/extension.js index 5a5c099..6344f7d 100644 --- a/randomwallpaper@iflow.space/extension.js +++ b/randomwallpaper@iflow.space/extension.js @@ -121,10 +121,10 @@ let RandomWallpaperEntry = new Lang.Class({ // reset it if needed this.menu.actor.connect('hide', () => { wallpaperController.resetWallpaper(); - this.setHistoryList(); + this.setHistoryList(); // TODO: move this call to a new background changed hook (because overhead on close) }); - this.menu.actor.connect('leave-event', function(e, t, a) { + this.menu.actor.connect('leave-event', () => { wallpaperController.resetWallpaper(); }); diff --git a/randomwallpaper@iflow.space/history.js b/randomwallpaper@iflow.space/history.js index 405fcdb..ab7a151 100644 --- a/randomwallpaper@iflow.space/history.js +++ b/randomwallpaper@iflow.space/history.js @@ -109,7 +109,7 @@ let HistoryController = new Lang.Class({ * Clear the history and delete all photos except the current one. * @returns {boolean} */ - clear() { + clear: function() { let firstHistoryElement = this.history[0]; if (firstHistoryElement) diff --git a/randomwallpaper@iflow.space/logger.js b/randomwallpaper@iflow.space/logger.js index d0a4fc0..9481ac9 100644 --- a/randomwallpaper@iflow.space/logger.js +++ b/randomwallpaper@iflow.space/logger.js @@ -11,7 +11,7 @@ let Logger = new Lang.Class({ }, _log: function(level, message) { - global.log(`${this._prefix} [${level}] >> ${this._callingClass} :: ${message}`); + global.log(this._prefix + " [" + level + "] >> " + this._callingClass + " :: " + message); }, debug: function (message) { diff --git a/randomwallpaper@iflow.space/metadata.json b/randomwallpaper@iflow.space/metadata.json index 1f8c5eb..15c9c4e 100644 --- a/randomwallpaper@iflow.space/metadata.json +++ b/randomwallpaper@iflow.space/metadata.json @@ -1,9 +1,5 @@ { "shell-version": [ - "3.12", - "3.14", - "3.16", - "3.18", "3.20", "3.22", "3.24" @@ -12,6 +8,6 @@ "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": "2.0.1", + "version": "2.1.0", "url": "https://github.com/ifl0w/RandomWallpaperGnome3" }