From 1c98a95974ae924bb93617d4badccbbb5bc0c900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Sun, 16 Jul 2023 14:40:08 +0200 Subject: [PATCH] extensionSystem: Include dir and path in data passed to extension Extensions often need to set up additional resources from their directory, like settings, translations or image assets. So far extensions have used getCurrentExtension() to access the shell's internal extension object which contains path and dir properties. That's far from ideal, first because it requires generating a stack to figure out the current extension, and second because the internal object also contains state that extensions shouldn't meddle with. Just include those properties in the metadata we pass to the extension constructor. Part-of: --- js/ui/extensionSystem.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index abe98b574..d2f608f4c 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -536,7 +536,9 @@ var ExtensionManager = class extends Signals.EventEmitter { } try { - extensionState = new extensionModule.default(extension.metadata); + const {metadata, path} = extension; + extensionState = + new extensionModule.default({...metadata, dir, path}); } catch (e) { this.logExtensionError(uuid, e); return false;