diff --git a/dashboard-ui/components/subtitleeditor/subtitleeditor.js b/dashboard-ui/components/subtitleeditor/subtitleeditor.js index bebc02de00..29044947b3 100644 --- a/dashboard-ui/components/subtitleeditor/subtitleeditor.js +++ b/dashboard-ui/components/subtitleeditor/subtitleeditor.js @@ -1,4 +1,4 @@ -define(['paperdialoghelper', 'paper-fab', 'paper-item-body', 'paper-icon-item'], function (paperDialogHelper) { +define(['paperdialoghelper', 'appStorage', 'paper-fab', 'paper-item-body', 'paper-icon-item'], function (paperDialogHelper, appStorage) { var currentItem; diff --git a/dashboard-ui/devices/ie/ie.js b/dashboard-ui/devices/ie/ie.js index b2d12d0801..c0d5edd9d4 100644 --- a/dashboard-ui/devices/ie/ie.js +++ b/dashboard-ui/devices/ie/ie.js @@ -1,4 +1,4 @@ -define(['browser'], function (browser) { +define(['browser', 'appStorage'], function (browser, appStorage) { require(['css!devices/ie/ie.css']); var browserSwitchKey = "ieswitchbrowser"; diff --git a/dashboard-ui/scripts/backdrops.js b/dashboard-ui/scripts/backdrops.js index 759741e744..c2e0bfbac2 100644 --- a/dashboard-ui/scripts/backdrops.js +++ b/dashboard-ui/scripts/backdrops.js @@ -1,4 +1,4 @@ -(function ($, document) { +define(['appStorage'], function (appStorage) { var pageBackgroundCreated; @@ -246,4 +246,4 @@ clear: clearBackdrop }; -})(jQuery, document); \ No newline at end of file +}); \ No newline at end of file diff --git a/dashboard-ui/scripts/librarybrowser.js b/dashboard-ui/scripts/librarybrowser.js index d423f7b3c6..803b175c08 100644 --- a/dashboard-ui/scripts/librarybrowser.js +++ b/dashboard-ui/scripts/librarybrowser.js @@ -1,4 +1,4 @@ -define(['playlistManager', 'appSettings'], function (playlistManager, appSettings) { +define(['playlistManager', 'appSettings', 'appStorage'], function (playlistManager, appSettings, appStorage) { var libraryBrowser = (function (window, document, screen) { diff --git a/dashboard-ui/scripts/librarylist.js b/dashboard-ui/scripts/librarylist.js index 3ac3972e30..f2dbcdb517 100644 --- a/dashboard-ui/scripts/librarylist.js +++ b/dashboard-ui/scripts/librarylist.js @@ -1,4 +1,4 @@ -define(['appSettings'], function (appSettings) { +define(['appSettings', 'appStorage'], function (appSettings, appStorage) { var showOverlayTimeout; diff --git a/dashboard-ui/scripts/mediacontroller.js b/dashboard-ui/scripts/mediacontroller.js index e51e02611b..3263a910ed 100644 --- a/dashboard-ui/scripts/mediacontroller.js +++ b/dashboard-ui/scripts/mediacontroller.js @@ -1,4 +1,4 @@ -(function (window) { +define(['appStorage'], function (appStorage) { var currentDisplayInfo; function mirrorItem(info) { @@ -1061,4 +1061,4 @@ mirrorIfEnabled(info); }); -})(this); \ No newline at end of file +}); \ No newline at end of file diff --git a/dashboard-ui/scripts/mediaplayer.js b/dashboard-ui/scripts/mediaplayer.js index abfe888eec..6859af0609 100644 --- a/dashboard-ui/scripts/mediaplayer.js +++ b/dashboard-ui/scripts/mediaplayer.js @@ -1,4 +1,4 @@ -define(['appSettings', 'userSettings'], function (appSettings, userSettings) { +define(['appSettings', 'userSettings', 'appStorage'], function (appSettings, userSettings, appStorage) { function mediaPlayer() { @@ -1729,7 +1729,7 @@ define(['appSettings', 'userSettings'], function (appSettings, userSettings) { window.MediaPlayer = new mediaPlayer(); - window.MediaPlayer.init = function() { + window.MediaPlayer.init = function () { window.MediaController.registerPlayer(window.MediaPlayer); window.MediaController.setActivePlayer(window.MediaPlayer, window.MediaPlayer.getTargetsInternal()[0]); }; diff --git a/dashboard-ui/scripts/mypreferencesdisplay.js b/dashboard-ui/scripts/mypreferencesdisplay.js index 6e873dd353..887e177d76 100644 --- a/dashboard-ui/scripts/mypreferencesdisplay.js +++ b/dashboard-ui/scripts/mypreferencesdisplay.js @@ -1,4 +1,4 @@ -define(['userSettings'], function (userSettings) { +define(['userSettings', 'appStorage'], function (userSettings, appStorage) { function loadForm(page, user) { diff --git a/dashboard-ui/scripts/playlistedit.js b/dashboard-ui/scripts/playlistedit.js index 2b05693aa1..f2e72ef395 100644 --- a/dashboard-ui/scripts/playlistedit.js +++ b/dashboard-ui/scripts/playlistedit.js @@ -1,4 +1,4 @@ -(function ($, document) { +define(['appStorage'], function (appStorage) { var data = {}; function getPageData() { @@ -197,4 +197,4 @@ } }; -})(jQuery, document); \ No newline at end of file +}); \ No newline at end of file diff --git a/dashboard-ui/scripts/registrationservices.js b/dashboard-ui/scripts/registrationservices.js index 3e9265e3dc..95e606826d 100644 --- a/dashboard-ui/scripts/registrationservices.js +++ b/dashboard-ui/scripts/registrationservices.js @@ -1,4 +1,4 @@ -(function () { +define(['appStorage'], function (appStorage) { var supporterPlaybackKey = 'lastSupporterPlaybackMessage4'; @@ -297,4 +297,4 @@ } }; -})(); \ No newline at end of file +}); \ No newline at end of file diff --git a/dashboard-ui/scripts/site.js b/dashboard-ui/scripts/site.js index 6a662b8da5..bc3a714cf7 100644 --- a/dashboard-ui/scripts/site.js +++ b/dashboard-ui/scripts/site.js @@ -2332,58 +2332,60 @@ var AppInfo = {}; return new Promise(function (resolve, reject) { - var deviceName; + require(['appStorage'], function (appStorage) { + var deviceName; - if (browserInfo.chrome) { - deviceName = "Chrome"; - } else if (browserInfo.edge) { - deviceName = "Edge"; - } else if (browserInfo.firefox) { - deviceName = "Firefox"; - } else if (browserInfo.msie) { - deviceName = "Internet Explorer"; - } else { - deviceName = "Web Browser"; - } + if (browserInfo.chrome) { + deviceName = "Chrome"; + } else if (browserInfo.edge) { + deviceName = "Edge"; + } else if (browserInfo.firefox) { + deviceName = "Firefox"; + } else if (browserInfo.msie) { + deviceName = "Internet Explorer"; + } else { + deviceName = "Web Browser"; + } - if (browserInfo.version) { - deviceName += " " + browserInfo.version; - } + if (browserInfo.version) { + deviceName += " " + browserInfo.version; + } - if (browserInfo.ipad) { - deviceName += " Ipad"; - } else if (browserInfo.iphone) { - deviceName += " Iphone"; - } else if (browserInfo.android) { - deviceName += " Android"; - } + if (browserInfo.ipad) { + deviceName += " Ipad"; + } else if (browserInfo.iphone) { + deviceName += " Iphone"; + } else if (browserInfo.android) { + deviceName += " Android"; + } - function onDeviceAdAcquired(id) { + function onDeviceAdAcquired(id) { - resolve({ - deviceId: id, - deviceName: deviceName, - appName: "Emby Web Client", - appVersion: window.dashboardVersion - }); - } + resolve({ + deviceId: id, + deviceName: deviceName, + appName: "Emby Web Client", + appVersion: window.dashboardVersion + }); + } - var deviceIdKey = '_deviceId1'; - var deviceId = appStorage.getItem(deviceIdKey); + var deviceIdKey = '_deviceId1'; + var deviceId = appStorage.getItem(deviceIdKey); - if (deviceId) { - onDeviceAdAcquired(deviceId); - } else { - require(['cryptojs-sha1'], function () { - var keys = []; - keys.push(navigator.userAgent); - keys.push((navigator.cpuClass || "")); - keys.push(new Date().getTime()); - var randomId = CryptoJS.SHA1(keys.join('|')).toString(); - appStorage.setItem(deviceIdKey, randomId); - onDeviceAdAcquired(randomId); - }); - } + if (deviceId) { + onDeviceAdAcquired(deviceId); + } else { + require(['cryptojs-sha1'], function () { + var keys = []; + keys.push(navigator.userAgent); + keys.push((navigator.cpuClass || "")); + keys.push(new Date().getTime()); + var randomId = CryptoJS.SHA1(keys.join('|')).toString(); + appStorage.setItem(deviceIdKey, randomId); + onDeviceAdAcquired(randomId); + }); + } + }); }); } @@ -2403,18 +2405,16 @@ var AppInfo = {}; var initialDependencies = []; initialDependencies.push('browser'); - initialDependencies.push('appStorage'); if (!window.Promise) { initialDependencies.push('native-promise-only'); } - require(initialDependencies, function (browser, appStorage) { + require(initialDependencies, function (browser) { initRequireWithBrowser(browser); window.browserInfo = browser; - window.appStorage = appStorage; setAppInfo(); setDocumentClasses(); diff --git a/dashboard-ui/scripts/taskbutton.js b/dashboard-ui/scripts/taskbutton.js index 04a2a47eb1..f28fed34c7 100644 --- a/dashboard-ui/scripts/taskbutton.js +++ b/dashboard-ui/scripts/taskbutton.js @@ -1,175 +1,178 @@ -$.fn.taskButton = function (options) { +define(['appStorage'], function (appStorage) { - function pollTasks(button) { + $.fn.taskButton = function (options) { - ApiClient.getScheduledTasks({ + function pollTasks(button) { - IsEnabled: true + ApiClient.getScheduledTasks({ - }).then(function (tasks) { + IsEnabled: true - updateTasks(button, tasks); - }); + }).then(function (tasks) { - } + updateTasks(button, tasks); + }); - function updateTasks(button, tasks) { + } - var task = tasks.filter(function (t) { + function updateTasks(button, tasks) { - return t.Key == options.taskKey; + var task = tasks.filter(function (t) { - })[0]; + return t.Key == options.taskKey; - if (options.panel) { - if (task) { - $(options.panel).show(); + })[0]; + + if (options.panel) { + if (task) { + $(options.panel).show(); + } else { + $(options.panel).hide(); + } + } + + if (!task) { + return; + } + + if (task.State == 'Idle') { + $(button).removeAttr('disabled'); } else { - $(options.panel).hide(); + $(button).attr('disabled', 'disabled'); + } + + $(button).attr('data-taskid', task.Id); + + var progress = (task.CurrentProgressPercentage || 0).toFixed(1); + + if (options.progressElem) { + options.progressElem.value = progress; + + if (task.State == 'Running') { + options.progressElem.classList.remove('hide'); + } else { + options.progressElem.classList.add('hide'); + } + } + + if (options.lastResultElem) { + var lastResult = task.LastExecutionResult ? task.LastExecutionResult.Status : ''; + + if (lastResult == "Failed") { + options.lastResultElem.html('' + Globalize.translate('LabelFailed') + ''); + } + else if (lastResult == "Cancelled") { + options.lastResultElem.html('' + Globalize.translate('LabelCancelled') + ''); + } + else if (lastResult == "Aborted") { + options.lastResultElem.html('' + Globalize.translate('LabelAbortedByServerShutdown') + ''); + } else { + options.lastResultElem.html(lastResult); + } } } - if (!task) { - return; - } - - if (task.State == 'Idle') { - $(button).removeAttr('disabled'); - } else { - $(button).attr('disabled', 'disabled'); - } - - $(button).attr('data-taskid', task.Id); - - var progress = (task.CurrentProgressPercentage || 0).toFixed(1); - - if (options.progressElem) { - options.progressElem.value = progress; - - if (task.State == 'Running') { - options.progressElem.classList.remove('hide'); - } else { - options.progressElem.classList.add('hide'); - } - } - - if (options.lastResultElem) { - var lastResult = task.LastExecutionResult ? task.LastExecutionResult.Status : ''; - - if (lastResult == "Failed") { - options.lastResultElem.html('' + Globalize.translate('LabelFailed') + ''); - } - else if (lastResult == "Cancelled") { - options.lastResultElem.html('' + Globalize.translate('LabelCancelled') + ''); - } - else if (lastResult == "Aborted") { - options.lastResultElem.html('' + Globalize.translate('LabelAbortedByServerShutdown') + ''); - } else { - options.lastResultElem.html(lastResult); - } - } - } - - function onScheduledTaskMessageConfirmed(instance, id) { - ApiClient.startScheduledTask(id).then(function () { - - pollTasks(instance); - }); - } - - function onButtonClick() { - - var button = this; - var id = button.getAttribute('data-taskid'); - - var key = 'scheduledTaskButton' + options.taskKey; - var expectedValue = new Date().getMonth() + '5'; - - if (appStorage.getItem(key) == expectedValue) { - onScheduledTaskMessageConfirmed(button, id); - } else { - - var msg = Globalize.translate('ConfirmMessageScheduledTaskButton'); - msg += '
'; - msg += '
'; - msg += '' + Globalize.translate('ButtonScheduledTasks') + ''; - msg += '
'; - - require(['confirm'], function (confirm) { - - confirm(msg, Globalize.translate('HeaderConfirmation')).then(function () { - appStorage.setItem(key, expectedValue); - onScheduledTaskMessageConfirmed(button, id); - }); + function onScheduledTaskMessageConfirmed(instance, id) { + ApiClient.startScheduledTask(id).then(function () { + pollTasks(instance); }); } - } - function onSocketOpen() { - startInterval(); - } + function onButtonClick() { - function onSocketMessage(e, msg) { - if (msg.MessageType == "ScheduledTasksInfo") { + var button = this; + var id = button.getAttribute('data-taskid'); - var tasks = msg.Data; + var key = 'scheduledTaskButton' + options.taskKey; + var expectedValue = new Date().getMonth() + '5'; - updateTasks(self, tasks); + if (appStorage.getItem(key) == expectedValue) { + onScheduledTaskMessageConfirmed(button, id); + } else { + + var msg = Globalize.translate('ConfirmMessageScheduledTaskButton'); + msg += '
'; + msg += '
'; + msg += '' + Globalize.translate('ButtonScheduledTasks') + ''; + msg += '
'; + + require(['confirm'], function (confirm) { + + confirm(msg, Globalize.translate('HeaderConfirmation')).then(function () { + appStorage.setItem(key, expectedValue); + onScheduledTaskMessageConfirmed(button, id); + }); + + }); + } } - } - var self = this; - var pollInterval; + function onSocketOpen() { + startInterval(); + } - function onPollIntervalFired() { + function onSocketMessage(e, msg) { + if (msg.MessageType == "ScheduledTasksInfo") { + + var tasks = msg.Data; + + updateTasks(self, tasks); + } + } + + var self = this; + var pollInterval; + + function onPollIntervalFired() { + + if (!ApiClient.isWebSocketOpen()) { + pollTasks(self); + } + } + + function startInterval() { + if (ApiClient.isWebSocketOpen()) { + ApiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "1000,1000"); + } + if (pollInterval) { + clearInterval(pollInterval); + } + pollInterval = setInterval(onPollIntervalFired, 5000); + } + + function stopInterval() { + if (ApiClient.isWebSocketOpen()) { + ApiClient.sendWebSocketMessage("ScheduledTasksInfoStop"); + } + if (pollInterval) { + clearInterval(pollInterval); + } + } + + if (options.panel) { + $(options.panel).hide(); + } + + if (options.mode == 'off') { + + this.off('click', onButtonClick); + Events.off(ApiClient, 'websocketmessage', onSocketMessage); + Events.off(ApiClient, 'websocketopen', onSocketOpen); + stopInterval(); + + } else if (this.length) { + + this.on('click', onButtonClick); - if (!ApiClient.isWebSocketOpen()) { pollTasks(self); + + startInterval(); + + Events.on(ApiClient, 'websocketmessage', onSocketMessage); + Events.on(ApiClient, 'websocketopen', onSocketOpen); } - } - function startInterval() { - if (ApiClient.isWebSocketOpen()) { - ApiClient.sendWebSocketMessage("ScheduledTasksInfoStart", "1000,1000"); - } - if (pollInterval) { - clearInterval(pollInterval); - } - pollInterval = setInterval(onPollIntervalFired, 5000); - } - - function stopInterval() { - if (ApiClient.isWebSocketOpen()) { - ApiClient.sendWebSocketMessage("ScheduledTasksInfoStop"); - } - if (pollInterval) { - clearInterval(pollInterval); - } - } - - if (options.panel) { - $(options.panel).hide(); - } - - if (options.mode == 'off') { - - this.off('click', onButtonClick); - Events.off(ApiClient, 'websocketmessage', onSocketMessage); - Events.off(ApiClient, 'websocketopen', onSocketOpen); - stopInterval(); - - } else if (this.length) { - - this.on('click', onButtonClick); - - pollTasks(self); - - startInterval(); - - Events.on(ApiClient, 'websocketmessage', onSocketMessage); - Events.on(ApiClient, 'websocketopen', onSocketOpen); - } - - return this; -}; \ No newline at end of file + return this; + }; +}); \ No newline at end of file diff --git a/dashboard-ui/scripts/thememediaplayer.js b/dashboard-ui/scripts/thememediaplayer.js index e2e4f0db37..5d6eabf682 100644 --- a/dashboard-ui/scripts/thememediaplayer.js +++ b/dashboard-ui/scripts/thememediaplayer.js @@ -1,4 +1,4 @@ -(function (document) { +define(['appStorage'], function (appStorage) { var currentOwnerId; var currentThemeIds = []; @@ -73,4 +73,4 @@ } }); -})(document); \ No newline at end of file +}); \ No newline at end of file