diff --git a/.eslintrc.js b/.eslintrc.js index ec1cd17c41..0f94de8ed9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -76,7 +76,6 @@ module.exports = { 'sonarjs/cognitive-complexity': ['warn'], // TODO: Enable the following rules and fix issues 'sonarjs/no-duplicate-string': ['off'], - 'sonarjs/no-identical-functions': ['off'], 'sonarjs/no-redundant-jump': ['off'], 'sonarjs/no-small-switch': ['off'], 'sonarjs/prefer-object-literal': ['off'], diff --git a/src/components/dialogHelper/dialogHelper.js b/src/components/dialogHelper/dialogHelper.js index 130a1742cb..9c1ecec625 100644 --- a/src/components/dialogHelper/dialogHelper.js +++ b/src/components/dialogHelper/dialogHelper.js @@ -275,6 +275,11 @@ import '../../assets/css/scrollstyles.scss'; } } + const getAnimationEndHandler = (dlg, callback) => function handler() { + dom.removeEventListener(dlg, dom.whichAnimationEvent(), handler, { once: true }); + callback(); + }; + function animateDialogOpen(dlg) { const onAnimationFinish = () => { focusManager.pushScope(dlg); @@ -290,15 +295,11 @@ import '../../assets/css/scrollstyles.scss'; }; if (enableAnimation()) { - const onFinish = () => { - dom.removeEventListener(dlg, dom.whichAnimationEvent(), onFinish, { - once: true - }); - onAnimationFinish(); - }; - dom.addEventListener(dlg, dom.whichAnimationEvent(), onFinish, { - once: true - }); + dom.addEventListener( + dlg, + dom.whichAnimationEvent(), + getAnimationEndHandler(dlg, onAnimationFinish), + { once: true }); return; } @@ -324,15 +325,12 @@ import '../../assets/css/scrollstyles.scss'; animated = false; break; } - const onFinish = () => { - dom.removeEventListener(dlg, dom.whichAnimationEvent(), onFinish, { - once: true - }); - onAnimationFinish(); - }; - dom.addEventListener(dlg, dom.whichAnimationEvent(), onFinish, { - once: true - }); + + dom.addEventListener( + dlg, + dom.whichAnimationEvent(), + getAnimationEndHandler(dlg, onAnimationFinish), + { once: true }); if (animated) { return; diff --git a/src/components/itemsrefresher.js b/src/components/itemsrefresher.js index a2c57dee1d..8b71d9c926 100644 --- a/src/components/itemsrefresher.js +++ b/src/components/itemsrefresher.js @@ -24,37 +24,18 @@ function getEventsToMonitor(instance) { return []; } -function onTimerCreated() { +function notifyTimerRefresh() { const instance = this; if (getEventsToMonitor(instance).indexOf('timers') !== -1) { instance.notifyRefreshNeeded(); - return; } } -function onSeriesTimerCreated() { +function notifySeriesTimerRefresh() { const instance = this; if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) { instance.notifyRefreshNeeded(); - return; - } -} - -function onTimerCancelled() { - const instance = this; - - if (getEventsToMonitor(instance).indexOf('timers') !== -1) { - instance.notifyRefreshNeeded(); - return; - } -} - -function onSeriesTimerCancelled() { - const instance = this; - if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) { - instance.notifyRefreshNeeded(); - return; } } @@ -125,10 +106,10 @@ class ItemsRefresher { this.options = options || {}; addNotificationEvent(this, 'UserDataChanged', onUserDataChanged); - addNotificationEvent(this, 'TimerCreated', onTimerCreated); - addNotificationEvent(this, 'SeriesTimerCreated', onSeriesTimerCreated); - addNotificationEvent(this, 'TimerCancelled', onTimerCancelled); - addNotificationEvent(this, 'SeriesTimerCancelled', onSeriesTimerCancelled); + addNotificationEvent(this, 'TimerCreated', notifyTimerRefresh); + addNotificationEvent(this, 'SeriesTimerCreated', notifySeriesTimerRefresh); + addNotificationEvent(this, 'TimerCancelled', notifyTimerRefresh); + addNotificationEvent(this, 'SeriesTimerCancelled', notifySeriesTimerRefresh); addNotificationEvent(this, 'LibraryChanged', onLibraryChanged); addNotificationEvent(this, 'playbackstop', onPlaybackStopped, playbackManager); } diff --git a/src/controllers/dashboard/dashboard.js b/src/controllers/dashboard/dashboard.js index f700595c37..7d9b9536c2 100644 --- a/src/controllers/dashboard/dashboard.js +++ b/src/controllers/dashboard/dashboard.js @@ -747,14 +747,7 @@ import confirm from '../../components/confirm/confirm'; console.debug('onServerRestarting not implemented', evt, apiClient); } - function onPackageInstalling(evt, apiClient) { - if (apiClient.serverId() === serverId) { - pollForInfo(view, apiClient); - reloadSystemInfo(view, apiClient); - } - } - - function onPackageInstallationCompleted(evt, apiClient) { + function onPackageInstall(_, apiClient) { if (apiClient.serverId() === serverId) { pollForInfo(view, apiClient); reloadSystemInfo(view, apiClient); @@ -786,8 +779,8 @@ import confirm from '../../components/confirm/confirm'; Events.on(serverNotifications, 'RestartRequired', onRestartRequired); Events.on(serverNotifications, 'ServerShuttingDown', onServerShuttingDown); Events.on(serverNotifications, 'ServerRestarting', onServerRestarting); - Events.on(serverNotifications, 'PackageInstalling', onPackageInstalling); - Events.on(serverNotifications, 'PackageInstallationCompleted', onPackageInstallationCompleted); + Events.on(serverNotifications, 'PackageInstalling', onPackageInstall); + Events.on(serverNotifications, 'PackageInstallationCompleted', onPackageInstall); Events.on(serverNotifications, 'Sessions', onSessionsUpdate); Events.on(serverNotifications, 'ScheduledTasksInfo', onScheduledTasksUpdate); DashboardPage.lastAppUpdateCheck = null; @@ -824,8 +817,8 @@ import confirm from '../../components/confirm/confirm'; Events.off(serverNotifications, 'RestartRequired', onRestartRequired); Events.off(serverNotifications, 'ServerShuttingDown', onServerShuttingDown); Events.off(serverNotifications, 'ServerRestarting', onServerRestarting); - Events.off(serverNotifications, 'PackageInstalling', onPackageInstalling); - Events.off(serverNotifications, 'PackageInstallationCompleted', onPackageInstallationCompleted); + Events.off(serverNotifications, 'PackageInstalling', onPackageInstall); + Events.off(serverNotifications, 'PackageInstallationCompleted', onPackageInstall); Events.off(serverNotifications, 'Sessions', onSessionsUpdate); Events.off(serverNotifications, 'ScheduledTasksInfo', onScheduledTasksUpdate); diff --git a/src/controllers/playback/video/index.js b/src/controllers/playback/video/index.js index a51bff1d50..a1ce0297cf 100644 --- a/src/controllers/playback/video/index.js +++ b/src/controllers/playback/video/index.js @@ -1204,17 +1204,6 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components resetIdle(); } - function onWindowTouchStart(e) { - clickedElement = e.target; - mouseIsDown = true; - resetIdle(); - } - - function onWindowTouchEnd() { - mouseIsDown = false; - resetIdle(); - } - function onWindowDragEnd() { // mousedown -> dragstart -> dragend !!! no mouseup :( mouseIsDown = false; @@ -1370,12 +1359,12 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components capture: true, passive: true }); - dom.addEventListener(window, 'touchstart', onWindowTouchStart, { + dom.addEventListener(window, 'touchstart', onWindowMouseDown, { capture: true, passive: true }); ['touchend', 'touchcancel'].forEach((event) => { - dom.addEventListener(window, event, onWindowTouchEnd, { + dom.addEventListener(window, event, onWindowMouseUp, { capture: true, passive: true }); @@ -1411,12 +1400,12 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components capture: true, passive: true }); - dom.removeEventListener(window, 'touchstart', onWindowTouchStart, { + dom.removeEventListener(window, 'touchstart', onWindowMouseDown, { capture: true, passive: true }); ['touchend', 'touchcancel'].forEach((event) => { - dom.removeEventListener(window, event, onWindowTouchEnd, { + dom.removeEventListener(window, event, onWindowMouseUp, { capture: true, passive: true }); diff --git a/src/plugins/htmlAudioPlayer/plugin.js b/src/plugins/htmlAudioPlayer/plugin.js index 440bb4c3d0..4d31e52cae 100644 --- a/src/plugins/htmlAudioPlayer/plugin.js +++ b/src/plugins/htmlAudioPlayer/plugin.js @@ -417,10 +417,7 @@ class HtmlAudioPlayer { // This is a retry after error resume() { - const mediaElement = this._mediaElement; - if (mediaElement) { - mediaElement.play(); - } + this.unpause(); } unpause() { diff --git a/src/plugins/htmlVideoPlayer/plugin.js b/src/plugins/htmlVideoPlayer/plugin.js index 40a2c1c06b..1611684890 100644 --- a/src/plugins/htmlVideoPlayer/plugin.js +++ b/src/plugins/htmlVideoPlayer/plugin.js @@ -1690,10 +1690,7 @@ function tryRemoveElement(elem) { // This is a retry after error resume() { - const mediaElement = this.#mediaElement; - if (mediaElement) { - mediaElement.play(); - } + this.unpause(); } unpause() { diff --git a/src/scripts/editorsidebar.js b/src/scripts/editorsidebar.js index ca0db05034..10a474798c 100644 --- a/src/scripts/editorsidebar.js +++ b/src/scripts/editorsidebar.js @@ -215,19 +215,7 @@ import { getParameterByName } from '../utils/url.ts'; } } - function onNodeOpen(event, data) { - const page = $(this).parents('.page')[0]; - const node = data.node; - if (node.children) { - loadNodesToLoad(page, node); - } - if (node.li_attr && node.id != '#' && !node.li_attr.loadedFromServer) { - node.li_attr.loadedFromServer = true; - $.jstree.reference('.libraryTree', page).load_node(node.id, loadNodeCallback); - } - } - - function onNodeLoad(event, data) { + function onNodeOpen(_, data) { const page = $(this).parents('.page')[0]; const node = data.node; if (node.children) { @@ -254,7 +242,13 @@ import { getParameterByName } from '../utils/url.ts'; variant: 'large' } } - }).off('select_node.jstree', onNodeSelect).on('select_node.jstree', onNodeSelect).off('open_node.jstree', onNodeOpen).on('open_node.jstree', onNodeOpen).off('load_node.jstree', onNodeLoad).on('load_node.jstree', onNodeLoad); + }) + .off('select_node.jstree', onNodeSelect) + .on('select_node.jstree', onNodeSelect) + .off('open_node.jstree', onNodeOpen) + .on('open_node.jstree', onNodeOpen) + .off('load_node.jstree', onNodeOpen) + .on('load_node.jstree', onNodeOpen); } function loadNodesToLoad(page, node) { @@ -327,7 +321,10 @@ import { getParameterByName } from '../utils/url.ts'; }); }).on('pagebeforehide', '.metadataEditorPage', function () { const page = this; - $('.libraryTree', page).off('select_node.jstree', onNodeSelect).off('open_node.jstree', onNodeOpen).off('load_node.jstree', onNodeLoad); + $('.libraryTree', page) + .off('select_node.jstree', onNodeSelect) + .off('open_node.jstree', onNodeOpen) + .off('load_node.jstree', onNodeOpen); }); let itemId; window.MetadataEditor = {