From 82237a398f2d019f7992a911f6f214abc9c3f8c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Mon, 10 Jul 2023 10:33:31 +0200 Subject: [PATCH] extensions: Add static lookupByUUID() method This allows the Extension/Preferences classes to provide the UUID -> extension lookup without exposing the underlying extension manager. Part-of: --- js/extensions/extension.js | 4 ++++ js/extensions/prefs.js | 4 ++++ js/extensions/sharedInternals.js | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/js/extensions/extension.js b/js/extensions/extension.js index bcc518edd..cdbc33da7 100644 --- a/js/extensions/extension.js +++ b/js/extensions/extension.js @@ -4,6 +4,10 @@ const {extensionManager} = imports.ui.main; setExtensionManager(extensionManager); export class Extension extends ExtensionBase { + static lookupByUUID(uuid) { + return extensionManager.lookup(uuid)?.stateObj ?? null; + } + static defineTranslationFunctions(url) { const wrapper = new GettextWrapper(this, url); return wrapper.defineTranslationFunctions(); diff --git a/js/extensions/prefs.js b/js/extensions/prefs.js index 5d2de3f98..ab0a74dd2 100644 --- a/js/extensions/prefs.js +++ b/js/extensions/prefs.js @@ -6,6 +6,10 @@ import {extensionManager} from '../extensionsService.js'; setExtensionManager(extensionManager); export class ExtensionPreferences extends ExtensionBase { + static lookupByUUID(uuid) { + return extensionManager.lookup(uuid)?.stateObj ?? null; + } + static defineTranslationFunctions(url) { const wrapper = new GettextWrapper(this, url); return wrapper.defineTranslationFunctions(); diff --git a/js/extensions/sharedInternals.js b/js/extensions/sharedInternals.js index dcac3c233..ac6d035a8 100644 --- a/js/extensions/sharedInternals.js +++ b/js/extensions/sharedInternals.js @@ -1,5 +1,6 @@ import Gio from 'gi://Gio'; import GLib from 'gi://GLib'; +import GObject from 'gi://GObject'; import {bindtextdomain} from 'gettext'; @@ -38,14 +39,23 @@ export class ExtensionBase { path = GLib.path_get_dirname(path); const dirName = GLib.path_get_basename(path); - const extension = _extensionManager.lookup(dirName); + const extension = this.lookupByUUID(dirName); if (extension !== undefined) - return extension.stateObj; + return extension; } while (path !== '/'); return null; } + /** + * Look up an extension by UUID + * + * @param {string} _uuid + */ + static lookupByUUID(_uuid) { + throw new GObject.NotImplementedError(); + } + /** * @param {object} metadata - metadata passed in when loading the extension */