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:
parent
c9df2f9370
commit
40e22eb524
@ -427,8 +427,7 @@ class CyclerHighlight extends St.Widget {
|
|||||||
if (this._clone.source)
|
if (this._clone.source)
|
||||||
this._clone.source.sync_visibility();
|
this._clone.source.sync_visibility();
|
||||||
|
|
||||||
let windowActor = this._window
|
const windowActor = this._window?.get_compositor_private();
|
||||||
? this._window.get_compositor_private() : null;
|
|
||||||
|
|
||||||
if (windowActor)
|
if (windowActor)
|
||||||
windowActor.hide();
|
windowActor.hide();
|
||||||
@ -532,7 +531,7 @@ class GroupCyclerPopup extends CyclerPopup {
|
|||||||
|
|
||||||
_getWindows() {
|
_getWindows() {
|
||||||
let app = Shell.WindowTracker.get_default().focus_app;
|
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')) {
|
if (this._settings.get_boolean('current-workspace-only')) {
|
||||||
const workspaceManager = global.workspace_manager;
|
const workspaceManager = global.workspace_manager;
|
||||||
|
@ -972,7 +972,7 @@ class AppDisplay extends BaseAppView {
|
|||||||
this._switcherooProxy = global.get_switcheroo_control();
|
this._switcherooProxy = global.get_switcheroo_control();
|
||||||
if (this._switcherooProxy) {
|
if (this._switcherooProxy) {
|
||||||
let prop = this._switcherooProxy.get_cached_property('HasDualGpu');
|
let prop = this._switcherooProxy.get_cached_property('HasDualGpu');
|
||||||
discreteGpuAvailable = prop ? prop.unpack() : false;
|
discreteGpuAvailable = prop?.unpack() ?? false;
|
||||||
} else {
|
} else {
|
||||||
discreteGpuAvailable = false;
|
discreteGpuAvailable = false;
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ var AutomountManager = class {
|
|||||||
if (allowAutorun)
|
if (allowAutorun)
|
||||||
this._allowAutorun(volume);
|
this._allowAutorun(volume);
|
||||||
|
|
||||||
let mountOp = operation ? operation.mountOp : null;
|
const mountOp = operation?.mountOp ?? null;
|
||||||
this._activeOperations.set(volume, operation);
|
this._activeOperations.set(volume, operation);
|
||||||
|
|
||||||
volume.mount(0, mountOp, null,
|
volume.mount(0, mountOp, null,
|
||||||
@ -226,7 +226,7 @@ var AutomountManager = class {
|
|||||||
|
|
||||||
_reaskPassword(volume) {
|
_reaskPassword(volume) {
|
||||||
let prevOperation = this._activeOperations.get(volume);
|
let prevOperation = this._activeOperations.get(volume);
|
||||||
let existingDialog = prevOperation ? prevOperation.borrowDialog() : null;
|
const existingDialog = prevOperation?.borrowDialog();
|
||||||
let operation =
|
let operation =
|
||||||
new ShellMountOperation.ShellMountOperation(volume,
|
new ShellMountOperation.ShellMountOperation(volume,
|
||||||
{ existingDialog });
|
{ existingDialog });
|
||||||
|
@ -793,7 +793,7 @@ var NetworkAgent = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const prop = plugin.lookup_property('GNOME', 'supports-external-ui-mode');
|
const prop = plugin.lookup_property('GNOME', 'supports-external-ui-mode');
|
||||||
const trimmedProp = prop ? prop.trim().toLowerCase() : '';
|
const trimmedProp = prop?.trim().toLowerCase() ?? '';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
fileName,
|
fileName,
|
||||||
|
@ -676,8 +676,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
|
|||||||
let userAvatar = new UserWidget.Avatar(session.user, { iconSize: _ITEM_ICON_SIZE });
|
let userAvatar = new UserWidget.Avatar(session.user, { iconSize: _ITEM_ICON_SIZE });
|
||||||
userAvatar.update();
|
userAvatar.update();
|
||||||
|
|
||||||
userName = session.user.get_real_name()
|
userName = session.user.get_real_name() ?? session.username;
|
||||||
? session.user.get_real_name() : session.username;
|
|
||||||
|
|
||||||
let userLabelText;
|
let userLabelText;
|
||||||
if (session.remote)
|
if (session.remote)
|
||||||
|
@ -364,7 +364,7 @@ function init() {
|
|||||||
this.getHours(),
|
this.getHours(),
|
||||||
this.getMinutes(),
|
this.getMinutes(),
|
||||||
this.getSeconds());
|
this.getSeconds());
|
||||||
return dt ? dt.format(format) : '';
|
return dt?.format(format) ?? '';
|
||||||
};
|
};
|
||||||
|
|
||||||
let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
|
let slowdownEnv = GLib.getenv('GNOME_SHELL_SLOWDOWN_FACTOR');
|
||||||
|
@ -73,7 +73,7 @@ var InhibitShortcutsDialog = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
_buildLayout() {
|
_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({
|
let content = new Dialog.MessageDialogContent({
|
||||||
title: _('Allow inhibiting shortcuts'),
|
title: _('Allow inhibiting shortcuts'),
|
||||||
|
@ -124,7 +124,7 @@ var FdoNotificationDaemon = class FdoNotificationDaemon {
|
|||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
let appId = ndata ? ndata.hints['desktop-entry'] || null : null;
|
const appId = ndata?.hints['desktop-entry'];
|
||||||
source = new FdoNotificationDaemonSource(title, pid, sender, appId);
|
source = new FdoNotificationDaemonSource(title, pid, sender, appId);
|
||||||
|
|
||||||
this._sources.push(source);
|
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._defaultActionTarget = defaultActionTarget;
|
||||||
|
|
||||||
this.update(title.unpack(), body ? body.unpack() : null,
|
this.update(title.unpack(), body?.unpack(),
|
||||||
{ gicon: gicon ? Gio.icon_deserialize(gicon) : null,
|
{ gicon: gicon ? Gio.icon_deserialize(gicon) : null,
|
||||||
datetime: time ? GLib.DateTime.new_from_unix_local(time.unpack()) : null });
|
datetime: time ? GLib.DateTime.new_from_unix_local(time.unpack()) : null });
|
||||||
}
|
}
|
||||||
|
@ -770,7 +770,7 @@ var PadOsd = GObject.registerClass({
|
|||||||
|
|
||||||
_getActionText(type, number) {
|
_getActionText(type, number) {
|
||||||
let str = global.display.get_pad_action_label(this.padDevice, type, number);
|
let str = global.display.get_pad_action_label(this.padDevice, type, number);
|
||||||
return str ? str : _("None");
|
return str ?? _('None');
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateActionLabels() {
|
_updateActionLabels() {
|
||||||
@ -887,7 +887,7 @@ var PadOsd = GObject.registerClass({
|
|||||||
if (this._followUpActionEdition(str))
|
if (this._followUpActionEdition(str))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this._padDiagram.stopEdition(false, str ? str : _("None"));
|
this._padDiagram.stopEdition(false, str ?? _('None'));
|
||||||
this._editedAction = null;
|
this._editedAction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,8 +143,8 @@ class AppMenu extends PopupMenu.PopupMenu {
|
|||||||
|
|
||||||
this._updateWindowsSection();
|
this._updateWindowsSection();
|
||||||
|
|
||||||
let appInfo = app ? app.app_info : null;
|
const appInfo = app?.app_info;
|
||||||
let actions = appInfo ? appInfo.list_actions() : [];
|
const actions = appInfo?.list_actions() ?? [];
|
||||||
|
|
||||||
this._actionSection.removeAll();
|
this._actionSection.removeAll();
|
||||||
actions.forEach(action => {
|
actions.forEach(action => {
|
||||||
|
@ -96,11 +96,13 @@ var Button = GObject.registerClass({
|
|||||||
Signals: { 'menu-set': {} },
|
Signals: { 'menu-set': {} },
|
||||||
}, class PanelMenuButton extends ButtonBox {
|
}, class PanelMenuButton extends ButtonBox {
|
||||||
_init(menuAlignment, nameText, dontCreateMenu) {
|
_init(menuAlignment, nameText, dontCreateMenu) {
|
||||||
super._init({ reactive: true,
|
super._init({
|
||||||
|
reactive: true,
|
||||||
can_focus: true,
|
can_focus: true,
|
||||||
track_hover: true,
|
track_hover: true,
|
||||||
accessible_name: nameText ? nameText : "",
|
accessible_name: nameText ?? '',
|
||||||
accessible_role: Atk.Role.MENU });
|
accessible_role: Atk.Role.MENU,
|
||||||
|
});
|
||||||
|
|
||||||
if (dontCreateMenu)
|
if (dontCreateMenu)
|
||||||
this.menu = new PopupMenu.PopupDummyMenu(this);
|
this.menu = new PopupMenu.PopupDummyMenu(this);
|
||||||
|
@ -226,7 +226,7 @@ var PopupBaseMenuItem = GObject.registerClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSensitive() {
|
getSensitive() {
|
||||||
let parentSensitive = this._parent ? this._parent.sensitive : true;
|
const parentSensitive = this._parent?.sensitive ?? true;
|
||||||
return this._activatable && this._sensitive && parentSensitive;
|
return this._activatable && this._sensitive && parentSensitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +504,7 @@ var PopupMenuBase = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSensitive() {
|
getSensitive() {
|
||||||
let parentSensitive = this._parent ? this._parent.sensitive : true;
|
const parentSensitive = this._parent?.sensitive ?? true;
|
||||||
return this._sensitive && parentSensitive;
|
return this._sensitive && parentSensitive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -873,7 +873,7 @@ var SearchResultsView = GObject.registerClass({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let from = this._defaultResult ? this._defaultResult : null;
|
const from = this._defaultResult ?? null;
|
||||||
this.navigate_focus(from, direction, false);
|
this.navigate_focus(from, direction, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,9 +160,10 @@ var GnomeShell = class {
|
|||||||
if (deviceNode)
|
if (deviceNode)
|
||||||
params['device-node'] = GLib.Variant.new('s', deviceNode);
|
params['device-node'] = GLib.Variant.new('s', deviceNode);
|
||||||
|
|
||||||
connection.emit_signal(destination,
|
connection.emit_signal(
|
||||||
|
destination,
|
||||||
this._dbusImpl.get_object_path(),
|
this._dbusImpl.get_object_path(),
|
||||||
info ? info.name : null,
|
info?.name ?? null,
|
||||||
'AcceleratorActivated',
|
'AcceleratorActivated',
|
||||||
GLib.Variant.new('(ua{sv})', [action, params]));
|
GLib.Variant.new('(ua{sv})', [action, params]));
|
||||||
}
|
}
|
||||||
|
@ -891,7 +891,7 @@ var WindowManager = class {
|
|||||||
// FIXME: Fix num buttons
|
// FIXME: Fix num buttons
|
||||||
for (let i = 0; i < 50; i++) {
|
for (let i = 0; i < 50; i++) {
|
||||||
let str = display.get_pad_action_label(pad, Meta.PadActionType.BUTTON, i);
|
let str = display.get_pad_action_label(pad, Meta.PadActionType.BUTTON, i);
|
||||||
labels.push(str ? str : '');
|
labels.push(str ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._gsdWacomProxy) {
|
if (this._gsdWacomProxy) {
|
||||||
|
@ -34,7 +34,7 @@ var WindowPreviewLayout = GObject.registerClass({
|
|||||||
|
|
||||||
for (const windowInfo of this._windows.values()) {
|
for (const windowInfo of this._windows.values()) {
|
||||||
const frame = windowInfo.metaWindow.get_frame_rect();
|
const frame = windowInfo.metaWindow.get_frame_rect();
|
||||||
frameRect = frameRect ? frameRect.union(frame) : frame;
|
frameRect = frameRect?.union(frame) ?? frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!frameRect)
|
if (!frameRect)
|
||||||
|
@ -1291,9 +1291,7 @@ class Workspace extends St.Widget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onCloneSelected(clone, time) {
|
_onCloneSelected(clone, time) {
|
||||||
let wsIndex;
|
const wsIndex = this.metaWorkspace?.index();
|
||||||
if (this.metaWorkspace)
|
|
||||||
wsIndex = this.metaWorkspace.index();
|
|
||||||
Main.activateWindow(clone.metaWindow, time, wsIndex);
|
Main.activateWindow(clone.metaWindow, time, wsIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ var XdndHandler = class {
|
|||||||
let dragEvent = {
|
let dragEvent = {
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
dragActor: this._cursorWindowClone ? this._cursorWindowClone : this._dummy,
|
dragActor: this._cursorWindowClone ?? this._dummy,
|
||||||
source: this,
|
source: this,
|
||||||
targetActor: pickedActor,
|
targetActor: pickedActor,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user