Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3.0.2 #203

Merged
merged 14 commits into from
May 9, 2024
2 changes: 1 addition & 1 deletion container/runx11docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ $SCRIPT_DIR/x11docker/x11docker \
--network \
--init=systemd \
--user=RETAIN \
--runasuser="journalctl -f &" \
--runasuser="gnome-extensions enable [email protected]; journalctl -f &" \
-- --mount type=bind,source=$SRC_DIR,target=$DST_DIR,readonly -- \
$1
9 changes: 8 additions & 1 deletion src/historyMenuElements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import {Logger} from './logger.js';
Gio._promisify(Gio.File.prototype, 'copy_async', 'copy_finish');
Gio._promisify(Gio.File.prototype, 'replace_contents_bytes_async', 'replace_contents_finish');

import * as Config from 'resource:///org/gnome/shell/misc/config.js';
const [MAJOR, unused_MINOR] = Config.PACKAGE_VERSION.split('.').map(s => Number(s));

// FIXME: Generated static class code produces a no-unused-expressions rule error
/* eslint-disable no-unused-expressions */

Expand Down Expand Up @@ -595,7 +598,11 @@ class HistorySection extends PopupMenu.PopupMenuSection {
overlay_scrollbars: true,
});

this.actor.add_actor(this.box);
// https://gjs.guide/extensions/upgrading/gnome-shell-46.html#clutter-container
if (MAJOR < 46)
this.actor.add_actor(this.box);
else
this.actor.add_child(this.box);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions src/manager/defaultWallpaperManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as Utils from '../utils.js';

import {WallpaperManager} from './wallpaperManager.js';
import {Logger} from '../logger.js';
import type {Settings} from '../settings.js';
import {Settings} from '../settings.js';

/**
* A general default wallpaper manager.
Expand Down Expand Up @@ -50,12 +50,12 @@ class DefaultWallpaperManager extends WallpaperManager {
* @returns {Promise<void>} Only resolves
*/
static setSingleBackground(wallpaperURI: string, backgroundSettings: Settings): Promise<void> {
const storedScalingMode = new Settings().getString('scaling-mode');
if (Utils.isImageMerged(wallpaperURI))
// merged wallpapers need mode "spanned"
backgroundSettings.setString('picture-options', 'spanned');
else
// single wallpapers need mode "zoom"
backgroundSettings.setString('picture-options', 'zoom');
else if (storedScalingMode)
backgroundSettings.setString('picture-options', storedScalingMode);

Utils.setPictureUriOfSettingsObject(backgroundSettings, wallpaperURI);
return Promise.resolve();
Expand All @@ -70,12 +70,12 @@ class DefaultWallpaperManager extends WallpaperManager {
* @returns {Promise<void>} Only resolves
*/
static setSingleLockScreen(wallpaperURI: string, backgroundSettings: Settings, screensaverSettings: Settings): Promise<void> {
const storedScalingMode = new Settings().getString('scaling-mode');
if (Utils.isImageMerged(wallpaperURI))
// merged wallpapers need mode "spanned"
screensaverSettings.setString('picture-options', 'spanned');
else
// single wallpapers need mode "zoom"
screensaverSettings.setString('picture-options', 'zoom');
else if (storedScalingMode)
screensaverSettings.setString('picture-options', storedScalingMode);

Utils.setPictureUriOfSettingsObject(screensaverSettings, wallpaperURI);
return Promise.resolve();
Expand Down
22 changes: 21 additions & 1 deletion src/manager/wallpaperManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Settings} from './../settings.js';
import {getEnumFromSettings} from './../utils.js';

// Generated code produces a no-shadow rule error
/* eslint-disable */
Expand Down Expand Up @@ -104,8 +105,27 @@ function getModeNameList(): string[] {
return list;
}

/**
* Get a list of all the valid enum entries and return them as an array of strings
*
* Note: The list gets pre-filtered of unwanted values.
*
* @returns {string[]} Array of string containing valid enum values
*/
function getScalingModeEnum(): string[] {
const excludes = [
'none', // No wallpaper
'wallpaper', // Tiled wallpapers, repeating pattern
'spanned', // Ignoring aspect ratio
];

return getEnumFromSettings(new Settings('org.gnome.desktop.background'), 'picture-options')
.filter(s => !excludes.includes(s));
}

export {
WallpaperManager,
Mode,
getModeNameList
getModeNameList,
getScalingModeEnum
};
6 changes: 3 additions & 3 deletions src/metadata.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"shell-version": [ "45" ],
"shell-version": [ "45", "46" ],
"uuid": "[email protected]",
"settings-schema": "org.gnome.shell.extensions.space.iflow.randomwallpaper",
"name": "Random Wallpaper",
"description": "Load new desktop wallpapers from various online sources with ease!",
"version": 34,
"semantic-version": "3.0.1",
"version": 35,
"semantic-version": "3.0.2",
"url": "https://github.com/ifl0w/RandomWallpaperGnome3",
"issue-url": "https://github.com/ifl0w/RandomWallpaperGnome3/issues"
}
14 changes: 14 additions & 0 deletions src/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ class Notification {
const message = `A new wallpaper was set!\n${infoString}`;
notify('New Wallpaper', message);
}

/**
* Show an error notification for failed wallpaper downloads.
*
* @param {unknown} error The error that was thrown when fetching a new wallpaper
*/
static fetchWallpaperFailed(error: unknown): void {
let errorMessage = String(error);

if (error instanceof Error)
errorMessage = error.message;

notify('RandomWallpaperGnome3: Wallpaper Download Failed!', errorMessage);
}
}

export {Notification};
19 changes: 19 additions & 0 deletions src/prefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ class RandomWallpaperSettings extends ExtensionPreferences {
'selected',
Gio.SettingsBindFlags.DEFAULT);

const comboScalingMode = this._getAs<Adw.ComboRow>(builder, 'combo_scaling_mode');
comboScalingMode.model = Gtk.StringList.new(WallpaperManager.getScalingModeEnum());
const gnomeDesktopSettings = new Settings.Settings('org.gnome.desktop.background');
const gnomeScreensaverSettings = new Settings.Settings('org.gnome.desktop.screensaver');

let storedScalingModeIdx = WallpaperManager.getScalingModeEnum().indexOf(settings.getString('scaling-mode'));
if (storedScalingModeIdx < 0)
// fallback to the current value set in gnome-shell for the desktop
storedScalingModeIdx = WallpaperManager.getScalingModeEnum().indexOf(gnomeDesktopSettings.getString('picture-options'));

// can't bind a string to "selected" and "active-item" is not available on Adw.ComboRow, binding is implemented manually below
comboScalingMode.selected = storedScalingModeIdx >= 0 ? storedScalingModeIdx : Gtk.INVALID_LIST_POSITION;
comboScalingMode.connect('notify::selected', () => {
const selectedString = WallpaperManager.getScalingModeEnum()[comboScalingMode.selected];
gnomeDesktopSettings.setString('picture-options', selectedString);
gnomeScreensaverSettings.setString('picture-options', selectedString);
settings.setString('scaling-mode', selectedString);
});

const comboLogLevel = this._getAs<Adw.ComboRow>(builder, 'log_level');
comboLogLevel.model = Gtk.StringList.new(Logger.getLogLevelNameList());
settings.bind('log-level',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
<description>Allows to choose what backgrounds will be changed.</description>
</key>

<key type='s' name='scaling-mode'>
<default>""</default>
<summary>Choose which zoom mode wallpapers get</summary>
<description>Allows to choose what setting 'picture-options' will get.</description>
</key>

<key type='i' name='log-level'>
<default>2</default>
<summary>Tier of logs</summary>
Expand Down
30 changes: 18 additions & 12 deletions src/soupBowl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,24 @@ class SoupBowl {
*/
private _send_and_receive_soup24(soupMessage: Soup.Message): Promise<Uint8Array> {
return new Promise((resolve, reject) => {
/* eslint-disable */
// Incompatible version of Soup types. Ignoring type checks.
// @ts-ignore
this._session.queue_message(soupMessage, (_, msg) => {
if (!msg.response_body) {
reject(new Error('Message has no response body'));
return;
}
try {
/* eslint-disable */
// Incompatible version of Soup types. Ignoring type checks.
// @ts-ignore
this._session.queue_message(soupMessage, (_, msg) => {
if (!msg.response_body) {
reject(new Error('Message has no response body'));
return;
}

const response_body_bytes = msg.response_body.flatten().get_data();
resolve(response_body_bytes);
});
/* eslint-enable */
const response_body_bytes = msg.response_body.flatten().get_data();
resolve(response_body_bytes);
});
/* eslint-enable */
} catch (error) {
Logger.error(error, this);
reject(new Error('Request failed'));
}
});
}

Expand All @@ -81,6 +86,7 @@ class SoupBowl {
reject(new Error('Empty response'));
}).catch(error => {
Logger.error(error, this);
reject(new Error('Request failed'));
});
});
}
Expand Down
7 changes: 6 additions & 1 deletion src/ui/pageGeneral.blp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ Adw.PreferencesPage page_general {
use-subtitle: true;
}

Adw.ComboRow combo_scaling_mode {
title: _("Wallpaper Scaling Mode");
use-subtitle: true;
}

Adw.ActionRow multiple_displays_row {
title: _("Different Wallpapers on Multiple Displays");
subtitle: _("Requires HydraPaper or Superpaper.\nFills from History.");
subtitle: _("Requires HydraPaper or Superpaper.");
sensitive: false;

Switch enable_multiple_displays {
Expand Down
21 changes: 21 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,29 @@ function isImageMerged(filename: string): boolean {
Superpaper.isImageMerged(filename);
}

/**
* Get all possible enum values from a gsettings schema.
*
* @param {Settings} settings The gsettings containing the enum
* @param {string} key The key of the enum in the schema
* @returns {string[]} A list of strings with all possible values for a key
*/
function getEnumFromSettings(settings: Settings, key: string): string[] {
// Fill combo from settings enum

const availableTypes = settings.getSchema().get_key(key).get_range(); // GLib.Variant (sv)
// (sv) = Tuple(%G_VARIANT_TYPE_STRING, %G_VARIANT_TYPE_VARIANT)
// s should be 'enum'
// v should be an array enumerating the possible values. Each item in the array is a possible valid value and no other values are valid.
// v is 'as' (array of strings)
const availableTypeNames = availableTypes.get_child_value(1).get_variant().get_strv();

return availableTypeNames;
}

export {
SourceType,
getEnumFromSettings,
getSourceTypeName,
getWallpaperManager,
isImageMerged,
Expand Down
2 changes: 2 additions & 0 deletions src/wallpaperController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ class WallpaperController {
Notification.newWallpaper(newImageEntries.reverse());
} catch (error) {
Logger.error(error, this);
if (this._settings.getBoolean('show-notifications'))
Notification.fetchWallpaperFailed(error);
} finally {
this._stopLoadingHooks.forEach(element => element());
}
Expand Down
4 changes: 4 additions & 0 deletions types/misc/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,7 @@ declare module 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js' {
getPreferencesWidget(): Gtk.Widget;
}
}

declare module 'resource:///org/gnome/shell/misc/config.js' {
export const PACKAGE_VERSION: string;
}
Loading