diff --git a/rollup.config.mjs b/rollup.config.mjs index b20ce004..5566bf35 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -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' }, }; @@ -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( diff --git a/src/prefs/prefs.d.ts b/src/prefs/prefs.d.ts new file mode 100644 index 00000000..bb19ecf1 --- /dev/null +++ b/src/prefs/prefs.d.ts @@ -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" instead of just "Promise" + */ + fillPreferencesWindow(window: Adw.PreferencesWindow): Promise | void; +} diff --git a/src/prefs/prefs.ts b/src/prefs/prefs.ts index 2407b8fe..55f1cd30 100644 --- a/src/prefs/prefs.ts +++ b/src/prefs/prefs.ts @@ -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 { window.add(new GeneralPage(this)); window.add(new CustomizationPage(this)); window.add(new DangerZonePage(this)); @@ -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; } } diff --git a/src/utils/compatibility.ts b/src/utils/compatibility.ts index 29d89c6c..77b4783a 100644 --- a/src/utils/compatibility.ts +++ b/src/utils/compatibility.ts @@ -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'; @@ -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 = 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 { diff --git a/tsconfig.json b/tsconfig.json index f7e9d682..af76df9d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"]