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
This commit is contained in:
parent
43cb3754d9
commit
ce1bee727a
@ -21,6 +21,17 @@
|
||||
EnableExtension and DisableExtension D-Bus methods on org.gnome.Shell.
|
||||
</description>
|
||||
</key>
|
||||
<key name="disabled-extensions" type="as">
|
||||
<default>[]</default>
|
||||
<summary>UUIDs of extensions to force disabling</summary>
|
||||
<description>
|
||||
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.
|
||||
</description>
|
||||
</key>
|
||||
<key name="disable-user-extensions" type="b">
|
||||
<default>false</default>
|
||||
<summary>Disable user extensions</summary>
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user