Skip to content

Commit

Permalink
🔀 Merge pull request #350 from Schneegans/fix/notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Schneegans authored Apr 11, 2024
2 parents 96f38b4 + b82603f commit 4a08c44
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
55 changes: 55 additions & 0 deletions src/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 //
Expand Down Expand Up @@ -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. //
Expand Down
24 changes: 18 additions & 6 deletions src/extension/Daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,25 +591,37 @@ 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');

// Show the settings dialog.
Main.extensionManager.openExtensionPrefs(this._metadata.uuid, '');
});

source.showNotification(n);
if (source.addNotification) {
source.addNotification(notification);
} else {
source.showNotification(notification);
}
}
}
};

0 comments on commit 4a08c44

Please sign in to comment.