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>
This commit is contained in:
Florian Müllner 2020-08-12 20:59:01 +02:00 committed by Marge Bot
parent c9df2f9370
commit 40e22eb524
18 changed files with 36 additions and 37 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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 });

View File

@ -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,

View File

@ -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)

View File

@ -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');

View File

@ -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'),

View File

@ -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 });
}

View File

@ -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;
}

View File

@ -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 => {

View File

@ -96,11 +96,13 @@ var Button = GObject.registerClass({
Signals: { 'menu-set': {} },
}, class PanelMenuButton extends ButtonBox {
_init(menuAlignment, nameText, dontCreateMenu) {
super._init({ reactive: true,
super._init({
reactive: true,
can_focus: true,
track_hover: true,
accessible_name: nameText ? nameText : "",
accessible_role: Atk.Role.MENU });
accessible_name: nameText ?? '',
accessible_role: Atk.Role.MENU,
});
if (dontCreateMenu)
this.menu = new PopupMenu.PopupDummyMenu(this);

View File

@ -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;
}

View File

@ -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);
}

View File

@ -160,9 +160,10 @@ var GnomeShell = class {
if (deviceNode)
params['device-node'] = GLib.Variant.new('s', deviceNode);
connection.emit_signal(destination,
connection.emit_signal(
destination,
this._dbusImpl.get_object_path(),
info ? info.name : null,
info?.name ?? null,
'AcceleratorActivated',
GLib.Variant.new('(ua{sv})', [action, params]));
}

View File

@ -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) {

View File

@ -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)

View File

@ -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);
}

View File

@ -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,
};