extensionSystem: Add canChange property to extensions
Whether or not an extension can be enabled/disabled depends on various factors: Whether the extension is in error state, whether user extensions are disabled and whether the underlying GSettings keys are writable. This is complex enough to share the logic, so add it to the extension properties that are exposed over D-Bus. https://bugzilla.gnome.org/show_bug.cgi?id=789852
This commit is contained in:
parent
32e0b895a4
commit
4a3476266f
@ -30,7 +30,7 @@ var ExtensionState = {
|
|||||||
UNINSTALLED: 99
|
UNINSTALLED: 99
|
||||||
};
|
};
|
||||||
|
|
||||||
const SERIALIZED_PROPERTIES = ['type', 'state', 'path', 'error', 'hasPrefs'];
|
const SERIALIZED_PROPERTIES = ['type', 'state', 'path', 'error', 'hasPrefs', 'canChange'];
|
||||||
|
|
||||||
// Maps uuid -> metadata object
|
// Maps uuid -> metadata object
|
||||||
var extensions = {};
|
var extensions = {};
|
||||||
@ -219,6 +219,7 @@ function createExtensionObject(uuid, dir, type) {
|
|||||||
extension.path = dir.get_path();
|
extension.path = dir.get_path();
|
||||||
extension.error = '';
|
extension.error = '';
|
||||||
extension.hasPrefs = dir.get_child('prefs.js').query_exists(null);
|
extension.hasPrefs = dir.get_child('prefs.js').query_exists(null);
|
||||||
|
extension.canChange = false;
|
||||||
|
|
||||||
extensions[uuid] = extension;
|
extensions[uuid] = extension;
|
||||||
|
|
||||||
|
@ -189,6 +189,7 @@ var ExtensionManager = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._updateCanChange(extension);
|
||||||
this.emit('extension-state-changed', extension);
|
this.emit('extension-state-changed', extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,12 +268,28 @@ var ExtensionManager = class {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
_getEnabledExtensions() {
|
_getModeExtensions() {
|
||||||
let extensions;
|
|
||||||
if (Array.isArray(Main.sessionMode.enabledExtensions))
|
if (Array.isArray(Main.sessionMode.enabledExtensions))
|
||||||
extensions = Main.sessionMode.enabledExtensions;
|
return Main.sessionMode.enabledExtensions;
|
||||||
else
|
return [];
|
||||||
extensions = [];
|
}
|
||||||
|
|
||||||
|
_updateCanChange(extension) {
|
||||||
|
let hasError =
|
||||||
|
extension.state == ExtensionState.ERROR ||
|
||||||
|
extension.state == ExtensionState.OUT_OF_DATE;
|
||||||
|
|
||||||
|
let isMode = this._getModeExtensions().includes(extension.uuid);
|
||||||
|
let modeOnly = global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY);
|
||||||
|
|
||||||
|
extension.canChange =
|
||||||
|
!hasError &&
|
||||||
|
global.settings.is_writable(ENABLED_EXTENSIONS_KEY) &&
|
||||||
|
(isMode || !modeOnly);
|
||||||
|
}
|
||||||
|
|
||||||
|
_getEnabledExtensions() {
|
||||||
|
let extensions = this._getModeExtensions();
|
||||||
|
|
||||||
if (global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY))
|
if (global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY))
|
||||||
return extensions;
|
return extensions;
|
||||||
@ -280,6 +297,11 @@ var ExtensionManager = class {
|
|||||||
return extensions.concat(global.settings.get_strv(ENABLED_EXTENSIONS_KEY));
|
return extensions.concat(global.settings.get_strv(ENABLED_EXTENSIONS_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onUserExtensionsEnabledChanged() {
|
||||||
|
this._onEnabledExtensionsChanged();
|
||||||
|
this._onSettingsWritableChanged();
|
||||||
|
}
|
||||||
|
|
||||||
_onEnabledExtensionsChanged() {
|
_onEnabledExtensionsChanged() {
|
||||||
let newEnabledExtensions = this._getEnabledExtensions();
|
let newEnabledExtensions = this._getEnabledExtensions();
|
||||||
|
|
||||||
@ -305,6 +327,14 @@ var ExtensionManager = class {
|
|||||||
this._enabledExtensions = newEnabledExtensions;
|
this._enabledExtensions = newEnabledExtensions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onSettingsWritableChanged() {
|
||||||
|
for (let uuid in ExtensionUtils.extensions) {
|
||||||
|
let extension = ExtensionUtils.extensions[uuid];
|
||||||
|
this._updateCanChange(extension);
|
||||||
|
this.emit('extension-state-changed', extension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_onVersionValidationChanged() {
|
_onVersionValidationChanged() {
|
||||||
// we want to reload all extensions, but only enable
|
// we want to reload all extensions, but only enable
|
||||||
// extensions when allowed by the sessionMode, so
|
// extensions when allowed by the sessionMode, so
|
||||||
@ -325,9 +355,11 @@ var ExtensionManager = class {
|
|||||||
global.settings.connect(`changed::${ENABLED_EXTENSIONS_KEY}`,
|
global.settings.connect(`changed::${ENABLED_EXTENSIONS_KEY}`,
|
||||||
this._onEnabledExtensionsChanged.bind(this));
|
this._onEnabledExtensionsChanged.bind(this));
|
||||||
global.settings.connect(`changed::${DISABLE_USER_EXTENSIONS_KEY}`,
|
global.settings.connect(`changed::${DISABLE_USER_EXTENSIONS_KEY}`,
|
||||||
this._onEnabledExtensionsChanged.bind(this));
|
this._onUserExtensionsEnabledChanged.bind(this));
|
||||||
global.settings.connect(`changed::${EXTENSION_DISABLE_VERSION_CHECK_KEY}`,
|
global.settings.connect(`changed::${EXTENSION_DISABLE_VERSION_CHECK_KEY}`,
|
||||||
this._onVersionValidationChanged.bind(this));
|
this._onVersionValidationChanged.bind(this));
|
||||||
|
global.settings.connect(`writable-changed::${ENABLED_EXTENSIONS_KEY}`,
|
||||||
|
this._onSettingsWritableChanged.bind(this));
|
||||||
|
|
||||||
this._enabledExtensions = this._getEnabledExtensions();
|
this._enabledExtensions = this._getEnabledExtensions();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user