[gnome-shell/wip/rstrode/login-screen-extensions: 60/62] extensionSystem: Allow extensions to run on the login screen




commit 5a3020c34e0cfc443d62395652594022f732485c
Author: Ray Strode <rstrode redhat com>
Date:   Sat Aug 28 13:54:39 2021 -0400

    extensionSystem: Allow extensions to run on the login screen
    
    At the moment it's not realy possible to extend the login screen to do
    things it doesn't have built-in support for. This means in order
    to support niche use cases, those cases have to change the main
    code base. For instance, oVirt and Vmware deployments want to be able
    to automaticaly log in guest VMs when a user pre-authenticates through a
    console on a management host. To support those use cases, we added
    code to the login screen directly, even though most machines will never
    be associated with oVirt or Vmware management hosts.
    
    We also get requests from e.g. government users that need certain features
    at the login screen that wouldn't get used much outside of government
    deployments. For instance, we've gotten requests that a machine contains
    prominently displays that it has "Top Secret" information.
    
    All of these use cases seem like they would better handled via
    extensions that could be installed in the specific deployments. The
    problem is extensions only run in the user session, and get
    disabled at the login screen automatically.
    
    This commit changes that. Now extensions can specify in their metadata
    via a new sessionModes property, which modes that want to run in. For
    backward compatibility, if an extension doesn't specify which session
    modes it works in, its assumed the extension only works in the user
    session.

 js/ui/extensionSystem.js | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)
---
diff --git a/js/ui/extensionSystem.js b/js/ui/extensionSystem.js
index cc61cab403..f116db3933 100644
--- a/js/ui/extensionSystem.js
+++ b/js/ui/extensionSystem.js
@@ -74,6 +74,31 @@ var ExtensionManager = class {
         return [...this._extensions.keys()];
     }
 
+    _extensionSupportsSessionMode(uuid) {
+        let extension = this.lookup(uuid);
+
+        if (!extension)
+            return false;
+
+        if (extension.sessionModes.includes(Main.sessionMode.currentMode))
+            return true;
+
+        if (extension.sessionModes.includes(Main.sessionMode.parentMode))
+            return true;
+
+        return false;
+    }
+
+    _sessionModeCanUseExtension(uuid) {
+        if (!Main.sessionMode.allowExtensions)
+            return false;
+
+        if (!this._extensionSupportsSessionMode(uuid))
+            return false;
+
+        return true;
+    }
+
     _callExtensionDisable(uuid) {
         let extension = this.lookup(uuid);
         if (!extension)
@@ -133,7 +158,7 @@ var ExtensionManager = class {
     }
 
     _callExtensionEnable(uuid) {
-        if (!Main.sessionMode.allowExtensions)
+        if (!this._sessionModeCanUseExtension(uuid))
             return;
 
         let extension = this.lookup(uuid);
@@ -315,6 +340,7 @@ var ExtensionManager = class {
             hasPrefs: dir.get_child('prefs.js').query_exists(null),
             hasUpdate: false,
             canChange: false,
+            sessionModes: meta['session-modes'] ? meta['session-modes'] : [ 'user' ],
         };
         this._extensions.set(uuid, extension);
 
@@ -399,7 +425,7 @@ var ExtensionManager = class {
     }
 
     _callExtensionInit(uuid) {
-        if (!Main.sessionMode.allowExtensions)
+        if (!this._sessionModeCanUseExtension(uuid))
             return false;
 
         let extension = this.lookup(uuid);
@@ -488,13 +514,15 @@ var ExtensionManager = class {
         // Find and enable all the newly enabled extensions: UUIDs found in the
         // new setting, but not in the old one.
         newEnabledExtensions
-            .filter(uuid => !this._enabledExtensions.includes(uuid))
+            .filter(uuid => !this._enabledExtensions.includes(uuid) &&
+                             this._extensionSupportsSessionMode(uuid))
             .forEach(uuid => this._callExtensionEnable(uuid));
 
         // Find and disable all the newly disabled extensions: UUIDs found in the
         // old setting, but not in the new one.
         this._extensionOrder
-            .filter(uuid => !newEnabledExtensions.includes(uuid))
+            .filter(uuid => !newEnabledExtensions.includes(uuid) ||
+                            !this._extensionSupportsSessionMode(uuid))
             .reverse().forEach(uuid => this._callExtensionDisable(uuid));
 
         this._enabledExtensions = newEnabledExtensions;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]