From afefc88e024e906b107d1a9a4e642c8f489793e8 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Thu, 1 Aug 2019 16:32:57 +0200 Subject: [PATCH] extensionSystem: Add isRequested property for extensions The property reflects whether the extension is enabled in the setting. This does not mean that the extension is actually loaded, the API user must check the state property for this information. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/695 --- js/misc/extensionUtils.js | 2 +- js/ui/extensionSystem.js | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/js/misc/extensionUtils.js b/js/misc/extensionUtils.js index a05a88418..f3437fe93 100644 --- a/js/misc/extensionUtils.js +++ b/js/misc/extensionUtils.js @@ -31,7 +31,7 @@ var ExtensionState = { UNINSTALLED: 99 }; -const SERIALIZED_PROPERTIES = ['type', 'state', 'path', 'error', 'hasPrefs', 'canChange']; +const SERIALIZED_PROPERTIES = ['type', 'state', 'path', 'error', 'hasPrefs', 'canChange', 'isRequested']; /** * getCurrentExtension: diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index fd7196972..e9934cc5c 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -22,6 +22,7 @@ var ExtensionManager = class { this._extensions = new Map(); this._enabledExtensions = []; + this._requestedExtensions = []; this._extensionOrder = []; Main.sessionMode.connect('updated', this._sessionUpdated.bind(this)); @@ -250,6 +251,9 @@ var ExtensionManager = class { // Default to error, we set success as the last step extension.state = ExtensionState.ERROR; + let requested = this._requestedExtensions.includes(extension.uuid); + extension.isRequested = requested; + let checkVersion = !global.settings.get_boolean(EXTENSION_DISABLE_VERSION_CHECK_KEY); if (checkVersion && ExtensionUtils.isOutOfDate(extension)) { @@ -380,6 +384,14 @@ var ExtensionManager = class { return extensions.filter(item => !disabledExtensions.includes(item)); } + _getRequestedExtensions() { + let extensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY); + + // filter out 'disabled-extensions' which takes precedence + let disabledExtensions = global.settings.get_strv(DISABLED_EXTENSIONS_KEY); + return extensions.filter(item => !disabledExtensions.includes(item)); + } + _onUserExtensionsEnabledChanged() { this._onEnabledExtensionsChanged(); this._onSettingsWritableChanged(); @@ -391,6 +403,16 @@ var ExtensionManager = class { if (!this._enabled) return; + // Updated requested state and emit change notifications + this._requestedExtensions = this._getRequestedExtensions(); + for (let extension of this._extensions.values()) { + let requested = this._requestedExtensions.includes(extension.uuid); + if (extension.isRequested == requested) + continue; + extension.isRequested = requested; + this.emit('extension-state-changed', extension); + } + // Find and enable all the newly enabled extensions: UUIDs found in the // new setting, but not in the old one. newEnabledExtensions.filter( @@ -451,6 +473,7 @@ var ExtensionManager = class { this._onSettingsWritableChanged.bind(this)); this._enabledExtensions = this._getEnabledExtensions(); + this._requestedExtensions = this._getRequestedExtensions(); let perUserDir = Gio.File.new_for_path(global.userdatadir); FileUtils.collectFromDatadirs('extensions', true, (dir, info) => { @@ -512,8 +535,9 @@ var ExtensionManager = class { // property; it might make sense to make enabledExtensions independent // from allowExtensions in the future if (Main.sessionMode.allowExtensions) { - if (this._initted) + if (this._initted) { this._enabledExtensions = this._getEnabledExtensions(); + } this._enableAllExtensions(); } else { this._disableAllExtensions();