mirror of
https://github.com/Hopiu/RandomWallpaperGnome3.git
synced 2026-03-16 22:20:24 +00:00
Implement feature request #5
This commit is contained in:
parent
09c50a32a8
commit
1d7299fa5c
5 changed files with 186 additions and 69 deletions
|
|
@ -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 () {
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -55,6 +55,12 @@
|
|||
<description>The time that already elapsed.</description>
|
||||
</key>
|
||||
|
||||
<key type='b' name='change-lock-screen'>
|
||||
<default>false</default>
|
||||
<summary>Change lock screen</summary>
|
||||
<description>Weather the gnome lock screen should also be set to the new wallpaper.</description>
|
||||
</key>
|
||||
|
||||
</schema>
|
||||
|
||||
<schema path="/org/gnome/shell/extensions/space-iflow-randomwallpaper-sources/"
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
<property name="margin_top">15</property>
|
||||
<property name="margin_bottom">15</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">10</property>
|
||||
<child>
|
||||
<object class="GtkFrame">
|
||||
<property name="visible">True</property>
|
||||
|
|
@ -101,7 +102,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="label" translatable="yes">The source that is used to fetch random wallpapers. You can select between desktoppr.co (default) and an experimental version of wallheaven.cc.</property>
|
||||
<property name="label" translatable="yes">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.</property>
|
||||
<property name="wrap">True</property>
|
||||
<property name="max_width_chars">1</property>
|
||||
<property name="xalign">0</property>
|
||||
|
|
@ -185,19 +186,6 @@
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparator">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
|
@ -285,15 +273,97 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkSeparator">
|
||||
<object class="GtkFrame">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
<property name="label_xalign">0</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">10</property>
|
||||
<property name="margin_right">10</property>
|
||||
<property name="margin_top">10</property>
|
||||
<property name="margin_bottom">10</property>
|
||||
<property name="column_spacing">10</property>
|
||||
<property name="baseline_row">2</property>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="column_homogeneous">True</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="change-lock-screen-label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="label" translatable="yes">Change lock screen</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="change-lock-screen-description">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="hexpand">True</property>
|
||||
<property name="label" translatable="yes">Also change the gnome lock screen image to the new wallpaper.</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="wrap">True</property>
|
||||
<property name="max_width_chars">1</property>
|
||||
<property name="xalign">0</property>
|
||||
<style>
|
||||
<class name="dim-label"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">0</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkSwitch" id="change-lock-screen">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="halign">end</property>
|
||||
<property name="valign">start</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="top_attach">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="label_item">
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue