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
This commit is contained in:
Jonas Dreßler 2019-06-23 16:32:29 +02:00 committed by Florian Müllner
parent 5c7a701a68
commit d5eafbad87

View File

@ -15,6 +15,8 @@ var DIALOG_ICON_SIZE = 48;
var WORK_SPINNER_ICON_SIZE = 16; var WORK_SPINNER_ICON_SIZE = 16;
const DELAYED_RESET_TIMEOUT = 200;
var AuthenticationDialog = GObject.registerClass({ var AuthenticationDialog = GObject.registerClass({
Signals: { 'done': { param_types: [GObject.TYPE_BOOLEAN] } } Signals: { 'done': { param_types: [GObject.TYPE_BOOLEAN] } }
}, class AuthenticationDialog extends ModalDialog.ModalDialog { }, class AuthenticationDialog extends ModalDialog.ModalDialog {
@ -160,7 +162,8 @@ var AuthenticationDialog = GObject.registerClass({
} }
performAuthentication() { performAuthentication() {
this._destroySession(); this._destroySession(DELAYED_RESET_TIMEOUT);
this._session = new PolkitAgent.Session({ identity: this._identityToAuth, this._session = new PolkitAgent.Session({ identity: this._identityToAuth,
cookie: this._cookie }); cookie: this._cookie });
this._sessionCompletedId = this._session.connect('completed', this._onSessionCompleted.bind(this)); this._sessionCompletedId = this._session.connect('completed', this._onSessionCompleted.bind(this));
@ -253,6 +256,11 @@ var AuthenticationDialog = GObject.registerClass({
} }
_onSessionRequest(session, request, echoOn) { _onSessionRequest(session, request, echoOn) {
if (this._sessionRequestTimeoutId) {
GLib.source_remove(this._sessionRequestTimeoutId);
this._sessionRequestTimeoutId = 0;
}
// Cheap localization trick // Cheap localization trick
if (request == 'Password:' || request == 'Password: ') if (request == 'Password:' || request == 'Password: ')
this._passwordLabel.set_text(_("Password:")); this._passwordLabel.set_text(_("Password:"));
@ -292,7 +300,7 @@ var AuthenticationDialog = GObject.registerClass({
this._ensureOpen(); this._ensureOpen();
} }
_destroySession() { _destroySession(delay = 0) {
if (this._session) { if (this._session) {
if (!this._completed) if (!this._completed)
this._session.cancel(); this._session.cancel();
@ -305,9 +313,23 @@ var AuthenticationDialog = GObject.registerClass({
this._session = null; this._session = null;
} }
this._passwordBox.hide(); if (this._sessionRequestTimeoutId) {
this._cancelButton.grab_key_focus(); GLib.source_remove(this._sessionRequestTimeoutId);
this._okButton.reactive = false; 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() { _onUserChanged() {
@ -332,7 +354,10 @@ var AuthenticationDialog = GObject.registerClass({
_onDialogClosed() { _onDialogClosed() {
if (this._sessionUpdatedId) if (this._sessionUpdatedId)
Main.sessionMode.disconnect(this._sessionUpdatedId); Main.sessionMode.disconnect(this._sessionUpdatedId);
this._sessionUpdatedId = 0;
if (this._sessionRequestTimeoutId)
GLib.source_remove(this._sessionRequestTimeoutId);
this._sessionRequestTimeoutId = 0;
if (this._user) { if (this._user) {
this._user.disconnect(this._userLoadedId); this._user.disconnect(this._userLoadedId);