diff --git a/src/gui/html/js/events.js b/src/gui/html/js/events.js index 6675d70c..c533309e 100644 --- a/src/gui/html/js/events.js +++ b/src/gui/html/js/events.js @@ -79,7 +79,7 @@ function onPluginIsDirtyChange(evt) { } } function saveFilterState(evt) { - loot.query('saveFilterState', evt.target.id, evt.target.checked).catch(processCefError); + loot.query('saveFilterState', evt.target.id, evt.target.checked).catch(handlePromiseError); } function onToggleDisplayCSS(evt) { var attr = 'data-hide-' + evt.target.getAttribute('data-class'); @@ -103,7 +103,7 @@ function onToggleBashTags(evt) { document.getElementById('searchBar').search(); } function onOpenLogLocation(evt) { - loot.query('openLogLocation').catch(processCefError); + loot.query('openLogLocation').catch(handlePromiseError); } function onChangeGame(evt) { /* Check that the selected game isn't the current one. */ @@ -147,10 +147,10 @@ function onChangeGame(evt) { } loot.Dialog.closeProgress(); - }).catch(processCefError); + }).catch(handlePromiseError); } function onOpenReadme(evt) { - loot.query('openReadme').catch(processCefError); + loot.query('openReadme').catch(handlePromiseError); } /* Masterlist update process, minus progress dialog. */ function updateMasterlistNoProgress() { @@ -180,13 +180,13 @@ function updateMasterlistNoProgress() { } else { loot.Dialog.showNotification(loot.l10n.translate('No masterlist update was necessary.')); } - }).catch(processCefError); + }).catch(handlePromiseError); } function onUpdateMasterlist(evt) { loot.Dialog.showProgress(loot.l10n.translate('Updating masterlist...')); updateMasterlistNoProgress().then(function(result){ loot.Dialog.closeProgress(); - }).catch(processCefError); + }).catch(handlePromiseError); } function onSortPlugins(evt) { if (document.body.hasAttribute('data-conflicts')) { @@ -255,8 +255,8 @@ function onSortPlugins(evt) { document.getElementById('gameMenu').setAttribute('disabled', ''); loot.Dialog.closeProgress(); } - }).catch(processCefError); - }).catch(processCefError); + }).catch(handlePromiseError); + }).catch(handlePromiseError); } function onApplySort(evt) { var loadOrder = []; @@ -277,7 +277,7 @@ function onApplySort(evt) { /* Enable changing game. */ document.getElementById('gameMenu').removeAttribute('disabled'); - }).catch(processCefError); + }).catch(handlePromiseError); } function onCancelSort(evt) { return loot.query('cancelSort').then(function(){ @@ -296,7 +296,7 @@ function onCancelSort(evt) { /* Enable changing game. */ document.getElementById('gameMenu').removeAttribute('disabled'); - }).catch(processCefError); + }).catch(handlePromiseError); } function onRedatePlugins(evt) { if (evt.target.hasAttribute('disabled')) { @@ -307,7 +307,7 @@ function onRedatePlugins(evt) { if (result) { loot.query('redatePlugins').then(function(response){ loot.Dialog.showNotification('Plugins were successfully redated.'); - }).catch(processCefError); + }).catch(handlePromiseError); } }); } @@ -336,7 +336,7 @@ function onClearAllMetadata(evt) { loot.Dialog.showNotification(loot.l10n.translate('All user-added metadata has been cleared.')); } - }).catch(processCefError); + }).catch(handlePromiseError); } }); } @@ -387,7 +387,7 @@ function onCopyContent(evt) { plugins: plugins }).then(function(){ loot.Dialog.showNotification(loot.l10n.translate("LOOT's content has been copied to the clipboard.")); - }).catch(processCefError); + }).catch(handlePromiseError); } function onCopyLoadOrder(evt) { var plugins = []; @@ -402,7 +402,7 @@ function onCopyLoadOrder(evt) { loot.query('copyLoadOrder', plugins).then(function(){ loot.Dialog.showNotification(loot.l10n.translate("The load order has been copied to the clipboard.")); - }).catch(processCefError); + }).catch(handlePromiseError); } function onSwitchSidebarTab(evt) { if (evt.detail.isSelected) { @@ -451,7 +451,7 @@ function onCloseSettingsDialog(evt) { loot.settings = settings; updateSettingsUI(); - }).catch(processCefError); + }).catch(handlePromiseError); } else { /* Re-apply the existing settings to the settings dialog elements. */ updateSettingsUI(); @@ -501,7 +501,7 @@ function onEditorOpen(evt) { document.body.setAttribute('data-editors', numEditors); document.getElementById('cardsNav').updateSize(); - return loot.query('editorOpened').catch(processCefError); + return loot.query('editorOpened').catch(handlePromiseError); } function onEditorClose(evt) { /* evt.detail is true if the apply button was pressed. */ @@ -567,7 +567,7 @@ function onEditorClose(evt) { document.body.setAttribute('data-editors', numEditors); } document.getElementById('cardsNav').updateSize(); - }).catch(processCefError); + }).catch(handlePromiseError); } function onConflictsFilter(evt) { /* Deactivate any existing plugin conflict filter. */ @@ -593,7 +593,7 @@ function onConflictsFilter(evt) { function onCopyMetadata(evt) { loot.query('copyMetadata', evt.target.getName()).then(function(){ loot.Dialog.showNotification(loot.l10n.translate('The metadata for "%s" has been copied to the clipboard.', evt.target.getName())); - }).catch(processCefError); + }).catch(handlePromiseError); } function onClearMetadata(evt) { loot.Dialog.askQuestion('', loot.l10n.translate('Are you sure you want to clear all existing user-added metadata from "%s"?', evt.target.getName()), loot.l10n.translate('Clear'), function(result){ @@ -620,7 +620,7 @@ function onClearMetadata(evt) { do anything. */ document.getElementById('searchBar').search(); } - }).catch(processCefError); + }).catch(handlePromiseError); } }); } @@ -714,7 +714,7 @@ function onContentRefresh(evt) { setFilteredUIData(); loot.Dialog.closeProgress(); - }).catch(processCefError); + }).catch(handlePromiseError); } function onSearchOpen(evt) { document.getElementById('mainToolbar').classList.add('search'); diff --git a/src/gui/html/js/helpers.js b/src/gui/html/js/helpers.js index 398492a0..cfe8cd99 100644 --- a/src/gui/html/js/helpers.js +++ b/src/gui/html/js/helpers.js @@ -1,44 +1,43 @@ 'use strict'; -function processCefError(err) { - /* Error.stack seems to be Chromium-specific. It gives a lot more useful - info than just the error message. Also, this can be used to catch any - promise errors, not just CEF errors. */ - console.log(err.stack); - loot.Dialog.closeProgress(); - loot.Dialog.showMessage(loot.l10n.translate('Error'), err.message); +function handlePromiseError(err) { + /* Error.stack seems to be Chromium-specific. */ + console.log(err.stack); + loot.Dialog.closeProgress(); + loot.Dialog.showMessage(loot.l10n.translate('Error'), err.message); } function showElement(element) { - if (element != null) { - element.classList.toggle('hidden', false); - } + if (element !== null) { + element.classList.toggle('hidden', false); + } } function hideElement(element) { - if (element != null) { - element.classList.toggle('hidden', true); - } + if (element !== null) { + element.classList.toggle('hidden', true); + } } function handleUnappliedChangesClose(change) { - loot.Dialog.askQuestion('', loot.l10n.translate('You have not yet applied or cancelled your %s. Are you sure you want to quit?', change), loot.l10n.translate('Quit'), function(result){ - if (result) { - /* Cancel any sorting and close any editors. Cheat by sending a - cancelSort query for as many times as necessary. */ - var queries = []; - var numQueries = 0; - if (!document.getElementById('applySortButton').classList.contains('hidden')) { - numQueries += 1; - } - numQueries += document.body.getAttribute('data-editors'); - for (var i = 0; i < numQueries; ++i) { - queries.push(loot.query('cancelSort')); - } - Promise.all(queries).then(function(){ - window.close(); - }).catch(processCefError); - } - }); + loot.Dialog.askQuestion('', loot.l10n.translate('You have not yet applied or cancelled your %s. Are you sure you want to quit?', change), loot.l10n.translate('Quit'), (result) => { + if (!result) { + return; + } + /* Cancel any sorting and close any editors. Cheat by sending a + cancelSort query for as many times as necessary. */ + const queries = []; + let numQueries = 0; + if (!document.getElementById('applySortButton').classList.contains('hidden')) { + numQueries += 1; + } + numQueries += document.body.getAttribute('data-editors'); + for (let i = 0; i < numQueries; ++i) { + queries.push(loot.query('cancelSort')); + } + Promise.all(queries).then(() => { + window.close(); + }).catch(handlePromiseError); + }); } -function getConflictingPlugins(pluginName) { +function getConflictingPlugins(pluginName) { if (!pluginName) { return Promise.resolve([]); } @@ -72,9 +71,9 @@ function getConflictingPlugins(pluginName) { } loot.Dialog.closeProgress(); return [pluginName]; - }).catch(processCefError); + }).catch(handlePromiseError); } -function setFilteredUIData(filtersState) { +function setFilteredUIData() { getConflictingPlugins(loot.filters.conflictTargetPluginName).then((conflictingPluginNames) => { loot.filters.conflictingPluginNames = conflictingPluginNames; return loot.game.plugins.filter(loot.filters.pluginFilter, loot.filters); @@ -121,17 +120,17 @@ function updateSelectedGame(gameFolder) { /* Call whenever installedGames is changed or game menu is rewritten. */ function updateEnabledGames(installedGames) { - /* Update the disabled games in the game menu. */ - var gameMenuItems = document.getElementById('gameMenu').children; - for (var i = 0; i < gameMenuItems.length; ++i) { - if (installedGames.indexOf(gameMenuItems[i].getAttribute('value')) == -1) { - gameMenuItems[i].setAttribute('disabled', true); - gameMenuItems[i].removeEventListener('click', onChangeGame, false); - } else { - gameMenuItems[i].removeAttribute('disabled'); - gameMenuItems[i].addEventListener('click', onChangeGame, false); - } + /* Update the disabled games in the game menu. */ + const gameMenuItems = document.getElementById('gameMenu').children; + for (let i = 0; i < gameMenuItems.length; ++i) { + if (installedGames.indexOf(gameMenuItems[i].getAttribute('value')) === -1) { + gameMenuItems[i].setAttribute('disabled', true); + gameMenuItems[i].removeEventListener('click', onChangeGame); + } else { + gameMenuItems[i].removeAttribute('disabled'); + gameMenuItems[i].addEventListener('click', onChangeGame); } + } } function setInstalledGames(installedGames) { loot.installedGames = installedGames; @@ -139,38 +138,38 @@ function setInstalledGames(installedGames) { } /* Call whenever settings are changed. */ function updateSettingsUI() { - var gameSelect = document.getElementById('defaultGameSelect'); - var gameMenu = document.getElementById('gameMenu'); - var gameTable = document.getElementById('gameTable'); + const gameSelect = document.getElementById('defaultGameSelect'); + const gameMenu = document.getElementById('gameMenu'); + const gameTable = document.getElementById('gameTable'); - /* First make sure game listing elements don't have any existing entries. */ - while (gameSelect.children.length > 1) { - gameSelect.removeChild(gameSelect.lastElementChild); - } - while (gameMenu.firstElementChild) { - gameMenu.firstElementChild.removeEventListener('click', onChangeGame, false); - gameMenu.removeChild(gameMenu.firstElementChild); - } - gameTable.clear(); + /* First make sure game listing elements don't have any existing entries. */ + while (gameSelect.children.length > 1) { + gameSelect.removeChild(gameSelect.lastElementChild); + } + while (gameMenu.firstElementChild) { + gameMenu.firstElementChild.removeEventListener('click', onChangeGame); + gameMenu.removeChild(gameMenu.firstElementChild); + } + gameTable.clear(); - /* Now fill with new values. */ - loot.settings.games.forEach(function(game){ - var menuItem = document.createElement('paper-item'); - menuItem.setAttribute('value', game.folder); - menuItem.setAttribute('noink', ''); - menuItem.textContent = game.name; - gameMenu.appendChild(menuItem); - gameSelect.appendChild(menuItem.cloneNode(true)); + /* Now fill with new values. */ + loot.settings.games.forEach((game) => { + const menuItem = document.createElement('paper-item'); + menuItem.setAttribute('value', game.folder); + menuItem.setAttribute('noink', ''); + menuItem.textContent = game.name; + gameMenu.appendChild(menuItem); + gameSelect.appendChild(menuItem.cloneNode(true)); - var row = gameTable.addRow(game); - gameTable.setReadOnly(row, ['name','folder','type']); - }); + const row = gameTable.addRow(game); + gameTable.setReadOnly(row, ['name', 'folder', 'type']); + }); - gameSelect.value = loot.settings.game; - document.getElementById('languageSelect').value = loot.settings.language; - document.getElementById('enableDebugLogging').checked = loot.settings.enableDebugLogging; - document.getElementById('updateMasterlist').checked = loot.settings.updateMasterlist; + gameSelect.value = loot.settings.game; + document.getElementById('languageSelect').value = loot.settings.language; + document.getElementById('enableDebugLogging').checked = loot.settings.enableDebugLogging; + document.getElementById('updateMasterlist').checked = loot.settings.updateMasterlist; - updateEnabledGames(loot.installedGames); - updateSelectedGame(loot.game.folder); + updateEnabledGames(loot.installedGames); + updateSelectedGame(loot.game.folder); } diff --git a/src/gui/html/js/init.js b/src/gui/html/js/init.js index c7bc4a2d..195f3c23 100644 --- a/src/gui/html/js/init.js +++ b/src/gui/html/js/init.js @@ -205,7 +205,7 @@ function initialise() { if (!loot.settings.lastVersion || loot.settings.lastVersion !== loot.version) { document.getElementById('firstRun').showModal(); } - }).catch(processCefError); + }).catch(handlePromiseError); } window.addEventListener('polymer-ready', initialise);