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>
This commit is contained in:
Alessandro Bono 2022-08-08 12:19:51 +02:00 committed by Marge Bot
parent e177669842
commit dd97a2589b

View File

@ -273,16 +273,13 @@ var ShellUserVerifier = class extends Signals.EventEmitter {
this._userVerifierChoiceList.call_select_choice(serviceName, key, this._cancellable, null); this._userVerifierChoiceList.call_select_choice(serviceName, key, this._cancellable, null);
} }
answerQuery(serviceName, answer) { async answerQuery(serviceName, answer) {
if (!this.hasPendingMessages) { try {
await this._handlePendingMessages();
this._userVerifier.call_answer_query(serviceName, answer, this._cancellable, null); this._userVerifier.call_answer_query(serviceName, answer, this._cancellable, null);
} else { } catch (e) {
const cancellable = this._cancellable; if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
let signalId = this.connect('no-more-messages', () => { logError(e);
this.disconnect(signalId);
if (!cancellable.is_cancelled())
this._userVerifier.call_answer_query(serviceName, answer, cancellable, null);
});
} }
} }
@ -702,7 +699,7 @@ var ShellUserVerifier = class extends Signals.EventEmitter {
(this._reauthOnly || this._failCounter < this.allowedFailures); (this._reauthOnly || this._failCounter < this.allowedFailures);
} }
_verificationFailed(serviceName, shouldRetry) { async _verificationFailed(serviceName, shouldRetry) {
if (serviceName === FINGERPRINT_SERVICE_NAME) { if (serviceName === FINGERPRINT_SERVICE_NAME) {
if (this._fingerprintFailedId) if (this._fingerprintFailedId)
GLib.source_remove(this._fingerprintFailedId); GLib.source_remove(this._fingerprintFailedId);
@ -716,34 +713,36 @@ var ShellUserVerifier = class extends Signals.EventEmitter {
const doneTrying = !shouldRetry || !this._canRetry(); const doneTrying = !shouldRetry || !this._canRetry();
if (doneTrying) {
this._disconnectSignals();
// eslint-disable-next-line no-lonely-if
if (!this.hasPendingMessages) {
this._cancelAndReset();
} else {
const cancellable = this._cancellable;
let signalId = this.connect('no-more-messages', () => {
this.disconnect(signalId);
if (!cancellable.is_cancelled())
this._cancelAndReset();
});
}
}
this.emit('verification-failed', serviceName, !doneTrying); this.emit('verification-failed', serviceName, !doneTrying);
try {
if (doneTrying) {
this._disconnectSignals();
await this._handlePendingMessages();
this._cancelAndReset();
}
if (!this.hasPendingMessages) { await this._handlePendingMessages();
this._retry(serviceName); this._retry(serviceName);
} else { } catch (e) {
const cancellable = this._cancellable; if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED))
logError(e);
}
}
_handlePendingMessages() {
if (!this.hasPendingMessage)
return Promise.resolve();
const cancellable = this._cancellable;
return new Promise((resolve, reject) => {
let signalId = this.connect('no-more-messages', () => { let signalId = this.connect('no-more-messages', () => {
this.disconnect(signalId); this.disconnect(signalId);
if (!cancellable.is_cancelled()) if (cancellable.is_cancelled())
this._retry(serviceName); reject(new GLib.Error(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED, 'Operation was cancelled'));
else
resolve();
}); });
} });
} }
_onServiceUnavailable(_client, serviceName, errorMessage) { _onServiceUnavailable(_client, serviceName, errorMessage) {