[gnome-shell] cleanup: Use optional chaining and ?? operator



commit 40e22eb524556e63efa4285c1a9d8f872a507499
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Aug 12 20:59:01 2020 +0200

    cleanup: Use optional chaining and ?? operator
    
    Those operators have been supported since gjs switched to mozjs78
    last cycle. While not ground-breaking, using it makes for a nice
    cleanup here and there.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1517>

 js/ui/altTab.js                      |  5 ++---
 js/ui/appDisplay.js                  |  2 +-
 js/ui/components/automountManager.js |  4 ++--
 js/ui/components/networkAgent.js     |  2 +-
 js/ui/endSessionDialog.js            |  3 +--
 js/ui/environment.js                 |  2 +-
 js/ui/inhibitShortcutsDialog.js      |  2 +-
 js/ui/notificationDaemon.js          |  6 +++---
 js/ui/padOsd.js                      |  4 ++--
 js/ui/panel.js                       |  4 ++--
 js/ui/panelMenu.js                   | 12 +++++++-----
 js/ui/popupMenu.js                   |  4 ++--
 js/ui/search.js                      |  2 +-
 js/ui/shellDBus.js                   | 11 ++++++-----
 js/ui/windowManager.js               |  2 +-
 js/ui/windowPreview.js               |  2 +-
 js/ui/workspace.js                   |  4 +---
 js/ui/xdndHandler.js                 |  2 +-
 18 files changed, 36 insertions(+), 37 deletions(-)
