[gnome] Update extensions

This commit is contained in:
2024-10-31 10:19:02 -04:00
parent 851ec4a772
commit 6d1e6d1132
238 changed files with 8705 additions and 4185 deletions

View File

@ -4,7 +4,7 @@ Bring some color to your GNOME desktop by syncing your desktop and lockscreen wa
[![Get it on GNOME extensions](/screenshot/get_it_on_gnome_extensions.png)](https://extensions.gnome.org/extension/1262/bing-wallpaper-changer/) [![<3 Sponsor this project on GitHub <3](/screenshot/sponsor.png)](https://github.com/sponsors/neffo)
![Screenshot](/screenshot/notification.png)
![Screenshot](/screenshot/overview.jpg)
As featured on [OMG! Ubuntu](https://www.omgubuntu.co.uk/2017/07/bing-wallpaper-changer-gnome-extension).
@ -18,10 +18,44 @@ Also, check out my related [Google Earth View wallpaper extension](https://githu
* Image gallery to view, select and curate stored images
* Optionally delete old images after a week, or you can keep (and curate) them forever
* Override the lockscreen blur (NEW: lockscreen blur is now dynamic!)
* Language support: English (en), German (de), Dutch (nl), Italian (it), Polish (pl), Chinese (zh_CN, zh_TW), French (fr_FR), Portuguese (pt, pt_BR), Ukrainian (uk), Russian (ru_RU), Spanish (es), Korean (ko), Indonesian (id), Catalan (ca), Norwegian Bokmål (nb) & Nynorsk (nn), Swedish (sv), Arabic (ar), Hungarian (hu), Japanese (ja), Czech (cs_CZ), Finnish (fi_FI) and Turkish (tr) - a HUGE thanks to the translators
* Language support: English (en), German (de), Dutch (nl), Italian (it), Polish (pl), Chinese (zh_CN, zh_TW), French (fr_FR), Portuguese (pt, pt_BR), Ukrainian (uk), Russian (ru_RU), Spanish (es), Korean (ko), Indonesian (id), Catalan (ca), Norwegian Bokmål (nb) & Nynorsk (nn), Swedish (sv), Arabic (ar), Hungarian (hu), Japanese (ja), Czech (cs_CZ), Finnish (fi_FI) and Turkish (tr), Persian (fa_ir) - a HUGE thanks to the translators
* Image preview in menus & ability to manually set wallpapers individually or copy image to clipboard
* A selection of different theme-aware indicator (tray) icons to choose (or hide it completely)
## Quickstart guide
* Install from [GNOME extensions](https://extensions.gnome.org/extension/1262/bing-wallpaper-changer/), by default your wallpaper will be synced to the current Bing image of the day - if that's all you want you don't have to do anymore, everything is automatic
* Bing Wallpaper (by default) builds a collection of images over time (this can be disabled if required)
### Control bar
![Bing Wallpaper menu control bar](/screenshot/controlbar.png)
* 🤍 - Favorite/unfavorite current image (can be used to shuffle only favorite images and favorites are never deleted automatically)
* 🗑️ - Trash/untrash current image (exclude from shuffle selection or optionally deleted from disk)
* ⏪ - select previous day's image (in date order)
* ⏩ - select next day's image (in date order)
* ⏭️ - select today's image (skip to current)
* 🎲 - I'm feeling lucky, show me a random image (by default you should have at least 8 images available, curated with favorite and trash buttons)
### Quick settings
![Bing Wallpaper menu control bar](/screenshot/quicksettings.png)
* Always show new images - when a new Bing wallpaper is available switch to it immediately
* Image shuffle mode - switch to a random image at user defined intervals (default once per day or once per startup)
* Image shuffle only favorites - only select favorite images (🤍), by default 'trashed' images are always excluded
* Image shuffle only UHD resolution - occasionally some images are not UHD, exclude these from selection
### Gallery
![Gallery item](/screenshot/gallery.png)
The 4 buttons in the gallery (3rd page in the preferences) do have tool-tips but these do the following:
- Favorite - favorite this image (equivalent to doing this via the control bar)
- Apply - set this image as wallpaper
- View - open image in image viewer
- Info - open the Bing description of the image
- Trash - trash the image
## TODO
* add more languages (#14) - [please help if you can](https://github.com/neffo/bing-wallpaper-gnome-extension/issues/14)
@ -33,10 +67,25 @@ Also, check out my related [Google Earth View wallpaper extension](https://githu
* Bing may detect your location incorrectly (and force a locale as above) - if you see this, please let me know what Bing.com itself does
* GNOME Shell themes can break some GNOME popup menu elements (toggle switches for example). This impacts GNOME more generally, not just this extension. Double check you are running latest versions of your themes (or disable them).
## Requirements
## System Requirements
GNOME 3.36+ or 40+ (Ubuntu 20.04 LTS or later, older versions of the extension work with 3.18+, but are no longer supported).
## Package dependencies
Below packages are required to build the extension
```
npm
gettext
intltool
zip
```
For Ubuntu you can hit below command to install
```
sudo apt install npm gettext intltool zip -y
```
## Install
[Install from extensions.gnome.org](https://extensions.gnome.org/extension/1262/bing-wallpaper-changer/)
@ -53,7 +102,7 @@ sh install.sh
## Enable debug logging
Enable debug logging through the exptension preferences 'Debug options' tab or if unable to open preferences you can enable debugging using dconf-editor with this command:
Enable debug logging through the extension preferences 'Debug options' tab or if unable to open preferences you can enable debugging using dconf-editor with this command:
```
GSETTINGS_SCHEMA_DIR=$HOME/.local/share/gnome-shell/extensions/BingWallpaper@ineffable-gmail.com/schemas dconf-editor /org/gnome/shell/extensions/bingwallpaper/
```

View File

@ -20,6 +20,7 @@ var shellVersionMajor = parseInt(Config.PACKAGE_VERSION.split('.')[0]);
var shellVersionMinor = parseInt(Config.PACKAGE_VERSION.split('.')[1]);
var shellVersionPoint = parseInt(Config.PACKAGE_VERSION.split('.')[2]);
var blurField = shellVersionMajor >= 46 ? "radius" : "sigma";
// default BWP mild blur
var BWP_BLUR_SIGMA = 2;
var BWP_BLUR_BRIGHTNESS = 55;
@ -50,7 +51,7 @@ export function _updateBackgroundEffects_BWP(monitorIndex) {
if (effect) {
effect.set({ // GNOME defaults when login prompt is visible
brightness: BLUR_BRIGHTNESS,
sigma: BLUR_SIGMA * themeContext.scale_factor,
[blurField]: BLUR_SIGMA * themeContext.scale_factor,
});
}
}
@ -59,7 +60,7 @@ export function _updateBackgroundEffects_BWP(monitorIndex) {
if (effect) {
effect.set({ // adjustable blur when clock is visible
brightness: BWP_BLUR_BRIGHTNESS * 0.01, // we use 0-100 rather than 0-1, so divide by 100
sigma: BWP_BLUR_SIGMA * themeContext.scale_factor,
[blurField]: BWP_BLUR_SIGMA * themeContext.scale_factor,
});
}
}
@ -91,7 +92,7 @@ export function _clampValue(value) {
export default class Blur {
constructor() {
this.enabled = false;
log('Bing Wallpaper adjustable blur is '+supportedVersion()?'available':'not available');
log('Bing Wallpaper adjustable blur is '+(supportedVersion()?'available':'not available'));
}
set_blur_strength(value) {

View File

@ -108,7 +108,7 @@ export default class Carousel {
this.log('Delete requested for '+filename);
Utils.deleteImage(filename);
Utils.setImageHiddenStatus(this.settings, image.urlbase, true);
Utils.cleanupImageList(this.settings); // hide image instead
Utils.purgeImages(this.settings); // hide image instead
widget.get_parent().get_parent().set_visible(false); // bit of a hack
if (this.callbackfunc)
this.callbackfunc();

View File

@ -55,10 +55,16 @@ const newMenuSwitchItem = (label, state) => {
}
function log(msg) {
if (bingWallpaperIndicator && bingWallpaperIndicator._settings.get_boolean('debug-logging'))
if (BingDebug())
console.log('BingWallpaper extension: ' + msg); // disable to keep the noise down in journal
}
function BingDebug() {
if (bingWallpaperIndicator && bingWallpaperIndicator._settings.get_boolean('debug-logging'))
return true;
return false;
}
function notifyError(msg) {
Main.notifyError("BingWallpaper extension error", msg);
}
@ -152,12 +158,12 @@ class BingWallpaperIndicator extends Button {
this.toggleSetBackground = newMenuSwitchItem(_("Set background image"), this._settings.get_boolean('set-background'));
this.toggleSelectNew = newMenuSwitchItem(_("Always show new images"), this._settings.get_boolean('revert-to-current-image'));
this.toggleShuffle = newMenuSwitchItem(_("Image shuffle mode"), true);
this.toggleShuffleOnlyFaves = newMenuSwitchItem(_("Image shuffle only favourites"), this._settings.get_boolean('random-mode-include-only-favourites'));
this.toggleNotifications = newMenuSwitchItem(_("Enable desktop notifications"), this._settings.get_boolean('notify'));
this.toggleShuffleOnlyFaves = newMenuSwitchItem(_("Image shuffle only favorites"), this._settings.get_boolean('random-mode-include-only-favourites'));
/*this.toggleNotifications = newMenuSwitchItem(_("Enable desktop notifications"), this._settings.get_boolean('notify'));*/
this.toggleImageCount = newMenuSwitchItem(_("Show image count"), this._settings.get_boolean('show-count-in-image-title'));
this.toggleShuffleOnlyUHD = newMenuSwitchItem(_("Image shuffle only UHD resolutions"), this._settings.get_boolean('random-mode-include-only-uhd'));
[this.toggleNotifications, /*this.toggleImageCount, this.toggleSetBackground,*/ this.toggleSelectNew,
[/*this.toggleNotifications, this.toggleImageCount, this.toggleSetBackground,*/ this.toggleSelectNew,
this.toggleShuffle, this.toggleShuffleOnlyFaves, this.toggleShuffleOnlyUHD]
.forEach(e => this.settingsSubMenu.menu.addMenuItem(e));
@ -220,15 +226,21 @@ class BingWallpaperIndicator extends Button {
// listen for configuration changes
_setConnections() {
this._settings.connect('changed::hide', () => {
this.visible = !this._settings.get_boolean('hide');
});
this.settings_connections = [];
this.settings_connections.push(
this._settings.connect('changed::hide', () => {
this.visible = !this._settings.get_boolean('hide');
})
);
let settingConnections = [
{signal: 'changed::icon-name', call: this._setIcon},
{signal: 'changed::market', call: this._refresh},
{signal: 'changed::set-background', call: this._setBackground},
{signal: 'changed::override-lockscreen-blur', call: this._setBlur},
{signal: 'changed::lockscreen-blur-strength', call: this._setBlur},
{signal: 'changed::lockscreen-blur-brightness', call: this._setBlur},
{signal: 'changed::selected-image', call: this._setImage},
{signal: 'changed::delete-previous', call: this._cleanUpImages},
{signal: 'changed::notify', call: this._notifyCurrentImage},
@ -244,11 +256,10 @@ class BingWallpaperIndicator extends Button {
// _setShuffleToggleState
settingConnections.forEach((e) => {
this._settings.connect(e.signal, e.call.bind(this));
this.settings_connections.push(
this._settings.connect(e.signal, e.call.bind(this))
);
});
this._settings.connect('changed::lockscreen-blur-strength', blur.set_blur_strength.bind(this, this._settings.get_int('lockscreen-blur-strength')));
this._settings.connect('changed::lockscreen-blur-brightness', blur.set_blur_brightness.bind(this, this._settings.get_int('lockscreen-blur-brightness')));
// ensure we're in a sensible initial state
this._setIcon();
@ -275,19 +286,23 @@ class BingWallpaperIndicator extends Button {
let toggles = [ /*{key: 'set-background', toggle: this.toggleSetBackground},*/
{key: 'revert-to-current-image', toggle: this.toggleSelectNew},
{key: 'notify', toggle: this.toggleNotifications},
/*{key: 'show-count-in-image-title', toggle: this.toggleImageCount},*/
/*{key: 'notify', toggle: this.toggleNotifications},
{key: 'show-count-in-image-title', toggle: this.toggleImageCount},*/
{key: 'random-mode-enabled', toggle: this.toggleShuffle},
{key: 'random-mode-include-only-favourites', toggle: this.toggleShuffleOnlyFaves},
/*{key: 'random-mode-include-only-unhidden', toggle: this.toggleShuffleOnlyUnhidden},*/
{key: 'random-mode-include-only-uhd', toggle: this.toggleShuffleOnlyUHD}];
toggles.forEach( (e) => {
this._settings.connect('changed::'+e.key, () => {
e.toggle.setToggleState(this._settings.get_boolean(e.key));
});
toggles.forEach( (e) => {
this.settings_connections.push(
this._settings.connect('changed::'+e.key, () => {
log(e.key+' setting changed to '+ (this._settings.get_boolean(e.key)?'true':'false'));
e.toggle.setToggleState(this._settings.get_boolean(e.key));
})
);
e.toggle.connect('toggled', (item, state) => {
this._settings.set_boolean(e.key, state);
log(e.key+' switch toggled to '+ (state?'true':'false'));
this._setBooleanSetting(e.key, state);
});
});
@ -300,7 +315,32 @@ class BingWallpaperIndicator extends Button {
[this.clipboardImageItem, this.clipboardURLItem].
forEach(e => e.setSensitive(false));
}
}
}
_setBooleanSetting(key, state) {
let success = this._settings.set_boolean(key, state);
log('key '+key+' set to ' + (state?'true':'false') + ' (returned ' + (success?'true':'false')+')');
}
_setStringSetting(key, value) {
let success = this._settings.set_string(key, value);
log('key '+key+' set to ' + value + ' (returned ' + (success?'true':'false')+')');
}
_setIntSetting(key, value) {
let success = this._settings.set_int(key, value);
log('key '+key+' set to ' + value + ' (returned ' + (success?'true':'false')+')');
}
_onDestroy() {
this._unsetConnections();
}
_unsetConnections() {
this.settings_connections.forEach((e) => {
this._settings.disconnect(e);
});
}
_openPrefs() {
this._extension.openPreferences();
@ -312,7 +352,6 @@ class BingWallpaperIndicator extends Button {
this.clipboardImageItem.setSensitive(!this._updatePending && this.imageURL != "");
this.clipboardURLItem.setSensitive(!this._updatePending && this.imageURL != "");
this.thumbnailItem.setSensitive(!this._updatePending && this.imageURL != "");
//this.showItem.setSensitive(!this._updatePending && this.title != "" && this.explanation != "");
this.dwallpaperItem.setSensitive(!this._updatePending && this.filename != "");
this.swallpaperItem.setSensitive(!this._updatePending && this.filename != "");
this.titleItem.setSensitive(!this._updatePending && this.imageinfolink != "");
@ -348,7 +387,7 @@ class BingWallpaperIndicator extends Button {
if (this._settings.get_boolean('notify')) {
let image = this._getCurrentImage();
if (image) {
this._createNotification(image);
this._createImageNotification(image);
}
}
}
@ -555,7 +594,7 @@ class BingWallpaperIndicator extends Button {
}
_curImage() {
this._settings.set_string('selected-image', 'current');
this._setStringSetting('selected-image', 'current');
this._gotoImage(0);
}
@ -569,13 +608,13 @@ class BingWallpaperIndicator extends Button {
if (randomEnabled) {
log('enabled shuffle mode, by setting a shuffe timer (5 seconds)');
this._restartShuffleTimeout(5);
this._settings.set_boolean('revert-to-current-image', false);
this._setBooleanSetting('revert-to-current-image', false);
}
else {
// clear shuffle timer
if (this._shuffleTimeout)
GLib.source_remove(this._shuffleTimeout);
this._settings.set_boolean('revert-to-current-image', true);
this._setBooleanSetting('revert-to-current-image', true);
}
}
@ -627,7 +666,7 @@ class BingWallpaperIndicator extends Button {
let newImage = Utils.getImageByIndex(imageList, curIndex + relativePos);
if (newImage)
this._settings.set_string('selected-image', newImage.urlbase.replace('/th?id=OHR.', ''));
this._setStringSetting('selected-image', newImage.urlbase.replace('/th?id=OHR.', ''));
}
_getCurrentImage() {
@ -645,10 +684,17 @@ class BingWallpaperIndicator extends Button {
this._restartTimeout();
let market = this._settings.get_string('market');
// Soup3 should be the version used, but in the past some distros have packaged older versions only
if (Soup.MAJOR_VERSION >= 3) {
let url = BingImageURL;
let params = Utils.BingParams;
params['mkt'] = ( market != 'auto' ? market : '' );
// if we've set previous days to be something less than 8 and
// delete previous is active we want to just request a subset of wallpapers
if (this._settings.get_boolean('delete-previous') == true && this._settings.get_int('previous-days')<8) {
params['n'] = ""+this._settings.get_int('previous-days');
}
let request = Soup.Message.new_from_encoded_form('GET', url, Soup.form_encode_hash(params));
request.request_headers.append('Accept', 'application/json');
@ -660,6 +706,7 @@ class BingWallpaperIndicator extends Button {
}
catch(error) {
log('unable to send libsoup json message '+error);
notifyError('Unable to fetch Bing metadata\n'+error);
}
}
else {
@ -675,6 +722,7 @@ class BingWallpaperIndicator extends Button {
}
catch (error) {
log('unable to send libsoup json message '+error);
notifyError('Unable to fetch Bing metadata\n'+error);
}
}
}
@ -694,6 +742,7 @@ class BingWallpaperIndicator extends Button {
}
catch (error) {
log('Network error occured: ' + error);
notifyError('network error occured\n'+error);
this._updatePending = false;
this._restartTimeout(TIMEOUT_SECONDS_ON_HTTP_ERROR);
}
@ -759,13 +808,13 @@ class BingWallpaperIndicator extends Button {
log('WARNING: Bing returning market data for ' + datamarket + ' rather than selected ' + prefmarket);
Utils.purgeImages(this._settings); // delete older images if enabled
//Utils.cleanupImageList(this._settings); // disabled, as old images should still be downloadble in theory
//Utils.cleanupImageList(this._settings); // merged into purgeImages
this._downloadAllImages(); // fetch missing images that are still available
Utils.populateImageListResolutions(this._settings);
if (newImages.length > 0 && this._settings.get_boolean('revert-to-current-image')) {
// user wants to switch to the new image when it arrives
this._settings.set_string('selected-image', 'current');
this._setStringSetting('selected-image', 'current');
}
if (this._settings.get_boolean('notify')) {
@ -773,7 +822,7 @@ class BingWallpaperIndicator extends Button {
// notify all new images
newImages.forEach((image) => {
log('New image to notify: ' + Utils.getImageTitle(image));
this._createNotification(image);
this._createImageNotification(image);
});
}
else {
@ -781,7 +830,7 @@ class BingWallpaperIndicator extends Button {
let last = newImages.pop();
if (last) {
log('New image to notify: ' + Utils.getImageTitle(last));
this._createNotification(last);
this._createImageNotification(last);
}
}
}
@ -791,6 +840,7 @@ class BingWallpaperIndicator extends Button {
}
catch (error) {
log('_parseData() failed with error ' + error + ' @ '+error.lineNumber);
notifyError('Bing metadata parsing error check ' + error + ' @ '+error.lineNumber);
log(error.stack);
}
}
@ -801,15 +851,25 @@ class BingWallpaperIndicator extends Button {
}
}
_createNotification(image) {
// set notifications icon
let source = new MessageTray.Source('Bing Wallpaper', 'preferences-desktop-wallpaper-symbolic');
Main.messageTray.add(source);
_createImageNotification(image) {
let msg = _('Bing Wallpaper of the Day for') + ' ' + this._localeDate(image.fullstartdate);
let details = Utils.getImageTitle(image);
let notification = new MessageTray.Notification(source, msg, details);
notification.setTransient(this._settings.get_boolean('transient'));
source.showNotification(notification);
this._createNotification(msg, details);
log('_createImageNotification: '+msg+' details: '+details);
}
_createNotification(msg, details) {
const systemSource = MessageTray.getSystemSource();
const bingNotify = new MessageTray.Notification({
source: systemSource,
title: msg,
body: details,
gicon: new Gio.ThemedIcon({name: 'image-x-generic'}),
iconName: 'image-x-generic',
});
systemSource.addNotification(bingNotify);
//Main.notify(msg, details);
log('_createNotification: '+msg+' details: '+details);
}
_shuffleImage() {
@ -889,7 +949,7 @@ class BingWallpaperIndicator extends Button {
this.dimensions.width = image.width?image.width:null;
this.dimensions.height = image.height?image.height:null;
this.selected_image = Utils.getImageUrlBase(image);
this._settings.set_string('selected-image', this.selected_image);
this._setStringSetting('selected-image', this.selected_image);
if (("favourite" in image) && image.favourite === true ) {
this.favourite_status = true;
@ -944,14 +1004,14 @@ class BingWallpaperIndicator extends Button {
let stateJSON = JSON.stringify(state);
log('Storing state as JSON: ' + stateJSON);
this._settings.set_string('state', stateJSON);
this._setStringSetting('state', stateJSON);
}
}
_reStoreState() {
try {
// patch for relative paths, ensures that users running git version don't end up with broken state - see EGO review for version 38 https://extensions.gnome.org/review/30299
this._settings.set_string('download-folder', this._settings.get_string('download-folder').replace('$HOME', '~'));
this._setStringSetting('download-folder', this._settings.get_string('download-folder').replace('$HOME', '~'));
let stateJSON = this._settings.get_string('state');
let state = JSON.parse(stateJSON);
let maxLongDate = null;
@ -1015,7 +1075,9 @@ class BingWallpaperIndicator extends Button {
let BingWallpaperDir = Utils.getWallpaperDir(this._settings);
let dir = Gio.file_new_for_path(BingWallpaperDir);
if (!dir.query_exists(null)) {
dir.make_directory_with_parents(null);
//dir.make_directory_with_parents(null);
notifyError('Download folder '+BingWallpaperDir+' does not exist or is not writable');
return;
}
log("Downloading " + url + " to " + file.get_uri());
let request = Soup.Message.new('GET', url);
@ -1035,6 +1097,7 @@ class BingWallpaperIndicator extends Button {
}
catch (error) {
log('error sending libsoup message '+error);
notifyError('Network error '+error);
}
}
@ -1059,12 +1122,14 @@ class BingWallpaperIndicator extends Button {
}
catch(e) {
log('Error writing file: ' + e);
notifyError('Image '+file.get_path()+' is not writable, check folder permissions or select a different folder\n'+e);
}
}
);
}
catch (error) {
log('Unable download image '+error);
notifyError('Image '+file.get_path()+' file error, check folder permissions, disk space or select a different folder\n'+e);
}
}

View File

@ -6,9 +6,10 @@
"settings-schema": "org.gnome.shell.extensions.bingwallpaper",
"shell-version": [
"45",
"46"
"46",
"47"
],
"url": "https://github.com/neffo/bing-wallpaper-gnome-extension",
"uuid": "BingWallpaper@ineffable-gmail.com",
"version": 49
"version": 50
}

View File

@ -73,6 +73,8 @@ export default class BingWallpaperExtensionPreferences extends ExtensionPreferen
const debugSwitch = buildable.get_object('debug_switch');
const revertSwitch = buildable.get_object('revert_switch');
const trash_purge_switch = buildable.get_object('trash_purge_switch');
const delete_previous_switch = buildable.get_object('delete_previous_switch');
const delete_previous_adjustment = buildable.get_object('delete_previous_adjustment');
const always_export_switch = buildable.get_object('always_export_switch');
const gallery_page = buildable.get_object('gallery_page');
const carouselFlowBox = buildable.get_object('carouselFlowBox');
@ -213,6 +215,7 @@ export default class BingWallpaperExtensionPreferences extends ExtensionPreferen
settings.bind('random-interval', randomIntervalEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('trash-deletes-images', trash_purge_switch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('always-export-bing-json', always_export_switch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('delete-previous', delete_previous_switch, 'active', Gio.SettingsBindFlags.DEFAULT);
// button opens Nautilus at our image folder
openBtn.connect('clicked', (widget) => {
@ -276,6 +279,7 @@ export default class BingWallpaperExtensionPreferences extends ExtensionPreferen
settings.bind('override-lockscreen-blur', overrideSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
settings.bind('lockscreen-blur-strength', strengthEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('lockscreen-blur-brightness', brightnessEntry, 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('previous-days', delete_previous_adjustment, 'value', Gio.SettingsBindFlags.DEFAULT);
// add a couple of preset buttons
defaultBtn.connect('clicked', (widget) => {

View File

@ -69,7 +69,14 @@
<description>Save disk space</description>
</key>
<key name="keep-favourites" type="b">
<default>true</default>
<summary>Keep previous wallpapers if they are favourites</summary>
<description>Sensible default behaivour</description>
</key>
<key name="previous-days" type="i">
<range min="1" max="90" />
<default>8</default>
<summary>Number of days to keep wallpapers</summary>
<description>Delete wallpapers after this number of days</description>

View File

@ -162,7 +162,7 @@ Author: Michael Carroll
</child>
<child>
<object class="GtkButton" id="randomButton">
<property name="label" translatable="yes">Set random mode</property>
<property name="label" translatable="yes">Image shuffle mode</property>
<property name="receives-default">1</property>
<layout>
<property name="column">0</property>

View File

@ -201,6 +201,11 @@ Bing Wallpaper GNOME extension by: Michael Carroll
<property name="subtitle" translatable="yes">Enable logging to system journal</property>
</object>
</child>
</object>
</child>
<child>
<object class="AdwPreferencesGroup" id="adv_group">
<property name="title" translatable="yes">Advanced options</property>
<child>
<object class="AdwSwitchRow" id="revert_switch">
<property name="title" translatable="yes">Always show new images</property>
@ -210,7 +215,7 @@ Bing Wallpaper GNOME extension by: Michael Carroll
<child>
<object class="AdwSwitchRow" id="trash_purge_switch">
<property name="title" translatable="yes">Purge on trash</property>
<property name="subtitle" translatable="yes">Trashing an image will remove it from database</property>
<property name="subtitle" translatable="yes">Trashing an image will remove it from database and disk</property>
</object>
</child>
<child>
@ -233,6 +238,26 @@ Bing Wallpaper GNOME extension by: Michael Carroll
</property>
</object>
</child>
<child>
<object class="AdwSwitchRow" id="delete_previous_switch">
<property name="title" translatable="yes">Delete older images</property>
<property name="subtitle" translatable="yes">Automatically delete older images (excludes favourites)</property>
</object>
</child>
<child>
<object class="AdwSpinRow" id="delete_previous_entry">
<property name="title" translatable="yes">Number of days to keep images</property>
<property name="subtitle" translatable="yes">Keep images for this number of days (favourites are kept forever)</property>
<property name="adjustment">
<object class="GtkAdjustment" id="delete_previous_adjustment">
<property name="lower">1</property>
<property name="upper">90</property>
<property name="page_increment">5</property>
<property name="step_increment">1</property>
</object>
</property>
</object>
</child>
</object>
</child>
<child>

View File

@ -118,14 +118,16 @@ export function fetch_change_log(version, label, httpSession) {
httpSession.send_and_read_async(request, GLib.PRIORITY_DEFAULT, null, (httpSession, message) => {
let data = decoder.decode(httpSession.send_and_read_finish(message).get_data());
let text = JSON.parse(data).body;
label.set_label(text);
if (text)
label.set_label(text);
});
}
else {
httpSession.queue_message(request, (httpSession, message) => {
let data = message.response_body.data;
let text = JSON.parse(data).body;
label.set_label(text);
if (text)
label.set_label(text);
});
}
}
@ -299,26 +301,6 @@ export function getImageByIndex(imageList, index) {
return imageList[index];
}
export function cleanupImageList(settings) {
if (settings.get_boolean('trash-deletes-images') == false)
return;
let curList = imageListSortByDate(getImageList(settings));
let cutOff = GLib.DateTime.new_now_utc().add_days(-8); // 8 days ago
let newList = [];
curList.forEach( function (x, i) {
let filename = imageToFilename(settings, x);
let diff = dateFromLongDate(x.fullstartdate, 0).difference(cutOff);
// image is still downloadable (< 8 days old) or still on disk, so we keep
if (diff > 0 || Gio.file_new_for_path(filename).query_exists(null)) {
newList.push(x);
}
else {
BingLog('Cleaning up: '+filename);
}
});
setImageList(settings, newList);
}
export function populateImageListResolutions(settings) {
let curList = imageListSortByDate(getImageList(settings));
let newList = [];
@ -337,7 +319,11 @@ export function populateImageListResolutions(settings) {
export function getFetchableImageList(settings) {
let imageList = getImageList(settings);
let cutOff = GLib.DateTime.new_now_utc().add_days(-8); // 8 days ago
let maxpictures = settings.get_int('previous-days');
let maxdownload = 8;
if (maxpictures < maxdownload && maxpictures >=1)
maxdownload = maxpictures;
let cutOff = GLib.DateTime.new_now_utc().add_days(-maxdownload); // default 8 days ago, 1 day = 1 picture
let dlList = [];
imageList.forEach( function (x, i) {
let diff = dateFromLongDate(x.fullstartdate, 0).difference(cutOff);
@ -369,7 +355,10 @@ export function getWallpaperDir(settings) {
dir.make_directory_with_parents(null);
}
//FIXME: test if dir is good and writable
return BingWallpaperDir;
if (dir.query_exists(null))
return BingWallpaperDir;
else
return null;
}
export function setWallpaperDir(settings, uri) {
@ -547,24 +536,43 @@ export function deleteImage(to_delete) {
}
}
// add image to persistant list so we can delete it later (in chronological order), delete the oldest image (if user wants this)
// optionally purge trashed images (default is not, these just don't get select in random mode), optionally purge older images
export function purgeImages(settings) {
let deletepictures = settings.get_boolean('delete-previous');
if (deletepictures === false)
return;
let deleteprevious = settings.get_boolean('delete-previous');
let keepfavourites = settings.get_boolean('keep-favourites');
let emptytrash = settings.get_boolean('trash-deletes-images');
let maxDays = settings.get_int('previous-days');
BingLog('purgeImages() dp: '+(deleteprevious?'true':'false')+'days:'+maxDays+' favs: '+(keepfavourites?'true':'false')+' trash: '+(emptytrash?'true':'false'));
/*if (deleteprevious === false)
return;*/
let imagelist = imageListSortByDate(getImageList(settings));
let maxpictures = settings.get_int('previous-days');
let origlength = imagelist.length;
while (imagelist.length > maxpictures) {
var to_delete = imagelist.shift(); // get the first (oldest item from the list)
if (deletepictures && to_delete != '') {
let imageFilename = imageToFilename(settings, to_delete);
let cutOff = GLib.DateTime.new_now_utc().add_days(-maxDays); // 8 days ago
let newList = [];
imagelist.forEach( function (image, i) {
var diff = dateFromLongDate(image.fullstartdate, 0).difference(cutOff); // relative age of image, < 0 we can delete
// always keep favourites, keep images that are less than minimum period (previous days) or if clean up delete previous is disabled (default)
var keep_image = (keepfavourites && image.favourite && image.favourite === true) || diff > 0 || !deleteprevious;
var ok_to_delete = !keep_image || (emptytrash && image.hidden);
var imageFilename = imageToFilename(settings, image);
if (emptytrash && image.hidden && diff < 0)
ok_to_delete = true;
if (deleteprevious && image != '' && ok_to_delete) {
BingLog('deleting '+imageFilename);
deleteImage(imageFilename);
}
}
else {
BingLog('keeping '+imageFilename);
newList.push(image);
}
});
setImageList(settings, newList);
BingLog('cleaned up image list, count was '+origlength+' now '+imagelist.length);
cleanupImageList(settings);
//cleanupImageList(settings);
validate_imagename(settings); // if we deleted our current image, we want to reset it to something valid
}
@ -605,7 +613,8 @@ export function importBingJSON(settings) {
let parsed = JSON.parse(decoder.decode(contents)); // FIXME: triggers GJS warning without the conversion, need to investigate
// need to implement some checks for validity here
mergeImageLists(settings, parsed);
cleanupImageList(settings); // remove the older missing images
purgeImages(settings); // remove the older missing images
//cleanupImageList(settings);
}
}
else {