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: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2832>
This commit is contained in:
Florian Müllner 2023-07-09 12:47:05 +02:00 committed by Marge Bot
parent cdd19a7773
commit 10672597c2

View File

@ -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', () => {