From d5eafbad872dea250be3747feeac82ca6a6e8ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Sun, 23 Jun 2019 16:32:29 +0200 Subject: [PATCH] polkitAgent: Use a timeout for resetting the dialog Since polkit takes a few milliseconds from initiating the session to emitting the "request" signal, don't introduce visual distraction by hiding the password entry and showing it again a few ms later. So start a timeout of 200 ms when we destroy a session and if no session request (i.e. a request for a password-authentication) happened during this timeout, hide the password entry. https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/788 --- js/ui/components/polkitAgent.js | 37 +++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/js/ui/components/polkitAgent.js b/js/ui/components/polkitAgent.js index 6367bcc8f..1a11c0b7e 100644 --- a/js/ui/components/polkitAgent.js +++ b/js/ui/components/polkitAgent.js @@ -15,6 +15,8 @@ var DIALOG_ICON_SIZE = 48; var WORK_SPINNER_ICON_SIZE = 16; +const DELAYED_RESET_TIMEOUT = 200; + var AuthenticationDialog = GObject.registerClass({ Signals: { 'done': { param_types: [GObject.TYPE_BOOLEAN] } } }, class AuthenticationDialog extends ModalDialog.ModalDialog { @@ -160,7 +162,8 @@ var AuthenticationDialog = GObject.registerClass({ } performAuthentication() { - this._destroySession(); + this._destroySession(DELAYED_RESET_TIMEOUT); + this._session = new PolkitAgent.Session({ identity: this._identityToAuth, cookie: this._cookie }); this._sessionCompletedId = this._session.connect('completed', this._onSessionCompleted.bind(this)); @@ -253,6 +256,11 @@ var AuthenticationDialog = GObject.registerClass({ } _onSessionRequest(session, request, echoOn) { + if (this._sessionRequestTimeoutId) { + GLib.source_remove(this._sessionRequestTimeoutId); + this._sessionRequestTimeoutId = 0; + } + // Cheap localization trick if (request == 'Password:' || request == 'Password: ') this._passwordLabel.set_text(_("Password:")); @@ -292,7 +300,7 @@ var AuthenticationDialog = GObject.registerClass({ this._ensureOpen(); } - _destroySession() { + _destroySession(delay = 0) { if (this._session) { if (!this._completed) this._session.cancel(); @@ -305,9 +313,23 @@ var AuthenticationDialog = GObject.registerClass({ this._session = null; } - this._passwordBox.hide(); - this._cancelButton.grab_key_focus(); - this._okButton.reactive = false; + if (this._sessionRequestTimeoutId) { + GLib.source_remove(this._sessionRequestTimeoutId); + this._sessionRequestTimeoutId = 0; + } + + let resetDialog = () => { + this._passwordBox.hide(); + this._cancelButton.grab_key_focus(); + this._okButton.reactive = false; + }; + + if (delay) { + this._sessionRequestTimeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, delay, resetDialog); + GLib.Source.set_name_by_id(this._sessionRequestTimeoutId, '[gnome-shell] this._sessionRequestTimeoutId'); + } else { + resetDialog(); + } } _onUserChanged() { @@ -332,7 +354,10 @@ var AuthenticationDialog = GObject.registerClass({ _onDialogClosed() { if (this._sessionUpdatedId) Main.sessionMode.disconnect(this._sessionUpdatedId); - this._sessionUpdatedId = 0; + + if (this._sessionRequestTimeoutId) + GLib.source_remove(this._sessionRequestTimeoutId); + this._sessionRequestTimeoutId = 0; if (this._user) { this._user.disconnect(this._userLoadedId);