Commit f6b4b967 authored by Florian Müllner's avatar Florian Müllner Committed by Florian Müllner

cleanup: Use Array.includes() to check for element existence

We can use that newer method where we don't care about the actual position
of an element inside the array.

(Array.includes() and Array.indexOf() do behave differently in edge cases,
for example in the handling of NaN, but those don't matter to us)

!152
parent b87455c0
Pipeline #92140 passed with stages
in 4 minutes and 32 seconds
......@@ -582,12 +582,12 @@ class ExtensionRow extends Gtk.ListBoxRow {
_isEnabled() {
let extensions = this._settings.get_strv('enabled-extensions');
return extensions.indexOf(this.uuid) != -1;
return extensions.includes(this.uuid);
}
_enable() {
let extensions = this._settings.get_strv('enabled-extensions');
if (extensions.indexOf(this.uuid) != -1)
if (extensions.includes(this.uuid))
return;
extensions.push(this.uuid);
......
......@@ -31,7 +31,7 @@ function getCurrentExtension() {
// Search for an occurrence of an extension stack frame
// Start at 1 because 0 is the stack frame of this function
for (let i = 1; i < stack.length; i++) {
if (stack[i].indexOf('/gnome-shell/extensions/') > -1) {
if (stack[i].includes('/gnome-shell/extensions/')) {
extensionStackLine = stack[i];
break;
}
......
......@@ -125,7 +125,7 @@ var KeyboardManager = class {
_getLocaleLayout() {
let locale = GLib.get_language_names()[0];
if (locale.indexOf('_') == -1)
if (!locale.includes('_'))
locale = DEFAULT_LOCALE;
let [found, , id] = GnomeDesktop.get_input_source_from_locale(locale);
......
......@@ -69,7 +69,7 @@ function _getCategories(info) {
function _listsIntersect(a, b) {
for (let itemA of a)
if (b.indexOf(itemA) >= 0)
if (b.includes(itemA))
return true;
return false;
}
......@@ -1165,7 +1165,7 @@ var FolderIcon = class FolderIcon {
let excludedApps = this._folder.get_strv('excluded-apps');
let appSys = Shell.AppSystem.get_default();
let addAppId = appId => {
if (excludedApps.indexOf(appId) >= 0)
if (excludedApps.includes(appId))
return;
let app = appSys.lookup_app(appId);
......@@ -1728,7 +1728,7 @@ var AppIconMenu = class AppIconMenu extends PopupMenu.PopupMenu {
let appInfo = this._source.app.get_app_info();
let actions = appInfo.list_actions();
if (this._source.app.can_open_new_window() &&
actions.indexOf('new-window') == -1) {
actions.includes('new-window')) {
this._newWindowMenuItem = this._appendMenuItem(_("New Window"));
this._newWindowMenuItem.connect('activate', () => {
if (this._source.app.state == Shell.AppState.STOPPED)
......@@ -1742,7 +1742,7 @@ var AppIconMenu = class AppIconMenu extends PopupMenu.PopupMenu {
if (discreteGpuAvailable &&
this._source.app.state == Shell.AppState.STOPPED &&
actions.indexOf('activate-discrete-gpu') == -1) {
actions.includes('activate-discrete-gpu')) {
this._onDiscreteGpuMenuItem = this._appendMenuItem(_("Launch using Dedicated Graphics Card"));
this._onDiscreteGpuMenuItem.connect('activate', () => {
if (this._source.app.state == Shell.AppState.STOPPED)
......
......@@ -38,7 +38,7 @@ function isToday(date) {
function _isWorkDay(date) {
/* Translators: Enter 0-6 (Sunday-Saturday) for non-work days. Examples: "0" (Sunday) "6" (Saturday) "06" (Sunday and Saturday). */
let days = C_('calendar-no-work', "06");
return days.indexOf(date.getDay().toString()) == -1;
return !days.includes(date.getDay().toString());
}
function _getBeginningOfDay(date) {
......
......@@ -13,13 +13,13 @@ var ComponentManager = class {
let newEnabledComponents = Main.sessionMode.components;
newEnabledComponents.filter(
name => this._enabledComponents.indexOf(name) == -1
name => !this._enabledComponents.includes(name)
).forEach(name => {
this._enableComponent(name);
});
this._enabledComponents.filter(
name => newEnabledComponents.indexOf(name) == -1
name => !newEnabledComponents.includes(name)
).forEach(name => {
this._disableComponent(name);
});
......
......@@ -40,7 +40,7 @@ function isMountRootHidden(root) {
let path = root.get_path();
// skip any mounts in hidden directory hierarchies
return (path.indexOf('/.') != -1);
return (path.includes('/.'));
}
function isMountNonLocal(mount) {
......@@ -192,15 +192,15 @@ var AutorunDispatcher = class {
_getAutorunSettingForType(contentType) {
let runApp = this._settings.get_strv(SETTING_START_APP);
if (runApp.indexOf(contentType) != -1)
if (runApp.includes(contentType))
return AutorunSetting.RUN;
let ignore = this._settings.get_strv(SETTING_IGNORE);
if (ignore.indexOf(contentType) != -1)
if (ignore.includes(contentType))
return AutorunSetting.IGNORE;
let openFiles = this._settings.get_strv(SETTING_OPEN_FOLDER);
if (openFiles.indexOf(contentType) != -1)
if (openFiles.includes(contentType))
return AutorunSetting.FILES;
return AutorunSetting.ASK;
......
......@@ -327,7 +327,7 @@ class NetworkSecretDialog extends ModalDialog.ModalDialog {
this._getPPPoESecrets(content.secrets);
break;
case 'gsm':
if (this._hints.indexOf('pin') != -1) {
if (this._hints.includes('pin')) {
let gsmSetting = this._connection.get_setting_gsm();
content.title = _("PIN code required");
content.message = _("PIN code is needed for the mobile broadband device");
......@@ -695,7 +695,7 @@ var NetworkAgent = class {
body = _("A password is required to connect to “%s”.".format(connection.get_id()));
break;
case 'gsm':
if (hints.indexOf('pin') != -1) {
if (hints.includes('pin')) {
let gsmSetting = connection.get_setting_gsm();
title = _("PIN code required");
body = _("PIN code is needed for the mobile broadband device");
......
......@@ -45,9 +45,9 @@ var AuthenticationDialog = GObject.registerClass({
}
let userName = GLib.get_user_name();
if (userNames.indexOf(userName) < 0)
if (!userNames.includes(userName))
userName = 'root';
if (userNames.indexOf(userName) < 0)
if (!userNames.includes(userName))
userName = userNames[0];
this._user = AccountsService.UserManager.get_default().get_user(userName);
......
......@@ -700,14 +700,14 @@ var Dash = class Dash {
}
// App removed at oldIndex
if (oldApp && newApps.indexOf(oldApp) == -1) {
if (oldApp && !newApps.includes(oldApp)) {
removedActors.push(children[oldIndex]);
oldIndex++;
continue;
}
// App added at newIndex
if (newApp && oldApps.indexOf(newApp) == -1) {
if (newApp && !oldApps.includes(newApp)) {
addedItems.push({ app: newApp,
item: this._createAppItem(newApp),
pos: newIndex });
......
......@@ -585,7 +585,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
}
_onInhibitorLoaded(inhibitor) {
if (this._applications.indexOf(inhibitor) < 0) {
if (!this._applications.includes(inhibitor)) {
// Stale inhibitor
return;
}
......
......@@ -228,7 +228,7 @@ class InstallExtensionDialog extends ModalDialog.ModalDialog {
function callback() {
// Add extension to 'enabled-extensions' for the user, always...
let enabledExtensions = global.settings.get_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY);
if (enabledExtensions.indexOf(uuid) == -1) {
if (!enabledExtensions.includes(uuid)) {
enabledExtensions.push(uuid);
global.settings.set_strv(ExtensionSystem.ENABLED_EXTENSIONS_KEY, enabledExtensions);
}
......
......@@ -169,7 +169,7 @@ function loadExtension(extension) {
if (checkVersion && ExtensionUtils.isOutOfDate(extension)) {
extension.state = ExtensionState.OUT_OF_DATE;
} else {
let enabled = enabledExtensions.indexOf(extension.uuid) != -1;
let enabled = enabledExtensions.includes(extension.uuid);
if (enabled) {
if (!initExtension(extension.uuid))
return;
......
......@@ -87,7 +87,7 @@ var GrabHelper = class GrabHelper {
_isWithinGrabbedActor(actor) {
let currentActor = this.currentGrab.actor;
while (actor) {
if (this._actors.indexOf(actor) != -1)
if (this._actors.includes(actor))
return true;
if (actor == currentActor)
return true;
......
......@@ -111,7 +111,7 @@ var InhibitShortcutsDialog = GObject.registerClass({
}
vfunc_show() {
if (this._app && APP_WHITELIST.indexOf(this._app.get_id()) != -1) {
if (this._app && APP_WHITELIST.includes(this._app.get_id())) {
this._emitResponse(DialogResponse.ALLOW);
return;
}
......
......@@ -1074,7 +1074,7 @@ var Keyboard = class Keyboard {
let manager = Clutter.DeviceManager.get_default();
let device = manager.get_device(deviceId);
if (device.get_device_name().indexOf('XTEST') < 0) {
if (!device.get_device_name().includes('XTEST')) {
this._lastDeviceId = deviceId;
this._syncEnabled();
}
......
......@@ -663,7 +663,7 @@ function initializeDeferredWork(actor, callback, props) {
_deferredWorkData[workId] = { 'actor': actor,
'callback': callback };
actor.connect('notify::mapped', () => {
if (!(actor.mapped && _deferredWorkQueue.indexOf(workId) >= 0))
if (!(actor.mapped && _deferredWorkQueue.includes(workId)))
return;
_queueBeforeRedraw(workId);
});
......@@ -693,7 +693,7 @@ function queueDeferredWork(workId) {
logError(new Error(message), message);
return;
}
if (_deferredWorkQueue.indexOf(workId) < 0)
if (!_deferredWorkQueue.includes(workId))
_deferredWorkQueue.push(workId);
if (data.actor.mapped) {
_queueBeforeRedraw(workId);
......
......@@ -72,7 +72,7 @@ var URLHighlighter = class URLHighlighter {
let urlId = this._findUrlAtPos(event);
if (urlId != -1) {
let url = this._urls[urlId].url;
if (url.indexOf(':') == -1)
if (!url.includes(':'))
url = 'http://' + url;
Gio.app_info_launch_default_for_uri(url, global.create_app_launch_context(0, -1));
......
......@@ -228,7 +228,7 @@ class NotificationApplicationPolicy extends NotificationPolicy {
this._settings.set_string('application-id', this.id + '.desktop');
let apps = this._masterSettings.get_strv('application-children');
if (apps.indexOf(this._canonicalId) < 0) {
if (!apps.includes(this._canonicalId)) {
apps.push(this._canonicalId);
this._masterSettings.set_strv('application-children', apps);
}
......@@ -772,7 +772,7 @@ var Source = class Source {
}
pushNotification(notification) {
if (this.notifications.indexOf(notification) >= 0)
if (this.notifications.includes(notification))
return;
while (this.notifications.length >= MAX_NOTIFICATIONS_PER_SOURCE)
......@@ -1069,7 +1069,7 @@ var MessageTray = class MessageTray {
// If a new notification is updated while it is being hidden,
// we stop hiding it and show it again.
this._updateShowingNotification();
} else if (this._notificationQueue.indexOf(notification) < 0) {
} else if (!this._notificationQueue.includes(notification)) {
// If the queue is "full", we skip banner mode and just show a small
// indicator in the panel; however do make an exception for CRITICAL
// notifications, as only banner mode allows expansion.
......
......@@ -630,7 +630,7 @@ var PadOsd = class {
// If the device is being removed, destroy the padOsd.
if (device == this.padDevice) {
this.destroy();
} else if (this._groupPads.indexOf(device) != -1) {
} else if (this._groupPads.includes(device)) {
// Or update the pad chooser if the device belongs to
// the same group.
this._groupPads.splice(this._groupPads.indexOf(device), 1);
......@@ -749,8 +749,7 @@ var PadOsd = class {
}
_requestForOtherPad(pad) {
if (pad == this.padDevice ||
this._groupPads.indexOf(pad) == -1)
if (pad == this.padDevice || !this._groupPads.includes(pad))
return;
let editionMode = this._editionMode;
......@@ -801,7 +800,7 @@ var PadOsd = class {
// If the event comes from another pad in the same group,
// show the OSD for it.
if (this._groupPads.indexOf(event.get_source_device()) != -1) {
if (this._groupPads.includes(event.get_source_device())) {
this._requestForOtherPad(event.get_source_device());
return Clutter.EVENT_STOP;
}
......
......@@ -1056,9 +1056,9 @@ class Panel extends St.Widget {
this._updateBox(panel.center, this._centerBox);
this._updateBox(panel.right, this._rightBox);
if (panel.left.indexOf('dateMenu') != -1)
if (panel.left.includes('dateMenu'))
Main.messageTray.bannerAlignment = Clutter.ActorAlign.START;
else if (panel.right.indexOf('dateMenu') != -1)
else if (panel.right.includes('dateMenu'))
Main.messageTray.bannerAlignment = Clutter.ActorAlign.END;
// Default to center if there is no dateMenu
else
......
......@@ -146,10 +146,10 @@ function loadRemoteSearchProviders(searchSettings, callback) {
if (provider.defaultEnabled) {
let disabled = searchSettings.get_strv('disabled');
return disabled.indexOf(appId) == -1;
return !disabled.includes(appId);
} else {
let enabled = searchSettings.get_strv('enabled');
return enabled.indexOf(appId) != -1;
return enabled.includes(appId);
}
});
......
......@@ -182,7 +182,7 @@ class RunDialog extends ModalDialog.ModalDialog {
}
_getCompletion(text) {
if (text.indexOf('/') != -1) {
if (text.includes('/')) {
return this._pathCompleter.get_completion_suffix(text);
} else {
return this._getCommandCompletion(text);
......
......@@ -128,7 +128,7 @@ function _loadMode(file, info) {
let propBlacklist = ['unlockDialog'];
for (let prop in _modes[DEFAULT_MODE]) {
if (newMode[prop] !== undefined &&
propBlacklist.indexOf(prop) == -1)
!propBlacklist.includes(prop))
_modes[modeName][prop] = newMode[prop];
}
_modes[modeName]['isPrimary'] = true;
......
......@@ -1040,7 +1040,7 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
_checkConnections(network, accessPoint) {
this._connections.forEach(connection => {
if (accessPoint.connection_valid(connection) &&
network.connections.indexOf(connection) == -1) {
!network.connections.includes(connection)) {
network.connections.push(connection);
}
});
......@@ -1059,7 +1059,7 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
if (pos != -1) {
network = this._networks[pos];
if (network.accessPoints.indexOf(accessPoint) != -1) {
if (network.accessPoints.includes(accessPoint)) {
log('Access point was already seen, not adding again');
return;
}
......
......@@ -215,7 +215,7 @@ var OutputStreamSlider = class extends StreamSlider {
// of different identifiers for headphones, and I could
// not find the complete list
if (sink.get_ports().length > 0)
return sink.get_port().port.indexOf('headphone') >= 0;
return sink.get_port().port.includes('headphone');
return false;
}
......
......@@ -1288,7 +1288,7 @@ var WindowManager = class {
return false;
let type = actor.meta_window.get_window_type();
return types.indexOf(type) >= 0;
return types.includes(type);
}
_removeEffect(list, actor) {
......@@ -1501,7 +1501,7 @@ var WindowManager = class {
_sizeChangedWindow(shellwm, actor) {
if (!actor.__animationInfo)
return;
if (this._resizing.indexOf(actor) != -1)
if (this._resizing.includes(actor))
return;
let actorClone = actor.__animationInfo.clone;
......
......@@ -536,7 +536,7 @@ var WindowOverlay = class {
let [cloneX, cloneY, cloneWidth, cloneHeight] = this._windowClone.slot;
let layout = Meta.prefs_get_button_layout();
let side = layout.left_buttons.indexOf(Meta.ButtonFunction.CLOSE) > -1 ? St.Side.LEFT : St.Side.RIGHT;
let side = layout.left_buttons.includes(Meta.ButtonFunction.CLOSE) ? St.Side.LEFT : St.Side.RIGHT;
let buttonX;
let buttonY = cloneY - (button.height - button._overlap);
......
......@@ -378,7 +378,7 @@ var WorkspaceThumbnail = class {
return;
}
if (this._allWindows.indexOf(metaWin) == -1) {
if (!this._allWindows.includes(metaWin)) {
let minimizedChangedId = metaWin.connect('notify::minimized',
this._updateMinimized.bind(this));
this._allWindows.push(metaWin);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment