diff --git a/docs/changelog.md b/docs/changelog.md index 2e77a9d9..fb645183 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -16,6 +16,7 @@ SPDX-License-Identifier: CC-BY-4.0 #### Bug Fixes - Fixed selecting items on GNOME 46 requiring two clicks. +- Fixed a bug which caused achievement notifications to be not shown on GNOME 46. ## [Fly-Pie 25](https://github.com/schneegans/fly-pie/releases/tag/v25) diff --git a/src/common/utils.js b/src/common/utils.js index 982eaaa3..9b883f15 100644 --- a/src/common/utils.js +++ b/src/common/utils.js @@ -25,6 +25,50 @@ import PangoCairo from 'gi://PangoCairo'; const St = await importInShellOnly('gi://St'); const Gtk = await importInPrefsOnly('gi://Gtk'); +// We import the Config module. This is done differently in the GNOME Shell process and in +// the preferences process. +const Config = await importConfig(); + +////////////////////////////////////////////////////////////////////////////////////////// +// Two methods for checking the current version of GNOME Shell. // +////////////////////////////////////////////////////////////////////////////////////////// + +// Returns the given argument, except for "alpha", "beta", and "rc". In these cases -3, +// -2, and -1 are returned respectively. +function toNumericVersion(x) { + switch (x) { + case 'alpha': + return -3; + case 'beta': + return -2; + case 'rc': + return -1; + } + return x; +} + +const [GS_MAJOR, GS_MINOR] = Config.PACKAGE_VERSION.split('.').map(toNumericVersion); + +// This method returns true if the current GNOME Shell version matches the given +// arguments. +export function shellVersionIs(major, minor) { + return GS_MAJOR == major && GS_MINOR == toNumericVersion(minor); +} + +// This method returns true if the current GNOME Shell version is at least as high as the +// given arguments. Supports "alpha" and "beta" for the minor version number. +export function shellVersionIsAtLeast(major, minor = 0) { + if (GS_MAJOR > major) { + return true; + } + + if (GS_MAJOR == major) { + return GS_MINOR >= toNumericVersion(minor); + } + + return false; +} + ////////////////////////////////////////////////////////////////////////////////////////// // This method can be used to write a message to GNOME Shell's log. This is enhances // // the standard log() functionality by prepending the extension's name and the location // @@ -85,6 +129,17 @@ export async function importGettext() { return (await import('resource:///org/gnome/shell/extensions/extension.js')).gettext; } +////////////////////////////////////////////////////////////////////////////////////////// +// This method can be used to import the Config module. // +////////////////////////////////////////////////////////////////////////////////////////// + +export async function importConfig() { + if (typeof global === 'undefined') { + return (await import('resource:///org/gnome/Shell/Extensions/js/misc/config.js')); + } + return (await import('resource:///org/gnome/shell/misc/config.js')); +} + ////////////////////////////////////////////////////////////////////////////////////////// // Returns the path to the extension's directory. This is useful to load resources from // // the extension's directory. // diff --git a/src/extension/Daemon.js b/src/extension/Daemon.js index f739b545..ba5f3e1d 100644 --- a/src/extension/Daemon.js +++ b/src/extension/Daemon.js @@ -591,17 +591,25 @@ export default class Daemon { // of the icon seems to depend on the currently used theme and cannot be set from here. // The notification will also contain a hard-coded button which opens the achievements // page of the settings dialog. - _notify(label, details, gicon) { + _notify(title, body, gicon) { if (this._settings.get_boolean('achievement-notifications')) { - const source = new Source('Fly-Pie', ''); - Main.messageTray.add(source); - const n = new Notification(source, label, details, {gicon: gicon}); + let source, notification; + + if (utils.shellVersionIsAtLeast(46)) { + source = new Source({title: 'Fly-Pie'}); + notification = new Notification({source, title, body, gicon: gicon}); + } else { + source = new Source('Fly-Pie', ''); + notification = new Notification(source, title, body, {gicon: gicon}); + } + + Main.messageTray.add(source); // Translators: This is shown on the action button of the notification bubble which // is shown once an achievement is unlocked. - n.addAction(_('Show Achievements'), () => { + notification.addAction(_('Show Achievements'), () => { // Make sure the achievements page is shown. this._settings.set_string('active-stack-child', 'achievements-page'); @@ -609,7 +617,11 @@ export default class Daemon { Main.extensionManager.openExtensionPrefs(this._metadata.uuid, ''); }); - source.showNotification(n); + if (source.addNotification) { + source.addNotification(notification); + } else { + source.showNotification(notification); + } } } }; \ No newline at end of file