extensionSystem: Add 'enabled' property

Unlike `state` which represents the actual state, the new property
reflects the desired state, i.e. whether an extension should be
enabled according to the settings.

The Extension app will soon use it to improve its handling of the
case where the two mismatch (e.g. extension errors).

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7004

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3073>
This commit is contained in:
Florian Müllner 2023-09-12 14:11:55 +02:00 committed by Marge Bot
parent e6624f8ba1
commit 02b19e3b5c
2 changed files with 9 additions and 0 deletions

View File

@ -30,6 +30,7 @@ export const ExtensionState = {
const SERIALIZED_PROPERTIES = [
'type',
'state',
'enabled',
'path',
'error',
'hasPrefs',

View File

@ -429,6 +429,7 @@ export class ExtensionManager extends Signals.EventEmitter {
path: dir.get_path(),
error: '',
hasPrefs: dir.get_child('prefs.js').query_exists(null),
enabled: this._enabledExtensions.includes(uuid),
hasUpdate: false,
canChange: false,
sessionModes: meta['session-modes'] ? meta['session-modes'] : ['user'],
@ -609,6 +610,13 @@ export class ExtensionManager extends Signals.EventEmitter {
async _onEnabledExtensionsChanged() {
let newEnabledExtensions = this._getEnabledExtensions();
for (const extension of this._extensions.values()) {
const wasEnabled = extension.enabled;
extension.enabled = newEnabledExtensions.includes(extension.uuid);
if (wasEnabled !== extension.enabled)
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.
const extensionsToEnable = newEnabledExtensions