[gnome-shell/wip/rstrode/login-screen-extensions: 38/134] extensionSystem: Add methods to enable/disable extensions
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/rstrode/login-screen-extensions: 38/134] extensionSystem: Add methods to enable/disable extensions
- Date: Thu, 26 Aug 2021 19:30:58 +0000 (UTC)
commit e3dc52e0d5c99057dc14c4c975f87ad6d68b2f84
Author: Didier Roche <didrocks ubuntu com>
Date: Wed Jan 17 13:43:11 2018 +0100
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
.../dbus-interfaces/org.gnome.Shell.Extensions.xml | 24 ++++++++++++++++++++
js/ui/extensionDownloader.js | 12 ++--------
js/ui/extensionSystem.js | 26 ++++++++++++++++++++++
js/ui/shellDBus.js | 8 +++++++
4 files changed, 60 insertions(+), 10 deletions(-)
---
diff --git a/data/dbus-interfaces/org.gnome.Shell.Extensions.xml
b/data/dbus-interfaces/org.gnome.Shell.Extensions.xml
index ce69439fcf..22273f889e 100644
--- a/data/dbus-interfaces/org.gnome.Shell.Extensions.xml
+++ b/data/dbus-interfaces/org.gnome.Shell.Extensions.xml
@@ -173,6 +173,30 @@
<arg type="s" direction="in" name="uuid"/>
</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:
@uuid: The UUID of the extension
diff --git a/js/ui/extensionDownloader.js b/js/ui/extensionDownloader.js
index fe37463f26..de52edfa6d 100644
--- a/js/ui/extensionDownloader.js
+++ b/js/ui/extensionDownloader.js
@@ -4,13 +4,10 @@ const { Clutter, Gio, GLib, Soup, St } = imports.gi;
const Config = imports.misc.config;
const ExtensionUtils = imports.misc.extensionUtils;
-const ExtensionSystem = imports.ui.extensionSystem;
const FileUtils = imports.misc.fileUtils;
const Main = imports.ui.main;
const ModalDialog = imports.ui.modalDialog;
-const _signals = ExtensionSystem._signals;
-
var REPOSITORY_URL_BASE = 'https://extensions.gnome.org';
var REPOSITORY_URL_DOWNLOAD = REPOSITORY_URL_BASE + '/download-extension/%s.shell-extension.zip';
var REPOSITORY_URL_INFO = REPOSITORY_URL_BASE + '/extension-info/';
@@ -231,16 +228,11 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
}
function callback() {
- // Add extension to 'enabled-extensions' for the user, always...
- let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY);
- if (enabledExtensions.indexOf(uuid) == -1) {
- enabledExtensions.push(uuid);
- global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
- }
-
try {
let extension = ExtensionUtils.createExtensionObject(uuid, dir,
ExtensionUtils.ExtensionType.PER_USER);
Main.extensionManager.loadExtension(extension);
+ if (!Main.extensionManager.enableExtension(uuid))
+ throw new Error(`Cannot add ${uuid} to enabled extensions gsettings key`);
} catch(e) {
uninstallExtension(uuid);
errback('LoadExtensionError', e);
diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js
index c5fb007ae7..8ff0fa56fd 100644
--- a/js/ui/extensionSystem.js
+++ b/js/ui/extensionSystem.js
@@ -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) {
let extension = ExtensionUtils.extensions[uuid];
if (!extension)
diff --git a/js/ui/shellDBus.js b/js/ui/shellDBus.js
index 4b04e68ac6..0ded84874b 100644
--- a/js/ui/shellDBus.js
+++ b/js/ui/shellDBus.js
@@ -319,6 +319,14 @@ var GnomeShellExtensions = class {
return ExtensionDownloader.uninstallExtension(uuid);
}
+ EnableExtension(uuid) {
+ return Main.extensionManager.enableExtension(uuid);
+ }
+
+ DisableExtension(uuid) {
+ return Main.extensionManager.disableExtension(uuid);
+ }
+
LaunchExtensionPrefs(uuid) {
let appSys = Shell.AppSystem.get_default();
let app = appSys.lookup_app('gnome-shell-extension-prefs.desktop');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]