[gnome-shell] gdm: Add ability to queue a message overriding ones with less priority



commit 1cc20ca6b67d1b211d5c3ec78e6981a9ad7adee9
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date:   Tue Feb 16 03:08:38 2021 +0100

    gdm: Add ability to queue a message overriding ones with less priority
    
    There are cases in which a service may want to override a message with
    one coming with higher priority, for example an info or hint message
    isn't useful anymore if we've already got an error message.
    
    In the same way when a service has been stopped we don't care anymore
    showing its info or hint messages, while it still may be relevant to show
    errors.
    
    An example is the fingerprint service that may emit errors quickly while
    the hints messages should not be kept around when an error is already
    queued or when the service has been stopped.
    
    So, add function that allows to override queued messages based by their
    type that follows this policy:
     - Messages coming from different services are always preserved in
       their original order.
     - Messages (from the same service) with a priority equal or higher than
       the last queued one are preserved.
     - Messages matching completely the last queued are dropped in favor of
       this one.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1683>

 js/gdm/util.js | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/js/gdm/util.js b/js/gdm/util.js
index 16689f10e6..67255bc9e2 100644
--- a/js/gdm/util.js
+++ b/js/gdm/util.js
@@ -49,10 +49,11 @@ var USER_READ_TIME = 48;
 const FINGERPRINT_ERROR_TIMEOUT_WAIT = 15;
 
 var MessageType = {
+    // Keep messages in order by priority
     NONE: 0,
-    ERROR: 1,
+    HINT: 1,
     INFO: 2,
-    HINT: 3,
+    ERROR: 3,
 };
 
 const FingerprintReaderType = {
@@ -330,6 +331,20 @@ var ShellUserVerifier = class {
         this._queueMessageTimeout();
     }
 
+    _queuePriorityMessage(serviceName, message, messageType) {
+        const newQueue = this._messageQueue.filter(m => {
+            if (m.serviceName !== serviceName || m.type >= messageType)
+                return m.text !== message;
+            return false;
+        });
+
+        if (!newQueue.includes(this.currentMessage))
+            this._clearMessageQueue();
+
+        this._messageQueue = newQueue;
+        this._queueMessage(serviceName, message, messageType);
+    }
+
     _clearMessageQueue() {
         this.finishMessageQueue();
 


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