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>
This commit is contained in:
Marco Trevisan (Treviño) 2021-02-16 03:08:38 +01:00 committed by Ray Strode
parent ef10bb6229
commit 1cc20ca6b6

View File

@ -49,10 +49,11 @@ var USER_READ_TIME = 48;
const FINGERPRINT_ERROR_TIMEOUT_WAIT = 15; const FINGERPRINT_ERROR_TIMEOUT_WAIT = 15;
var MessageType = { var MessageType = {
// Keep messages in order by priority
NONE: 0, NONE: 0,
ERROR: 1, HINT: 1,
INFO: 2, INFO: 2,
HINT: 3, ERROR: 3,
}; };
const FingerprintReaderType = { const FingerprintReaderType = {
@ -330,6 +331,20 @@ var ShellUserVerifier = class {
this._queueMessageTimeout(); 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() { _clearMessageQueue() {
this.finishMessageQueue(); this.finishMessageQueue();