loginManager: Return objects instead of multiple booleans

Multiple booleans - both in arguments and return values - are almost
always problematic API, because people have to memorize (or more likely
look up) the meaning of each position.

Instead, return a JS object so each value has a name attached to it.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2370>
This commit is contained in:
Florian Müllner 2022-07-08 16:23:39 +02:00
parent 637ee7386e
commit 0c68c33826
3 changed files with 24 additions and 12 deletions

View File

@ -146,25 +146,31 @@ var LoginManagerSystemd = class extends Signals.EventEmitter {
}
async canSuspend() {
let canSuspend, needsAuth;
try {
const [result] = await this._proxy.CanSuspendAsync();
const needsAuth = result === 'challenge';
const canSuspend = needsAuth || result === 'yes';
return [canSuspend, needsAuth];
needsAuth = result === 'challenge';
canSuspend = needsAuth || result === 'yes';
} catch (error) {
return [false, false];
canSuspend = false;
needsAuth = false;
}
return {canSuspend, needsAuth};
}
async canRebootToBootLoaderMenu() {
let canRebootToBootLoaderMenu, needsAuth;
try {
const [result] = await this._proxy.CanRebootToBootLoaderMenuAsync();
const needsAuth = result[0] === 'challenge';
const canRebootToBootLoaderMenu = needsAuth || result[0] === 'yes';
return [canRebootToBootLoaderMenu, needsAuth];
needsAuth = result[0] === 'challenge';
canRebootToBootLoaderMenu = needsAuth || result[0] === 'yes';
} catch (error) {
return [false, false];
canRebootToBootLoaderMenu = false;
needsAuth = false;
}
return {canRebootToBootLoaderMenu, needsAuth};
}
setRebootToBootLoaderMenu() {
@ -209,11 +215,17 @@ var LoginManagerDummy = class extends Signals.EventEmitter {
}
canSuspend() {
return new Promise(resolve => resolve([false, false]));
return new Promise(resolve => resolve({
canSuspend: false,
needsAuth: false,
}));
}
canRebootToBootLoaderMenu() {
return new Promise(resolve => resolve([false, false]));
return new Promise(resolve => resolve({
canRebootToBootLoaderMenu: false,
needsAuth: false,
}));
}
setRebootToBootLoaderMenu() {

View File

@ -351,7 +351,7 @@ const SystemActions = GObject.registerClass({
}
async _updateHaveSuspend() {
const [canSuspend, needsAuth] = await this._loginManager.canSuspend();
const {canSuspend, needsAuth} = await this._loginManager.canSuspend();
this._canHaveSuspend = canSuspend;
this._suspendNeedsAuth = needsAuth;
this._updateSuspend();

View File

@ -305,7 +305,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
}
async _getCanRebootToBootLoaderMenu() {
const [canRebootToBootLoaderMenu] = await this._loginManager.canRebootToBootLoaderMenu();
const {canRebootToBootLoaderMenu} = await this._loginManager.canRebootToBootLoaderMenu();
this._canRebootToBootLoaderMenu = canRebootToBootLoaderMenu;
}