From 56beb6ff2bc6ae1999b74f18bb61f91070628298 Mon Sep 17 00:00:00 2001 From: Evan Welsh Date: Sun, 24 Jul 2022 19:25:23 -0700 Subject: [PATCH] extensionUtils: Add DISABLING and ENABLING extension states Extensions can export asynchronous enable() and disable() functions. To guard against re-entrancy when enabling or disabling an extension, this commit adds two new states: ENABLING and DISABLING which are set immediately prior to calling enable() and disable() respectively. This commit updates the extensions CLI and Extensions app with new strings for these states. Part-of: --- .../dbus-interfaces/org.gnome.Shell.Extensions.xml | 2 ++ js/misc/extensionUtils.js | 2 ++ js/ui/extensionSystem.js | 6 ++++++ js/ui/lookingGlass.js | 14 +++++++++----- subprojects/extensions-tool/src/common.h | 2 ++ subprojects/extensions-tool/src/main.c | 4 ++++ 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/data/dbus-interfaces/org.gnome.Shell.Extensions.xml b/data/dbus-interfaces/org.gnome.Shell.Extensions.xml index 51448dce7..780aa9a4a 100644 --- a/data/dbus-interfaces/org.gnome.Shell.Extensions.xml +++ b/data/dbus-interfaces/org.gnome.Shell.Extensions.xml @@ -77,6 +77,8 @@ 4: OUT_OF_DATE 5: DOWNLOADING 6: INITIALIZED + 7: DISABLING + 8: ENABLING 99: UNINSTALLED diff --git a/js/misc/extensionUtils.js b/js/misc/extensionUtils.js index 3e89a870d..97ea66e82 100644 --- a/js/misc/extensionUtils.js +++ b/js/misc/extensionUtils.js @@ -38,6 +38,8 @@ var ExtensionState = { OUT_OF_DATE: 4, DOWNLOADING: 5, INITIALIZED: 6, + DISABLING: 7, + ENABLING: 8, // Used as an error state for operations on unknown extensions, // should never be in a real extensionMeta object. diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js index c66df59a1..5dfb325f2 100644 --- a/js/ui/extensionSystem.js +++ b/js/ui/extensionSystem.js @@ -100,6 +100,9 @@ var ExtensionManager = class extends Signals.EventEmitter { if (extension.state != ExtensionState.ENABLED) return; + extension.state = ExtensionState.DISABLING; + this.emit('extension-state-changed', extension); + // "Rebase" the extension order by disabling and then enabling extensions // in order to help prevent conflicts. @@ -164,6 +167,9 @@ var ExtensionManager = class extends Signals.EventEmitter { if (extension.state != ExtensionState.DISABLED) return; + extension.state = ExtensionState.ENABLING; + this.emit('extension-state-changed', extension); + let stylesheetNames = [`${global.session_mode}.css`, 'stylesheet.css']; let theme = St.ThemeContext.get_for_stage(global.stage).get_theme(); for (let i = 0; i < stylesheetNames.length; i++) { diff --git a/js/ui/lookingGlass.js b/js/ui/lookingGlass.js index f3af5638e..e903cc7dc 100644 --- a/js/ui/lookingGlass.js +++ b/js/ui/lookingGlass.js @@ -790,16 +790,20 @@ var Extensions = GObject.registerClass({ _stateToString(extensionState) { switch (extensionState) { case ExtensionState.ENABLED: - return _("Enabled"); + return _('Enabled'); case ExtensionState.DISABLED: case ExtensionState.INITIALIZED: - return _("Disabled"); + return _('Disabled'); case ExtensionState.ERROR: - return _("Error"); + return _('Error'); case ExtensionState.OUT_OF_DATE: - return _("Out of date"); + return _('Out of date'); case ExtensionState.DOWNLOADING: - return _("Downloading"); + return _('Downloading'); + case ExtensionState.DISABLING: + return _('Disabling'); + case ExtensionState.ENABLING: + return _('Enabling'); } return 'Unknown'; // Not translated, shouldn't appear } diff --git a/subprojects/extensions-tool/src/common.h b/subprojects/extensions-tool/src/common.h index 2b0448495..74d789e91 100644 --- a/subprojects/extensions-tool/src/common.h +++ b/subprojects/extensions-tool/src/common.h @@ -36,6 +36,8 @@ typedef enum { STATE_OUT_OF_DATE, STATE_DOWNLOADING, STATE_INITIALIZED, + STATE_DISABLING, + STATE_ENABLING, STATE_UNINSTALLED = 99 } ExtensionState; diff --git a/subprojects/extensions-tool/src/main.c b/subprojects/extensions-tool/src/main.c index 66a347626..5bf2579b7 100644 --- a/subprojects/extensions-tool/src/main.c +++ b/subprojects/extensions-tool/src/main.c @@ -43,6 +43,10 @@ extension_state_to_string (ExtensionState state) return "DOWNLOADING"; case STATE_INITIALIZED: return "INITIALIZED"; + case STATE_DISABLING: + return "DISABLING"; + case STATE_ENABLING: + return "ENABLING"; case STATE_UNINSTALLED: return "UNINSTALLED"; }