From 10672597c2127a8c4bb1ebbb051273087234c066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sun, 9 Jul 2023 12:47:05 +0200 Subject: [PATCH] dbusServices/extensions: Add basic extension manager ExtensionUtils' getCurrentExtension() method currently either returns the extension that was injected with setCurrentExtension(), or imports Main locally to access the extensionManager. But local imports won't work anymore when we convert to ESM, and setCurrentExtension() is only an option for prefs. Instead of diverging the code paths even further, we'll unify the two cases as much as possible. As a first step, add a basic extension manager in the Extensions D-Bus service that exposes the same lookup() API as the "real" extension manager. Part-of: --- .../extensions/extensionsService.js | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/js/dbusServices/extensions/extensionsService.js b/js/dbusServices/extensions/extensionsService.js index 4ef58babf..4af99f8e3 100644 --- a/js/dbusServices/extensions/extensionsService.js +++ b/js/dbusServices/extensions/extensionsService.js @@ -6,12 +6,28 @@ import Shew from 'gi://Shew'; import {ExtensionPrefsDialog} from './extensionPrefsDialog.js'; import {ServiceImplementation} from './dbusService.js'; -const ExtensionUtils = imports.misc.extensionUtils; +const {deserializeExtension} = imports.misc.extensionUtils; const {loadInterfaceXML} = imports.misc.dbusUtils; const ExtensionsIface = loadInterfaceXML('org.gnome.Shell.Extensions'); const ExtensionsProxy = Gio.DBusProxy.makeProxyWrapper(ExtensionsIface); +class ExtensionManager { + #extensions = new Map(); + + createExtensionObject(serialized) { + const extension = deserializeExtension(serialized); + this.#extensions.set(extension.uuid, extension); + return extension; + } + + lookup(uuid) { + return this.#extensions.get(uuid); + } +} + +const extensionManager = new ExtensionManager(); + export const ExtensionsService = class extends ServiceImplementation { constructor() { super(ExtensionsIface, '/org/gnome/Shell/Extensions'); @@ -118,7 +134,7 @@ export const ExtensionsService = class extends ServiceImplementation { throw new Error('Already showing a prefs dialog'); const [serialized] = await this._proxy.GetExtensionInfoAsync(uuid); - const extension = ExtensionUtils.deserializeExtension(serialized); + const extension = extensionManager.createExtensionObject(serialized); this._prefsDialog = new ExtensionPrefsDialog(extension); this._prefsDialog.connect('realize', () => {