[gnome-shell/gnome-41] gdmUtil: Refactor on no-more-messages case



commit 2808fc4fc16063ef661d0263550adec2efeda362
Author: Alessandro Bono <alessandro bono369 gmail com>
Date:   Mon Aug 8 12:19:51 2022 +0200

    gdmUtil: Refactor on no-more-messages case
    
    There are few places where we want to perform an action when no more
    messages are present. Create a function that covers this use case
    and use it.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2412>
    (cherry picked from commit dd97a2589b8b686f273550f3e9e6ce370b25c10d)

 js/gdm/util.js | 59 +++++++++++++++++++++++++++++-----------------------------
 1 file changed, 29 insertions(+), 30 deletions(-)
---
diff --git a/js/gdm/util.js b/js/gdm/util.js
index 72561daab2..29dba325fc 100644
--- a/js/gdm/util.js
+++ b/js/gdm/util.js
@@ -267,16 +267,13 @@ var ShellUserVerifier = class {
         }
     }
 
-    answerQuery(serviceName, answer) {
-        if (!this.hasPendingMessages) {
+    async answerQuery(serviceName, answer) {
+        try {
+            await this._handlePendingMessages();
             this._userVerifier.call_answer_query(serviceName, answer, this._cancellable, null);
-        } else {
-            const cancellable = this._cancellable;
-            let signalId = this.connect('no-more-messages', () => {
-                this.disconnect(signalId);
-                if (!cancellable.is_cancelled())
-                    this._userVerifier.call_answer_query(serviceName, answer, cancellable, null);
-            });
+        } catch (e) {
+            if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
+                logError(e);
         }
     }
 
@@ -685,7 +682,7 @@ var ShellUserVerifier = class {
             (this._reauthOnly || this._failCounter < this.allowedFailures);
     }
 
-    _verificationFailed(serviceName, shouldRetry) {
+    async _verificationFailed(serviceName, shouldRetry) {
         if (serviceName === FINGERPRINT_SERVICE_NAME) {
             if (this._fingerprintFailedId)
                 GLib.source_remove(this._fingerprintFailedId);
@@ -699,34 +696,36 @@ var ShellUserVerifier = class {
 
         const doneTrying = !shouldRetry || !this._canRetry();
 
-        if (doneTrying) {
-            this._disconnectSignals();
-
-            // eslint-disable-next-line no-lonely-if
-            if (!this.hasPendingMessages) {
+        this.emit('verification-failed', serviceName, !doneTrying);
+        try {
+            if (doneTrying) {
+                this._disconnectSignals();
+                await this._handlePendingMessages();
                 this._cancelAndReset();
-            } else {
-                const cancellable = this._cancellable;
-                let signalId = this.connect('no-more-messages', () => {
-                    this.disconnect(signalId);
-                    if (!cancellable.is_cancelled())
-                        this._cancelAndReset();
-                });
             }
+
+            await this._handlePendingMessages();
+            this._retry(serviceName);
+        } catch (e) {
+            if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
+                logError(e);
         }
+    }
 
-        this.emit('verification-failed', serviceName, !doneTrying);
+    _handlePendingMessages() {
+        if (!this.hasPendingMessage)
+            return Promise.resolve();
 
-        if (!this.hasPendingMessages) {
-            this._retry(serviceName);
-        } else {
-            const cancellable = this._cancellable;
+        const cancellable = this._cancellable;
+        return new Promise((resolve, reject) => {
             let signalId = this.connect('no-more-messages', () => {
                 this.disconnect(signalId);
-                if (!cancellable.is_cancelled())
-                    this._retry(serviceName);
+                if (cancellable.is_cancelled())
+                    reject(new GLib.Error(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED, 'Operation was 
cancelled'));
+                else
+                    resolve();
             });
-        }
+        });
     }
 
     _onServiceUnavailable(_client, serviceName, errorMessage) {


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