From ce1bee727ae4811ff81ce109ca7d44a95c2e9d06 Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Wed, 17 Jan 2018 13:43:11 +0100 Subject: [PATCH] extensionSystem: Allow disabling session mode extensions Trying to disable an extension that is enabled by the session mode currently has no effect, which is clearly confusing. We could update the various extension UIs to reflect that via sensitivity, but being unable to configure extensions based on which session the user picked at login isn't obvious either. So instead, add a 'disabled-extensions' gsettings key to list extensions that should not be enabled which takes precedence over 'enabled-extensions' and can be used to disable session mode extensions. https://bugzilla.gnome.org/show_bug.cgi?id=789852 --- data/org.gnome.shell.gschema.xml.in | 11 ++++++++++ js/ui/extensionSystem.js | 33 +++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/data/org.gnome.shell.gschema.xml.in b/data/org.gnome.shell.gschema.xml.in index 5a065593b..4aca92162 100644 --- a/data/org.gnome.shell.gschema.xml.in +++ b/data/org.gnome.shell.gschema.xml.in @@ -21,6 +21,17 @@ EnableExtension and DisableExtension D-Bus methods on org.gnome.Shell. + + [] + UUIDs of extensions to force disabling + + GNOME Shell extensions have a UUID property; this key lists extensions + which should be disabled, even if loaded as part of the current mode. + You can also manipulate this list with the EnableExtension and + DisableExtension D-Bus methods on org.gnome.Shell. + This key takes precedence over the “enabled-extensions” setting. + + false Disable user extensions diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index 1efb3f048..2099d709d 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -10,6 +10,7 @@ const Main = imports.ui.main; const { ExtensionState, ExtensionType } = ExtensionUtils; const ENABLED_EXTENSIONS_KEY = 'enabled-extensions'; +const DISABLED_EXTENSIONS_KEY = 'disabled-extensions'; const DISABLE_USER_EXTENSIONS_KEY = 'disable-user-extensions'; const EXTENSION_DISABLE_VERSION_CHECK_KEY = 'disable-extension-version-validation'; @@ -144,6 +145,13 @@ var ExtensionManager = class { return false; let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY); + let disabledExtensions = global.settings.get_strv(DISABLED_EXTENSIONS_KEY); + + if (disabledExtensions.includes(uuid)) { + disabledExtensions = disabledExtensions.filter(item => item !== uuid); + global.settings.set_strv(DISABLED_EXTENSIONS_KEY, disabledExtensions); + } + if (!enabledExtensions.includes(uuid)) { enabledExtensions.push(uuid); global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions); @@ -157,11 +165,18 @@ var ExtensionManager = class { return false; let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY); + let disabledExtensions = global.settings.get_strv(DISABLED_EXTENSIONS_KEY); + if (enabledExtensions.includes(uuid)) { enabledExtensions = enabledExtensions.filter(item => item !== uuid); global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions); } + if (!disabledExtensions.includes(uuid)) { + disabledExtensions.push(uuid); + global.settings.set_strv(DISABLED_EXTENSIONS_KEY, disabledExtensions); + } + return true; } @@ -343,19 +358,25 @@ var ExtensionManager = class { let isMode = this._getModeExtensions().includes(extension.uuid); let modeOnly = global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY); + let changeKey = isMode + ? DISABLE_USER_EXTENSIONS_KEY + : ENABLED_EXTENSIONS_KEY; + extension.canChange = !hasError && - global.settings.is_writable(ENABLED_EXTENSIONS_KEY) && + global.settings.is_writable(changeKey) && (isMode || !modeOnly); } _getEnabledExtensions() { let extensions = this._getModeExtensions(); - if (global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY)) - return extensions; + if (!global.settings.get_boolean(DISABLE_USER_EXTENSIONS_KEY)) + extensions = extensions.concat(global.settings.get_strv(ENABLED_EXTENSIONS_KEY)); - return extensions.concat(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() { @@ -417,12 +438,16 @@ var ExtensionManager = class { _loadExtensions() { global.settings.connect(`changed::${ENABLED_EXTENSIONS_KEY}`, this._onEnabledExtensionsChanged.bind(this)); + global.settings.connect(`changed::${DISABLED_EXTENSIONS_KEY}`, + this._onEnabledExtensionsChanged.bind(this)); global.settings.connect(`changed::${DISABLE_USER_EXTENSIONS_KEY}`, this._onUserExtensionsEnabledChanged.bind(this)); global.settings.connect(`changed::${EXTENSION_DISABLE_VERSION_CHECK_KEY}`, this._onVersionValidationChanged.bind(this)); global.settings.connect(`writable-changed::${ENABLED_EXTENSIONS_KEY}`, this._onSettingsWritableChanged.bind(this)); + global.settings.connect(`writable-changed::${DISABLED_EXTENSIONS_KEY}`, + this._onSettingsWritableChanged.bind(this)); this._enabledExtensions = this._getEnabledExtensions();