mirror of
https://github.com/Hopiu/RandomWallpaperGnome3.git
synced 2026-05-13 01:23:11 +00:00
add support for 3.22 and enhance preview
This commit is contained in:
parent
f386717b4a
commit
5bc0be523f
4 changed files with 61 additions and 43 deletions
|
|
@ -20,7 +20,7 @@ const HistoryElement = new Lang.Class({
|
|||
let timeString = date.toLocaleTimeString();
|
||||
let dateString = date.toLocaleDateString();
|
||||
|
||||
this.label = new St.Label({
|
||||
this.label = new St.Label({
|
||||
text: index,
|
||||
style_class: 'rwg-history-index'
|
||||
});
|
||||
|
|
@ -31,13 +31,13 @@ const HistoryElement = new Lang.Class({
|
|||
vertical: true
|
||||
});
|
||||
|
||||
this.dateLabel = new St.Label({
|
||||
this.dateLabel = new St.Label({
|
||||
text: dateString,
|
||||
style_class: 'rwg-history-date'
|
||||
});
|
||||
this._container.add_child(this.dateLabel);
|
||||
|
||||
this.timeLabel = new St.Label({
|
||||
this.timeLabel = new St.Label({
|
||||
text: timeString,
|
||||
style_class: 'rwg-history-time'
|
||||
});
|
||||
|
|
@ -53,9 +53,9 @@ const HistoryElement = new Lang.Class({
|
|||
const StatusElement = new Lang.Class({
|
||||
Name: 'StatusElement',
|
||||
Extends: St.Icon,
|
||||
|
||||
|
||||
_init: function() {
|
||||
|
||||
|
||||
this.parent({
|
||||
icon_name: 'preferences-desktop-wallpaper-symbolic',
|
||||
style_class: 'system-status-icon'
|
||||
|
|
@ -64,8 +64,8 @@ const StatusElement = new Lang.Class({
|
|||
let _this = this;
|
||||
|
||||
this.loadingTweenIn = {
|
||||
opacity:20,
|
||||
time:1,
|
||||
opacity:20,
|
||||
time:1,
|
||||
transition:'easeInOutSine',
|
||||
onComplete: function() {
|
||||
Tweener.addTween(_this, _this.loadingTweenOut);
|
||||
|
|
@ -73,14 +73,14 @@ const StatusElement = new Lang.Class({
|
|||
}
|
||||
|
||||
this.loadingTweenOut = {
|
||||
opacity:255,
|
||||
time:1,
|
||||
opacity:255,
|
||||
time:1,
|
||||
transition:'easeInOutSine',
|
||||
onComplete: function() {
|
||||
if (_this.isLoading) {
|
||||
Tweener.addTween(_this, _this.loadingTweenIn);
|
||||
} else {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -196,4 +196,4 @@ const DelaySlider = new Lang.Class({
|
|||
}
|
||||
});
|
||||
|
||||
// -------------------------------------------------------------------------------
|
||||
// -------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ let RandomWallpaperEntry = new Lang.Class({
|
|||
this.setHistoryList();
|
||||
|
||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||
|
||||
|
||||
// clear history button
|
||||
this.clearHistoryItem = new PopupMenu.PopupMenuItem('Clear History');
|
||||
this.menu.addMenuItem(this.clearHistoryItem);
|
||||
|
|
@ -68,6 +68,7 @@ let RandomWallpaperEntry = new Lang.Class({
|
|||
/*
|
||||
add eventlistener
|
||||
*/
|
||||
|
||||
let _this = this;
|
||||
// new wallpaper event
|
||||
this.newWallpaperItem.connect('activate', function() {
|
||||
|
|
@ -85,22 +86,25 @@ let RandomWallpaperEntry = new Lang.Class({
|
|||
|
||||
// Open Wallpaper Folder
|
||||
this.openFolder.connect('activate', function(event) {
|
||||
let now = new Date().getTime()/1000;
|
||||
let uri = GLib.filename_to_uri(wallpaperController.wallpaperlocation, "");
|
||||
Gio.AppInfo.launch_default_for_uri(uri, global.create_app_launch_context(now, -1))
|
||||
Gio.AppInfo.launch_default_for_uri(uri, global.create_app_launch_context(0, -1))
|
||||
});
|
||||
|
||||
this.menu.actor.connect('show', function() {
|
||||
wallpaperController.menuShowHook();
|
||||
});
|
||||
|
||||
// when the popupmenu disapears, check if the wallpaper is the original and
|
||||
// reset it if needed
|
||||
this.menu.actor.connect('hide', function() {
|
||||
wallpaperController.setWallpaper(_this.history[0], true);
|
||||
wallpaperController.resetWallpaper();
|
||||
_this.setHistoryList();
|
||||
});
|
||||
|
||||
this.menu.actor.connect('leave-event', function() {
|
||||
wallpaperController.previewWallpaper(_this.history[0], 400, true);
|
||||
this.menu.actor.connect('leave-event', function(e, t, a) {
|
||||
wallpaperController.resetWallpaper();
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
|
||||
setHistoryList: function() {
|
||||
|
|
@ -120,14 +124,14 @@ let RandomWallpaperEntry = new Lang.Class({
|
|||
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.historySection.addMenuItem(tmp);
|
||||
};
|
||||
|
||||
function onLeave(actor) {
|
||||
wallpaperController.previewWallpaper(history[0], 400, true);
|
||||
wallpaperController.resetWallpaper();
|
||||
}
|
||||
|
||||
function onEnter(actor) {
|
||||
|
|
@ -167,4 +171,4 @@ function enable() {
|
|||
function disable() {
|
||||
// Extension disabled
|
||||
panelEntry.destroy();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@
|
|||
"3.14",
|
||||
"3.16",
|
||||
"3.18",
|
||||
"3.20"
|
||||
"3.20",
|
||||
"3.22"
|
||||
],
|
||||
"uuid": "randomwallpaper@iflow.space",
|
||||
"name": "Random Wallpaper",
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ let WallpaperController = new Lang.Class({
|
|||
this.extensionMeta = extensionMeta;
|
||||
this.wallpaperlocation = this.extensionMeta.path + '/wallpapers/';
|
||||
this.history = this._loadHistory();
|
||||
this.currentWallpaper = this._getCurrentWallpaper();
|
||||
this.currentWallpaper = this._getCurrentWallpaper();
|
||||
},
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
fetch a random image url from desktopper.cc
|
||||
and call callback function with the URL of the image
|
||||
*/
|
||||
|
|
@ -51,8 +51,8 @@ let WallpaperController = new Lang.Class({
|
|||
},
|
||||
|
||||
/*
|
||||
copy file from uri to local wallpaper direcotry and calls
|
||||
the given callback with the name and the full filepath of
|
||||
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){
|
||||
|
|
@ -109,7 +109,7 @@ let WallpaperController = new Lang.Class({
|
|||
|
||||
_setBackground: function(path, callback){
|
||||
let background_setting = new Gio.Settings({schema: "org.gnome.desktop.background"});
|
||||
|
||||
|
||||
/*
|
||||
inspired from:
|
||||
https://bitbucket.org/LukasKnuth/backslide/src/7e36a49fc5e1439fa9ed21e39b09b61eca8df41a/backslide@codeisland.org/settings.js?at=master
|
||||
|
|
@ -135,13 +135,13 @@ let WallpaperController = new Lang.Class({
|
|||
|
||||
_getCurrentWallpaper: function() {
|
||||
let background_setting = new Gio.Settings({schema: "org.gnome.desktop.background"});
|
||||
return background_setting.get_string("picture-uri");
|
||||
return background_setting.get_string("picture-uri").replace(/^(file:\/\/)/, "");
|
||||
},
|
||||
|
||||
_loadHistory: function () {
|
||||
let directory = Gio.file_new_for_path(this.wallpaperlocation);
|
||||
let enumerator = directory.enumerate_children('', Gio.FileQueryInfoFlags.NONE, null);
|
||||
|
||||
|
||||
let fileinfo;
|
||||
let history = [];
|
||||
|
||||
|
|
@ -153,7 +153,7 @@ let WallpaperController = new Lang.Class({
|
|||
};
|
||||
|
||||
let name = fileinfo.get_name();
|
||||
|
||||
|
||||
// ignore hidden files
|
||||
if (name[0] != '.') {
|
||||
history.push(fileinfo.get_name());
|
||||
|
|
@ -180,6 +180,7 @@ let WallpaperController = new Lang.Class({
|
|||
historyEntry = this._setNewFileName(historyEntry);
|
||||
}
|
||||
this._setBackground(this.wallpaperlocation + historyEntry);
|
||||
this.currentWallpaper = this._getCurrentWallpaper();
|
||||
},
|
||||
|
||||
fetchNewWallpaper: function(callback) {
|
||||
|
|
@ -199,20 +200,19 @@ let WallpaperController = new Lang.Class({
|
|||
});
|
||||
},
|
||||
|
||||
previewWallpaper: function(historyid, delay, setWallpaper) {
|
||||
this.previewId = historyid;
|
||||
let _this = this;
|
||||
|
||||
delay = delay || 200;
|
||||
|
||||
if (_this.timeout) {
|
||||
_backgroundTimout: function(delay) {
|
||||
if (this.timeout) {
|
||||
return;
|
||||
};
|
||||
|
||||
let _this = this;
|
||||
delay = delay || 200;
|
||||
|
||||
this.timeout = Mainloop.timeout_add(Mainloop.PRIORITY_DEFAULT, delay, function(){
|
||||
_this.timeout = null;
|
||||
if (setWallpaper) {
|
||||
_this.setWallpaper(_this.previewId, true);
|
||||
if (_this._resetWallpaper) {
|
||||
_this._setBackground(_this.currentWallpaper);
|
||||
_this._resetWallpaper = false;
|
||||
} else {
|
||||
_this._setBackground(_this.wallpaperlocation + _this.previewId);
|
||||
}
|
||||
|
|
@ -220,7 +220,16 @@ let WallpaperController = new Lang.Class({
|
|||
});
|
||||
},
|
||||
|
||||
previewWallpaper: function(historyid, delay) {
|
||||
this.previewId = historyid;
|
||||
this._resetWallpaper = false;
|
||||
|
||||
this._backgroundTimout(delay);
|
||||
},
|
||||
|
||||
resetWallpaper: function() {
|
||||
this._resetWallpaper = true;
|
||||
this._backgroundTimout();
|
||||
},
|
||||
|
||||
getHistory: function() {
|
||||
|
|
@ -235,12 +244,12 @@ let WallpaperController = new Lang.Class({
|
|||
|
||||
let directory = Gio.file_new_for_path(this.wallpaperlocation);
|
||||
let enumerator = directory.enumerate_children('', Gio.FileQueryInfoFlags.NONE, null);
|
||||
|
||||
|
||||
let fileinfo;
|
||||
let deleteFile;
|
||||
|
||||
do {
|
||||
|
||||
|
||||
fileinfo = enumerator.next_file(null);
|
||||
|
||||
if (!fileinfo) {
|
||||
|
|
@ -248,7 +257,7 @@ let WallpaperController = new Lang.Class({
|
|||
};
|
||||
|
||||
let name = fileinfo.get_name();
|
||||
|
||||
|
||||
// ignore hidden files and first element
|
||||
if (name[0] != '.' && name != firstHistoryElement) {
|
||||
deleteFile = Gio.file_new_for_path(this.wallpaperlocation + name);
|
||||
|
|
@ -258,6 +267,10 @@ let WallpaperController = new Lang.Class({
|
|||
} while(fileinfo);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
menuShowHook: function() {
|
||||
this.currentWallpaper = this._getCurrentWallpaper();
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue