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
This commit is contained in:
Benjamin Berg 2019-08-01 16:32:57 +02:00
parent 44cd1ae25b
commit afefc88e02
2 changed files with 26 additions and 2 deletions

View File

@ -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:

View File

@ -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();