extensionSystem: Add methods to enable/disable extensions
Extensions are currently enabled or disabled by directly changing the list in the 'enabled-extensions' GSettings key. As we will soon add an overriding 'disabled-extensions' key as well, it makes sense to offer explicit API for enabling/disabling to avoid duplicating the logic. For the corresponding D-Bus API, the methods were even mentioned in the GSettings schema, albeit unimplemented until now. https://bugzilla.gnome.org/show_bug.cgi?id=789852
This commit is contained in:
parent
6a4c55b852
commit
4589da957b
@ -173,6 +173,30 @@
|
|||||||
<arg type="s" direction="in" name="uuid"/>
|
<arg type="s" direction="in" name="uuid"/>
|
||||||
</method>
|
</method>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
EnableExtension:
|
||||||
|
@uuid: The UUID of the extension
|
||||||
|
@success: Whether the operation was successful
|
||||||
|
|
||||||
|
Enable an extension.
|
||||||
|
-->
|
||||||
|
<method name="EnableExtension"> \
|
||||||
|
<arg type="s" direction="in" name="uuid"/> \
|
||||||
|
<arg type="b" direction="out" name="success"/> \
|
||||||
|
</method> \
|
||||||
|
|
||||||
|
<!--
|
||||||
|
DisableExtension:
|
||||||
|
@uuid: The UUID of the extension
|
||||||
|
@success: Whether the operation was successful
|
||||||
|
|
||||||
|
Disable an extension.
|
||||||
|
-->
|
||||||
|
<method name="DisableExtension"> \
|
||||||
|
<arg type="s" direction="in" name="uuid"/> \
|
||||||
|
<arg type="b" direction="out" name="success"/> \
|
||||||
|
</method> \
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
LaunchExtensionPrefs:
|
LaunchExtensionPrefs:
|
||||||
@uuid: The UUID of the extension
|
@uuid: The UUID of the extension
|
||||||
|
@ -5,7 +5,6 @@ const { Clutter, Gio, GLib, GObject, Soup } = imports.gi;
|
|||||||
const Config = imports.misc.config;
|
const Config = imports.misc.config;
|
||||||
const Dialog = imports.ui.dialog;
|
const Dialog = imports.ui.dialog;
|
||||||
const ExtensionUtils = imports.misc.extensionUtils;
|
const ExtensionUtils = imports.misc.extensionUtils;
|
||||||
const ExtensionSystem = imports.ui.extensionSystem;
|
|
||||||
const FileUtils = imports.misc.fileUtils;
|
const FileUtils = imports.misc.fileUtils;
|
||||||
const Main = imports.ui.main;
|
const Main = imports.ui.main;
|
||||||
const ModalDialog = imports.ui.modalDialog;
|
const ModalDialog = imports.ui.modalDialog;
|
||||||
@ -225,16 +224,11 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function callback() {
|
function callback() {
|
||||||
// Add extension to 'enabled-extensions' for the user, always...
|
|
||||||
let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY);
|
|
||||||
if (!enabledExtensions.includes(uuid)) {
|
|
||||||
enabledExtensions.push(uuid);
|
|
||||||
global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let extension = ExtensionUtils.createExtensionObject(uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
|
let extension = ExtensionUtils.createExtensionObject(uuid, dir, ExtensionUtils.ExtensionType.PER_USER);
|
||||||
Main.extensionManager.loadExtension(extension);
|
Main.extensionManager.loadExtension(extension);
|
||||||
|
if (!Main.extensionManager.enableExtension(uuid))
|
||||||
|
throw new Error(`Cannot add ${uuid} to enabled extensions gsettings key`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
uninstallExtension(uuid);
|
uninstallExtension(uuid);
|
||||||
errback('LoadExtensionError', e);
|
errback('LoadExtensionError', e);
|
||||||
|
@ -126,6 +126,32 @@ var ExtensionManager = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enableExtension(uuid) {
|
||||||
|
if (!ExtensionUtils.extensions[uuid])
|
||||||
|
return false;
|
||||||
|
|
||||||
|
let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
|
||||||
|
if (!enabledExtensions.includes(uuid)) {
|
||||||
|
enabledExtensions.push(uuid);
|
||||||
|
global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
disableExtension(uuid) {
|
||||||
|
if (!ExtensionUtils.extensions[uuid])
|
||||||
|
return false;
|
||||||
|
|
||||||
|
let enabledExtensions = global.settings.get_strv(ENABLED_EXTENSIONS_KEY);
|
||||||
|
if (enabledExtensions.includes(uuid)) {
|
||||||
|
enabledExtensions = enabledExtensions.filter(item => item !== uuid);
|
||||||
|
global.settings.set_strv(ENABLED_EXTENSIONS_KEY, enabledExtensions);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
logExtensionError(uuid, error) {
|
logExtensionError(uuid, error) {
|
||||||
let extension = ExtensionUtils.extensions[uuid];
|
let extension = ExtensionUtils.extensions[uuid];
|
||||||
if (!extension)
|
if (!extension)
|
||||||
|
@ -320,6 +320,14 @@ var GnomeShellExtensions = class {
|
|||||||
return ExtensionDownloader.uninstallExtension(uuid);
|
return ExtensionDownloader.uninstallExtension(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EnableExtension(uuid) {
|
||||||
|
return Main.extensionManager.enableExtension(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
DisableExtension(uuid) {
|
||||||
|
return Main.extensionManager.disableExtension(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
LaunchExtensionPrefs(uuid) {
|
LaunchExtensionPrefs(uuid) {
|
||||||
let appSys = Shell.AppSystem.get_default();
|
let appSys = Shell.AppSystem.get_default();
|
||||||
let app = appSys.lookup_app('gnome-shell-extension-prefs.desktop');
|
let app = appSys.lookup_app('gnome-shell-extension-prefs.desktop');
|
||||||
|
Loading…
Reference in New Issue
Block a user