From 1cc20ca6b67d1b211d5c3ec78e6981a9ad7adee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 16 Feb 2021 03:08:38 +0100 Subject: [PATCH] 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: --- 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 16689f10e..67255bc9e 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();