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:
parent
637ee7386e
commit
0c68c33826
@ -146,25 +146,31 @@ var LoginManagerSystemd = class extends Signals.EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async canSuspend() {
|
async canSuspend() {
|
||||||
|
let canSuspend, needsAuth;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [result] = await this._proxy.CanSuspendAsync();
|
const [result] = await this._proxy.CanSuspendAsync();
|
||||||
const needsAuth = result === 'challenge';
|
needsAuth = result === 'challenge';
|
||||||
const canSuspend = needsAuth || result === 'yes';
|
canSuspend = needsAuth || result === 'yes';
|
||||||
return [canSuspend, needsAuth];
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return [false, false];
|
canSuspend = false;
|
||||||
|
needsAuth = false;
|
||||||
}
|
}
|
||||||
|
return {canSuspend, needsAuth};
|
||||||
}
|
}
|
||||||
|
|
||||||
async canRebootToBootLoaderMenu() {
|
async canRebootToBootLoaderMenu() {
|
||||||
|
let canRebootToBootLoaderMenu, needsAuth;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [result] = await this._proxy.CanRebootToBootLoaderMenuAsync();
|
const [result] = await this._proxy.CanRebootToBootLoaderMenuAsync();
|
||||||
const needsAuth = result[0] === 'challenge';
|
needsAuth = result[0] === 'challenge';
|
||||||
const canRebootToBootLoaderMenu = needsAuth || result[0] === 'yes';
|
canRebootToBootLoaderMenu = needsAuth || result[0] === 'yes';
|
||||||
return [canRebootToBootLoaderMenu, needsAuth];
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return [false, false];
|
canRebootToBootLoaderMenu = false;
|
||||||
|
needsAuth = false;
|
||||||
}
|
}
|
||||||
|
return {canRebootToBootLoaderMenu, needsAuth};
|
||||||
}
|
}
|
||||||
|
|
||||||
setRebootToBootLoaderMenu() {
|
setRebootToBootLoaderMenu() {
|
||||||
@ -209,11 +215,17 @@ var LoginManagerDummy = class extends Signals.EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canSuspend() {
|
canSuspend() {
|
||||||
return new Promise(resolve => resolve([false, false]));
|
return new Promise(resolve => resolve({
|
||||||
|
canSuspend: false,
|
||||||
|
needsAuth: false,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
canRebootToBootLoaderMenu() {
|
canRebootToBootLoaderMenu() {
|
||||||
return new Promise(resolve => resolve([false, false]));
|
return new Promise(resolve => resolve({
|
||||||
|
canRebootToBootLoaderMenu: false,
|
||||||
|
needsAuth: false,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
setRebootToBootLoaderMenu() {
|
setRebootToBootLoaderMenu() {
|
||||||
|
@ -351,7 +351,7 @@ const SystemActions = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _updateHaveSuspend() {
|
async _updateHaveSuspend() {
|
||||||
const [canSuspend, needsAuth] = await this._loginManager.canSuspend();
|
const {canSuspend, needsAuth} = await this._loginManager.canSuspend();
|
||||||
this._canHaveSuspend = canSuspend;
|
this._canHaveSuspend = canSuspend;
|
||||||
this._suspendNeedsAuth = needsAuth;
|
this._suspendNeedsAuth = needsAuth;
|
||||||
this._updateSuspend();
|
this._updateSuspend();
|
||||||
|
@ -305,7 +305,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _getCanRebootToBootLoaderMenu() {
|
async _getCanRebootToBootLoaderMenu() {
|
||||||
const [canRebootToBootLoaderMenu] = await this._loginManager.canRebootToBootLoaderMenu();
|
const {canRebootToBootLoaderMenu} = await this._loginManager.canRebootToBootLoaderMenu();
|
||||||
this._canRebootToBootLoaderMenu = canRebootToBootLoaderMenu;
|
this._canRebootToBootLoaderMenu = canRebootToBootLoaderMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user