[gnome-shell] loginManager: Return objects instead of multiple booleans



commit 0c68c338268d98a8b652d13f2bff8bc2ef577790
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Jul 8 16:23:39 2022 +0200

    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>

 js/misc/loginManager.js   | 32 ++++++++++++++++++++++----------
 js/misc/systemActions.js  |  2 +-
 js/ui/endSessionDialog.js |  2 +-
 3 files changed, 24 insertions(+), 12 deletions(-)
---
diff --git a/js/misc/loginManager.js b/js/misc/loginManager.js
index 6317b1dc4a..fb61d64cb5 100644
--- a/js/misc/loginManager.js
+++ b/js/misc/loginManager.js
@@ -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() {
diff --git a/js/misc/systemActions.js b/js/misc/systemActions.js
index 444ab4badb..c57afe5b5e 100644
--- a/js/misc/systemActions.js
+++ b/js/misc/systemActions.js
@@ -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();
diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js
index 5723a221ca..ca24d0698d 100644
--- a/js/ui/endSessionDialog.js
+++ b/js/ui/endSessionDialog.js
@@ -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;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]