Skip to content

Commit

Permalink
fix: add a hack to the types, so that we are backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Totto16 committed Sep 26, 2024
1 parent cdc4c1d commit 6d61513
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
2 changes: 2 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const importsGeneral = {
'@girs/gnome-shell/dist/ui/modalDialog': { name: 'resource://EXT_ROOT/ui/modalDialog.js' },
'@girs/gnome-shell/dist/ui/popupMenu': { name: 'resource://EXT_ROOT/ui/popupMenu.js' },
'@girs/gnome-shell/dist/ui/panelMenu': { name: 'resource://EXT_ROOT/ui/panelMenu.js' },
'@girs/gnome-shell/dist/misc/config': { name: 'resource://EXT_ROOT/misc/config.js' },
//compatibility imports
'@girs/gnome-shell-45/dist/ui/messageTray': { name: 'resource://EXT_ROOT/ui/messageTray.js' },
};
Expand All @@ -48,6 +49,7 @@ const importsGeneral = {
const importsPrefs = {
...importsGeneral,
'@girs/gnome-shell/dist/extensions/prefs': { name: 'resource://EXT_ROOT/extensions/prefs.js' },
'@custom_types/gnome-shell/dist/extensions/prefs': { name: 'resource://EXT_ROOT/extensions/prefs.js' },
};

const ExtensionEntries = Object.fromEntries(
Expand Down
10 changes: 10 additions & 0 deletions src/prefs/prefs.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ExtensionPreferences as ExtensionPreferencesOriginal } from '@girs/gnome-shell/dist/extensions/prefs';
export { gettext, ngettext, pgettext } from '@girs/gnome-shell/dist/extensions/prefs';

export class ExtensionPreferences extends ExtensionPreferencesOriginal {
/**
* @description This is only the type, that overrides the original one, so that we have backwards compatibility
* This returns "Promise<void> | void" instead of just "Promise<void>"
*/
fillPreferencesWindow(window: Adw.PreferencesWindow): Promise<void> | void;
}
14 changes: 12 additions & 2 deletions src/prefs/prefs.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { ExtensionPreferences, gettext as _ } from '@custom_types/gnome-shell/dist/extensions/prefs';
import Adw from '@girs/adw-1';
import Gdk4 from '@girs/gdk-4.0';
import { ExtensionPreferences, gettext as _ } from '@girs/gnome-shell/dist/extensions/prefs';
import Gtk4 from '@girs/gtk-4.0';
import { CustomizationPage } from '@pano/prefs/customization';
import { DangerZonePage } from '@pano/prefs/dangerZone';
import { GeneralPage } from '@pano/prefs/general';
import { isGnome47 } from '@pano/utils/compatibility';

export default class PanoExtensionPreferences extends ExtensionPreferences {
override fillPreferencesWindow(window: Adw.PreferencesWindow) {
override fillPreferencesWindow(window: Adw.PreferencesWindow): Promise<void> | void {
window.add(new GeneralPage(this));
window.add(new CustomizationPage(this));
window.add(new DangerZonePage(this));
Expand All @@ -17,5 +18,14 @@ export default class PanoExtensionPreferences extends ExtensionPreferences {
if (display) {
Gtk4.IconTheme.get_for_display(display).add_search_path(`${this.path}/icons/`);
}

/**
* gnome 47 explicitly states, that we need to return a Promise, so we check the version at runtime and decide what to return, to support older versions of gnome shell, that don't expected a promise here
* @see https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/js/extensions/prefs.js#L34
*/
if (isGnome47()) {
return Promise.resolve();
}
return;
}
}
24 changes: 24 additions & 0 deletions src/utils/compatibility.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type Gda5 from '@girs/gda-5.0';
import type Gda6 from '@girs/gda-6.0';
import GLib from '@girs/glib-2.0';
import { PACKAGE_VERSION } from '@girs/gnome-shell/dist/misc/config';
import { Notification, Source as MessageTraySource } from '@girs/gnome-shell/dist/ui/messageTray';
import St from '@girs/st-15';

Expand Down Expand Up @@ -72,6 +73,29 @@ export function unescape_string(input: string): string {
}
}

// compatibility functions to check if a specific gnome-shell is used
export function isGnomeVersion(version: number): boolean {
const [major, _minor, _patch, ..._rest]: Array<number | undefined> = PACKAGE_VERSION.split('.').map((num) => {
const result = parseInt(num);
if (isNaN(result)) {
return undefined;
}
return result;
});

if (major === undefined) {
return PACKAGE_VERSION.includes(version.toString());
}

return major === version;
}

// compatibility functions for gnome-shell 47

export function isGnome47(): boolean {
return isGnomeVersion(47);
}

// compatibility functions for gnome-shell 45 / 46

function isGnome45Notifications(): boolean {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"moduleResolution": "Node",
"experimentalDecorators": true,
"paths": {
"@pano/*": ["./*"]
"@pano/*": ["./*"],
"@custom_types/gnome-shell/dist/extensions/prefs": ["./prefs/prefs.d.ts"]
}
},
"exclude": ["./dist", "rollup.config.mjs", "./build", "./scripts/fix-jasmine-imports.js"]
Expand Down

0 comments on commit 6d61513

Please sign in to comment.