Skip to content

Commit 712f61a

Browse files
committed
🔀 Merge branch 'main' into fix/menu-layout
2 parents 2ea6059 + 4a08c44 commit 712f61a

File tree

3 files changed

+74
-6
lines changed

3 files changed

+74
-6
lines changed

docs/changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SPDX-License-Identifier: CC-BY-4.0
2121

2222
- Fixed selecting items on GNOME 46 requiring two clicks.
2323
- Fixed an issue which allowed the settings dialog to be resized below its minimal size.
24+
- Fixed a bug which caused achievement notifications to be not shown on GNOME 46.
2425

2526
## [Fly-Pie 25](https://github.com/schneegans/fly-pie/releases/tag/v25)
2627

src/common/utils.js

+55
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,50 @@ import PangoCairo from 'gi://PangoCairo';
2525
const St = await importInShellOnly('gi://St');
2626
const Gtk = await importInPrefsOnly('gi://Gtk');
2727

28+
// We import the Config module. This is done differently in the GNOME Shell process and in
29+
// the preferences process.
30+
const Config = await importConfig();
31+
32+
//////////////////////////////////////////////////////////////////////////////////////////
33+
// Two methods for checking the current version of GNOME Shell. //
34+
//////////////////////////////////////////////////////////////////////////////////////////
35+
36+
// Returns the given argument, except for "alpha", "beta", and "rc". In these cases -3,
37+
// -2, and -1 are returned respectively.
38+
function toNumericVersion(x) {
39+
switch (x) {
40+
case 'alpha':
41+
return -3;
42+
case 'beta':
43+
return -2;
44+
case 'rc':
45+
return -1;
46+
}
47+
return x;
48+
}
49+
50+
const [GS_MAJOR, GS_MINOR] = Config.PACKAGE_VERSION.split('.').map(toNumericVersion);
51+
52+
// This method returns true if the current GNOME Shell version matches the given
53+
// arguments.
54+
export function shellVersionIs(major, minor) {
55+
return GS_MAJOR == major && GS_MINOR == toNumericVersion(minor);
56+
}
57+
58+
// This method returns true if the current GNOME Shell version is at least as high as the
59+
// given arguments. Supports "alpha" and "beta" for the minor version number.
60+
export function shellVersionIsAtLeast(major, minor = 0) {
61+
if (GS_MAJOR > major) {
62+
return true;
63+
}
64+
65+
if (GS_MAJOR == major) {
66+
return GS_MINOR >= toNumericVersion(minor);
67+
}
68+
69+
return false;
70+
}
71+
2872
//////////////////////////////////////////////////////////////////////////////////////////
2973
// This method can be used to write a message to GNOME Shell's log. This is enhances //
3074
// the standard log() functionality by prepending the extension's name and the location //
@@ -85,6 +129,17 @@ export async function importGettext() {
85129
return (await import('resource:///org/gnome/shell/extensions/extension.js')).gettext;
86130
}
87131

132+
//////////////////////////////////////////////////////////////////////////////////////////
133+
// This method can be used to import the Config module. //
134+
//////////////////////////////////////////////////////////////////////////////////////////
135+
136+
export async function importConfig() {
137+
if (typeof global === 'undefined') {
138+
return (await import('resource:///org/gnome/Shell/Extensions/js/misc/config.js'));
139+
}
140+
return (await import('resource:///org/gnome/shell/misc/config.js'));
141+
}
142+
88143
//////////////////////////////////////////////////////////////////////////////////////////
89144
// Returns the path to the extension's directory. This is useful to load resources from //
90145
// the extension's directory. //

src/extension/Daemon.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -591,25 +591,37 @@ export default class Daemon {
591591
// of the icon seems to depend on the currently used theme and cannot be set from here.
592592
// The notification will also contain a hard-coded button which opens the achievements
593593
// page of the settings dialog.
594-
_notify(label, details, gicon) {
594+
_notify(title, body, gicon) {
595595

596596
if (this._settings.get_boolean('achievement-notifications')) {
597-
const source = new Source('Fly-Pie', '');
598-
Main.messageTray.add(source);
599597

600-
const n = new Notification(source, label, details, {gicon: gicon});
598+
let source, notification;
599+
600+
if (utils.shellVersionIsAtLeast(46)) {
601+
source = new Source({title: 'Fly-Pie'});
602+
notification = new Notification({source, title, body, gicon: gicon});
603+
} else {
604+
source = new Source('Fly-Pie', '');
605+
notification = new Notification(source, title, body, {gicon: gicon});
606+
}
607+
608+
Main.messageTray.add(source);
601609

602610
// Translators: This is shown on the action button of the notification bubble which
603611
// is shown once an achievement is unlocked.
604-
n.addAction(_('Show Achievements'), () => {
612+
notification.addAction(_('Show Achievements'), () => {
605613
// Make sure the achievements page is shown.
606614
this._settings.set_string('active-stack-child', 'achievements-page');
607615

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

612-
source.showNotification(n);
620+
if (source.addNotification) {
621+
source.addNotification(notification);
622+
} else {
623+
source.showNotification(notification);
624+
}
613625
}
614626
}
615627
};

0 commit comments

Comments
 (0)