---
diff --git a/js/ui/altTab.js b/js/ui/altTab.js
index 5332d3b7c4..3ecadad868 100644
--- a/js/ui/altTab.js
+++ b/js/ui/altTab.js
@@ -427,8 +427,7 @@ class CyclerHighlight extends St.Widget {
         if (this._clone.source)
             this._clone.source.sync_visibility();
 
-        let windowActor = this._window
-            ? this._window.get_compositor_private() : null;
+        const windowActor = this._window?.get_compositor_private();
 
         if (windowActor)
             windowActor.hide();
@@ -532,7 +531,7 @@ class GroupCyclerPopup extends CyclerPopup {
 
     _getWindows() {
         let app = Shell.WindowTracker.get_default().focus_app;
-        let appWindows = app ? app.get_windows() : [];
+        let appWindows = app?.get_windows() ?? [];
 
         if (this._settings.get_boolean('current-workspace-only')) {
             const workspaceManager = global.workspace_manager;
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 1cca533c70..ac92d2fd9d 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -972,7 +972,7 @@ class AppDisplay extends BaseAppView {
         this._switcherooProxy = global.get_switcheroo_control();
         if (this._switcherooProxy) {
             let prop = this._switcherooProxy.get_cached_property('HasDualGpu');
-            discreteGpuAvailable = prop ? prop.unpack() : false;
+            discreteGpuAvailable = prop?.unpack() ?? false;
         } else {
             discreteGpuAvailable = false;
         }
diff --git a/js/ui/components/automountManager.js b/js/ui/components/automountManager.js
index b83bd22c6a..e50ae8e1d5 100644
--- a/js/ui/components/automountManager.js
+++ b/js/ui/components/automountManager.js
@@ -176,7 +176,7 @@ var AutomountManager = class {
         if (allowAutorun)
             this._allowAutorun(volume);
 
-        let mountOp = operation ? operation.mountOp : null;
+        const mountOp = operation?.mountOp ?? null;
         this._activeOperations.set(volume, operation);
 
         volume.mount(0, mountOp, null,
@@ -226,7 +226,7 @@ var AutomountManager = class {
 
     _reaskPassword(volume) {
         let prevOperation = this._activeOperations.get(volume);
-        let existingDialog = prevOperation ? prevOperation.borrowDialog() : null;
+        const existingDialog = prevOperation?.borrowDialog();
         let operation =
             new ShellMountOperation.ShellMountOperation(volume,
                                                         { existingDialog });
diff --git a/js/ui/components/networkAgent.js b/js/ui/components/networkAgent.js
index 29565d214f..4367a2f2a0 100644
--- a/js/ui/components/networkAgent.js
+++ b/js/ui/components/networkAgent.js
@@ -793,7 +793,7 @@ var NetworkAgent = class {
         }
 
         const prop = plugin.lookup_property('GNOME', 'supports-external-ui-mode');
-        const trimmedProp = prop ? prop.trim().toLowerCase() : '';
+        const trimmedProp = prop?.trim().toLowerCase() ?? '';
 
         return {
             fileName,
diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js
index ebf4f4d816..053ae8cce0 100644
--- a/js/ui/endSessionDialog.js
+++ b/js/ui/endSessionDialog.js
@@ -676,8 +676,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
                 let userAvatar = new UserWidget.Avatar(session.user, { iconSize: _ITEM_ICON_SIZE });
                 userAvatar.update();
 
-                userName = session.user.get_real_name()
-                    ? session.user.get_real_name() : session.username;
+                userName = session.user.get_real_name() ?? session.username;
 
                 let userLabelText;
                 if (session.remote)
diff --git a/js/ui/environment.js b/js/ui/environment.js
index e777d653ad..fa3d490a58 100644
--- a/js/ui/environment.js
+++ b/js/ui/environment.js
@@ -364,7 +364,7 @@ function init() {
             this.getHours(),
             this.getMinutes(),
             this.getSeconds());
-        return dt ? dt.format(format) : '';
+        return dt?.format(format) ?? '';
     };
 
     let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
diff --git a/js/ui/inhibitShortcutsDialog.js b/js/ui/inhibitShortcutsDialog.js
index d16c55abdb..c59544eaf9 100644
--- a/js/ui/inhibitShortcutsDialog.js
+++ b/js/ui/inhibitShortcutsDialog.js
@@ -73,7 +73,7 @@ var InhibitShortcutsDialog = GObject.registerClass({
     }
 
     _buildLayout() {
-        let name = this._app ? this._app.get_name() : this._window.title;
+        const name = this._app?.get_name() ?? this._window.title;
 
         let content = new Dialog.MessageDialogContent({
             title: _('Allow inhibiting shortcuts'),
diff --git a/js/ui/notificationDaemon.js b/js/ui/notificationDaemon.js
index 3c8e90b1e0..38f81c3814 100644
--- a/js/ui/notificationDaemon.js
+++ b/js/ui/notificationDaemon.js
@@ -124,7 +124,7 @@ var FdoNotificationDaemon = class FdoNotificationDaemon {
             return source;
         }
 
-        let appId = ndata ? ndata.hints['desktop-entry'] || null : null;
+        const appId = ndata?.hints['desktop-entry'];
         source = new FdoNotificationDaemonSource(title, pid, sender, appId);
 
         this._sources.push(source);
@@ -528,10 +528,10 @@ class GtkNotificationDaemonNotification extends MessageTray.Notification {
             });
         }
 
-        this._defaultAction = defaultAction ? defaultAction.unpack() : null;
+        this._defaultAction = defaultAction?.unpack();
         this._defaultActionTarget = defaultActionTarget;
 
-        this.update(title.unpack(), body ? body.unpack() : null,
+        this.update(title.unpack(), body?.unpack(),
                     { gicon: gicon ? Gio.icon_deserialize(gicon) : null,
                       datetime: time ? GLib.DateTime.new_from_unix_local(time.unpack()) : null });
     }
diff --git a/js/ui/padOsd.js b/js/ui/padOsd.js
index 110962259d..817770a4bb 100644
--- a/js/ui/padOsd.js
+++ b/js/ui/padOsd.js
@@ -770,7 +770,7 @@ var PadOsd = GObject.registerClass({
 
     _getActionText(type, number) {
         let str = global.display.get_pad_action_label(this.padDevice, type, number);
-        return str ? str : _("None");
+        return str ?? _('None');
     }
 
     _updateActionLabels() {
@@ -887,7 +887,7 @@ var PadOsd = GObject.registerClass({
             if (this._followUpActionEdition(str))
                 return;
 
-            this._padDiagram.stopEdition(false, str ? str : _("None"));
+            this._padDiagram.stopEdition(false, str ?? _('None'));
             this._editedAction = null;
         }
 
diff --git a/js/ui/panel.js b/js/ui/panel.js
index 272368a4b0..31b88f7fdd 100644
--- a/js/ui/panel.js
+++ b/js/ui/panel.js
@@ -143,8 +143,8 @@ class AppMenu extends PopupMenu.PopupMenu {
 
         this._updateWindowsSection();
 
-        let appInfo = app ? app.app_info : null;
-        let actions = appInfo ? appInfo.list_actions() : [];
+        const appInfo = app?.app_info;
+        const actions = appInfo?.list_actions() ?? [];
 
         this._actionSection.removeAll();
         actions.forEach(action => {
diff --git a/js/ui/panelMenu.js b/js/ui/panelMenu.js
index 81d34490bd..0c2478f8db 100644
--- a/js/ui/panelMenu.js
+++ b/js/ui/panelMenu.js
@@ -96,11 +96,13 @@ var Button = GObject.registerClass({
     Signals: { 'menu-set': {} },
 }, class PanelMenuButton extends ButtonBox {
     _init(menuAlignment, nameText, dontCreateMenu) {
-        super._init({ reactive: true,
-                      can_focus: true,
-                      track_hover: true,
-                      accessible_name: nameText ? nameText : "",
-                      accessible_role: Atk.Role.MENU });
+        super._init({
+            reactive: true,
+            can_focus: true,
+            track_hover: true,
+            accessible_name: nameText ?? '',
+            accessible_role: Atk.Role.MENU,
+        });
 
         if (dontCreateMenu)
             this.menu = new PopupMenu.PopupDummyMenu(this);
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index a618f8fb48..11528560d4 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -226,7 +226,7 @@ var PopupBaseMenuItem = GObject.registerClass({
     }
 
     getSensitive() {
-        let parentSensitive = this._parent ? this._parent.sensitive : true;
+        const parentSensitive = this._parent?.sensitive ?? true;
         return this._activatable && this._sensitive && parentSensitive;
     }
 
@@ -504,7 +504,7 @@ var PopupMenuBase = class {
     }
 
     getSensitive() {
-        let parentSensitive = this._parent ? this._parent.sensitive : true;
+        const parentSensitive = this._parent?.sensitive ?? true;
         return this._sensitive && parentSensitive;
     }
 
diff --git a/js/ui/search.js b/js/ui/search.js
index dd76735cec..de13d6e014 100644
--- a/js/ui/search.js
+++ b/js/ui/search.js
@@ -873,7 +873,7 @@ var SearchResultsView = GObject.registerClass({
             return;
         }
 
-        let from = this._defaultResult ? this._defaultResult : null;
+        const from = this._defaultResult ?? null;
         this.navigate_focus(from, direction, false);
     }
 
diff --git a/js/ui/shellDBus.js b/js/ui/shellDBus.js
index bac9caa095..f7b542b290 100644
--- a/js/ui/shellDBus.js
+++ b/js/ui/shellDBus.js
@@ -160,11 +160,12 @@ var GnomeShell = class {
         if (deviceNode)
             params['device-node'] = GLib.Variant.new('s', deviceNode);
 
-        connection.emit_signal(destination,
-                               this._dbusImpl.get_object_path(),
-                               info ? info.name : null,
-                               'AcceleratorActivated',
-                               GLib.Variant.new('(ua{sv})', [action, params]));
+        connection.emit_signal(
+            destination,
+            this._dbusImpl.get_object_path(),
+            info?.name ?? null,
+            'AcceleratorActivated',
+            GLib.Variant.new('(ua{sv})', [action, params]));
     }
 
     _grabAcceleratorForSender(accelerator, modeFlags, grabFlags, sender) {
diff --git a/js/ui/windowManager.js b/js/ui/windowManager.js
index afe45037aa..1b90c3b7da 100644
--- a/js/ui/windowManager.js
+++ b/js/ui/windowManager.js
@@ -891,7 +891,7 @@ var WindowManager = class {
             // FIXME: Fix num buttons
             for (let i = 0; i < 50; i++) {
                 let str = display.get_pad_action_label(pad, Meta.PadActionType.BUTTON, i);
-                labels.push(str ? str : '');
+                labels.push(str ?? '');
             }
 
             if (this._gsdWacomProxy) {
diff --git a/js/ui/windowPreview.js b/js/ui/windowPreview.js
index d379703dd8..23a353ef5b 100644
--- a/js/ui/windowPreview.js
+++ b/js/ui/windowPreview.js
@@ -34,7 +34,7 @@ var WindowPreviewLayout = GObject.registerClass({
 
         for (const windowInfo of this._windows.values()) {
             const frame = windowInfo.metaWindow.get_frame_rect();
-            frameRect = frameRect ? frameRect.union(frame) : frame;
+            frameRect = frameRect?.union(frame) ?? frame;
         }
 
         if (!frameRect)
diff --git a/js/ui/workspace.js b/js/ui/workspace.js
index ab49e64123..511ef5def3 100644
--- a/js/ui/workspace.js
+++ b/js/ui/workspace.js
@@ -1291,9 +1291,7 @@ class Workspace extends St.Widget {
     }
 
     _onCloneSelected(clone, time) {
-        let wsIndex;
-        if (this.metaWorkspace)
-            wsIndex = this.metaWorkspace.index();
+        const wsIndex = this.metaWorkspace?.index();
         Main.activateWindow(clone.metaWindow, time, wsIndex);
     }
 
diff --git a/js/ui/xdndHandler.js b/js/ui/xdndHandler.js
index 13d012dec1..95549f3dbb 100644
--- a/js/ui/xdndHandler.js
+++ b/js/ui/xdndHandler.js
@@ -86,7 +86,7 @@ var XdndHandler = class {
         let dragEvent = {
             x,
             y,
-            dragActor: this._cursorWindowClone ? this._cursorWindowClone : this._dummy,
+            dragActor: this._cursorWindowClone ?? this._dummy,
             source: this,
             targetActor: pickedActor,
         };


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