Merge branch 'master' into migrate-to-ES6-63

This commit is contained in:
Cameron 2020-08-08 18:33:47 +01:00 committed by GitHub
commit 68271c8699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 204 additions and 190 deletions

View File

@ -125,6 +125,8 @@
"src/components/itemHelper.js", "src/components/itemHelper.js",
"src/components/itemidentifier/itemidentifier.js", "src/components/itemidentifier/itemidentifier.js",
"src/components/itemMediaInfo/itemMediaInfo.js", "src/components/itemMediaInfo/itemMediaInfo.js",
"src/components/itemsrefresher.js",
"src/components/layoutManager.js",
"src/components/lazyLoader/lazyLoaderIntersectionObserver.js", "src/components/lazyLoader/lazyLoaderIntersectionObserver.js",
"src/components/libraryoptionseditor/libraryoptionseditor.js", "src/components/libraryoptionseditor/libraryoptionseditor.js",
"src/components/listview/listview.js", "src/components/listview/listview.js",

View File

@ -2,6 +2,8 @@ define(['require', 'dom', 'focusManager', 'dialogHelper', 'loading', 'apphost',
'use strict'; 'use strict';
focusManager = focusManager.default || focusManager; focusManager = focusManager.default || focusManager;
layoutManager = layoutManager.default || layoutManager;
function onSubmit(e) { function onSubmit(e) {
e.preventDefault(); e.preventDefault();
return false; return false;

View File

@ -1,6 +1,7 @@
define(['dialogHelper', 'globalize', 'userSettings', 'layoutManager', 'connectionManager', 'require', 'loading', 'scrollHelper', 'emby-checkbox', 'emby-radio', 'css!./../formdialog', 'material-icons'], function (dialogHelper, globalize, userSettings, layoutManager, connectionManager, require, loading, scrollHelper) { define(['dialogHelper', 'globalize', 'userSettings', 'layoutManager', 'connectionManager', 'require', 'loading', 'scrollHelper', 'emby-checkbox', 'emby-radio', 'css!./../formdialog', 'material-icons'], function (dialogHelper, globalize, userSettings, layoutManager, connectionManager, require, loading, scrollHelper) {
'use strict'; 'use strict';
layoutManager = layoutManager.default || layoutManager;
scrollHelper = scrollHelper.default || scrollHelper; scrollHelper = scrollHelper.default || scrollHelper;
function saveCategories(context, options) { function saveCategories(context, options) {

View File

@ -4,6 +4,7 @@ define(['require', 'inputManager', 'browser', 'globalize', 'connectionManager',
playbackManager = playbackManager.default || playbackManager; playbackManager = playbackManager.default || playbackManager;
browser = browser.default || browser; browser = browser.default || browser;
loading = loading.default || loading; loading = loading.default || loading;
layoutManager = layoutManager.default || layoutManager;
focusManager = focusManager.default || focusManager; focusManager = focusManager.default || focusManager;
scrollHelper = scrollHelper.default || scrollHelper; scrollHelper = scrollHelper.default || scrollHelper;
serverNotifications = serverNotifications.default || serverNotifications; serverNotifications = serverNotifications.default || serverNotifications;

View File

@ -1,131 +1,130 @@
define(['playbackManager', 'serverNotifications', 'events'], function (playbackManager, serverNotifications, events) { import playbackManager from 'playbackManager';
'use strict'; import serverNotifications from 'serverNotifications';
import events from 'events';
serverNotifications = serverNotifications.default || serverNotifications; function onUserDataChanged(e, apiClient, userData) {
playbackManager = playbackManager.default || playbackManager; const instance = this;
function onUserDataChanged(e, apiClient, userData) { const eventsToMonitor = getEventsToMonitor(instance);
var instance = this;
var eventsToMonitor = getEventsToMonitor(instance);
// TODO: Check user data change reason?
if (eventsToMonitor.indexOf('markfavorite') !== -1) {
instance.notifyRefreshNeeded();
} else if (eventsToMonitor.indexOf('markplayed') !== -1) {
instance.notifyRefreshNeeded();
}
}
function getEventsToMonitor(instance) {
var options = instance.options;
var monitor = options ? options.monitorEvents : null;
if (monitor) {
return monitor.split(',');
}
return [];
}
function onTimerCreated(e, apiClient, data) {
var instance = this;
if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onSeriesTimerCreated(e, apiClient, data) {
var instance = this;
if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onTimerCancelled(e, apiClient, data) {
var instance = this;
if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onSeriesTimerCancelled(e, apiClient, data) {
var instance = this;
if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onLibraryChanged(e, apiClient, data) {
var instance = this;
var eventsToMonitor = getEventsToMonitor(instance);
if (eventsToMonitor.indexOf('seriestimers') !== -1 || eventsToMonitor.indexOf('timers') !== -1) {
// yes this is an assumption
return;
}
var itemsAdded = data.ItemsAdded || [];
var itemsRemoved = data.ItemsRemoved || [];
if (!itemsAdded.length && !itemsRemoved.length) {
return;
}
var options = instance.options || {};
var parentId = options.parentId;
if (parentId) {
var foldersAddedTo = data.FoldersAddedTo || [];
var foldersRemovedFrom = data.FoldersRemovedFrom || [];
var collectionFolders = data.CollectionFolders || [];
if (foldersAddedTo.indexOf(parentId) === -1 && foldersRemovedFrom.indexOf(parentId) === -1 && collectionFolders.indexOf(parentId) === -1) {
return;
}
}
// TODO: Check user data change reason?
if (eventsToMonitor.indexOf('markfavorite') !== -1) {
instance.notifyRefreshNeeded();
} else if (eventsToMonitor.indexOf('markplayed') !== -1) {
instance.notifyRefreshNeeded(); instance.notifyRefreshNeeded();
} }
}
function onPlaybackStopped(e, stopInfo) { function getEventsToMonitor(instance) {
var instance = this; const options = instance.options;
const monitor = options ? options.monitorEvents : null;
if (monitor) {
return monitor.split(',');
}
var state = stopInfo.state; return [];
}
var eventsToMonitor = getEventsToMonitor(instance); function onTimerCreated(e, apiClient, data) {
if (state.NowPlayingItem && state.NowPlayingItem.MediaType === 'Video') { const instance = this;
if (eventsToMonitor.indexOf('videoplayback') !== -1) {
instance.notifyRefreshNeeded(true); if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
return; instance.notifyRefreshNeeded();
} return;
} else if (state.NowPlayingItem && state.NowPlayingItem.MediaType === 'Audio') { }
if (eventsToMonitor.indexOf('audioplayback') !== -1) { }
instance.notifyRefreshNeeded(true);
return; function onSeriesTimerCreated(e, apiClient, data) {
} const instance = this;
if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onTimerCancelled(e, apiClient, data) {
const instance = this;
if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onSeriesTimerCancelled(e, apiClient, data) {
const instance = this;
if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onLibraryChanged(e, apiClient, data) {
const instance = this;
const eventsToMonitor = getEventsToMonitor(instance);
if (eventsToMonitor.indexOf('seriestimers') !== -1 || eventsToMonitor.indexOf('timers') !== -1) {
// yes this is an assumption
return;
}
const itemsAdded = data.ItemsAdded || [];
const itemsRemoved = data.ItemsRemoved || [];
if (!itemsAdded.length && !itemsRemoved.length) {
return;
}
const options = instance.options || {};
const parentId = options.parentId;
if (parentId) {
const foldersAddedTo = data.FoldersAddedTo || [];
const foldersRemovedFrom = data.FoldersRemovedFrom || [];
const collectionFolders = data.CollectionFolders || [];
if (foldersAddedTo.indexOf(parentId) === -1 && foldersRemovedFrom.indexOf(parentId) === -1 && collectionFolders.indexOf(parentId) === -1) {
return;
} }
} }
function addNotificationEvent(instance, name, handler, owner) { instance.notifyRefreshNeeded();
var localHandler = handler.bind(instance); }
function onPlaybackStopped(e, stopInfo) {
const instance = this;
const state = stopInfo.state;
const eventsToMonitor = getEventsToMonitor(instance);
if (state.NowPlayingItem && state.NowPlayingItem.MediaType === 'Video') {
if (eventsToMonitor.indexOf('videoplayback') !== -1) {
instance.notifyRefreshNeeded(true);
return;
}
} else if (state.NowPlayingItem && state.NowPlayingItem.MediaType === 'Audio') {
if (eventsToMonitor.indexOf('audioplayback') !== -1) {
instance.notifyRefreshNeeded(true);
return;
}
}
}
function addNotificationEvent(instance, name, handler, owner) {
const localHandler = handler.bind(instance);
owner = owner || serverNotifications;
events.on(owner, name, localHandler);
instance['event_' + name] = localHandler;
}
function removeNotificationEvent(instance, name, owner) {
const handler = instance['event_' + name];
if (handler) {
owner = owner || serverNotifications; owner = owner || serverNotifications;
events.on(owner, name, localHandler); events.off(owner, name, handler);
instance['event_' + name] = localHandler; instance['event_' + name] = null;
} }
}
function removeNotificationEvent(instance, name, owner) { class ItemsRefresher {
var handler = instance['event_' + name]; constructor(options) {
if (handler) {
owner = owner || serverNotifications;
events.off(owner, name, handler);
instance['event_' + name] = null;
}
}
function ItemsRefresher(options) {
this.options = options || {}; this.options = options || {};
addNotificationEvent(this, 'UserDataChanged', onUserDataChanged); addNotificationEvent(this, 'UserDataChanged', onUserDataChanged);
@ -137,18 +136,18 @@ define(['playbackManager', 'serverNotifications', 'events'], function (playbackM
addNotificationEvent(this, 'playbackstop', onPlaybackStopped, playbackManager); addNotificationEvent(this, 'playbackstop', onPlaybackStopped, playbackManager);
} }
ItemsRefresher.prototype.pause = function () { pause() {
clearRefreshInterval(this, true); clearRefreshInterval(this, true);
this.paused = true; this.paused = true;
}; }
ItemsRefresher.prototype.resume = function (options) { resume(options) {
this.paused = false; this.paused = false;
var refreshIntervalEndTime = this.refreshIntervalEndTime; const refreshIntervalEndTime = this.refreshIntervalEndTime;
if (refreshIntervalEndTime) { if (refreshIntervalEndTime) {
var remainingMs = refreshIntervalEndTime - new Date().getTime(); const remainingMs = refreshIntervalEndTime - new Date().getTime();
if (remainingMs > 0 && !this.needsRefresh) { if (remainingMs > 0 && !this.needsRefresh) {
resetRefreshInterval(this, remainingMs); resetRefreshInterval(this, remainingMs);
} else { } else {
@ -162,9 +161,9 @@ define(['playbackManager', 'serverNotifications', 'events'], function (playbackM
} }
return Promise.resolve(); return Promise.resolve();
}; }
ItemsRefresher.prototype.refreshItems = function () { refreshItems() {
if (!this.fetchData) { if (!this.fetchData) {
return Promise.resolve(); return Promise.resolve();
} }
@ -177,15 +176,15 @@ define(['playbackManager', 'serverNotifications', 'events'], function (playbackM
this.needsRefresh = false; this.needsRefresh = false;
return this.fetchData().then(onDataFetched.bind(this)); return this.fetchData().then(onDataFetched.bind(this));
}; }
ItemsRefresher.prototype.notifyRefreshNeeded = function (isInForeground) { notifyRefreshNeeded(isInForeground) {
if (this.paused) { if (this.paused) {
this.needsRefresh = true; this.needsRefresh = true;
return; return;
} }
var timeout = this.refreshTimeout; const timeout = this.refreshTimeout;
if (timeout) { if (timeout) {
clearTimeout(timeout); clearTimeout(timeout);
} }
@ -195,44 +194,9 @@ define(['playbackManager', 'serverNotifications', 'events'], function (playbackM
} else { } else {
this.refreshTimeout = setTimeout(this.refreshItems.bind(this), 10000); this.refreshTimeout = setTimeout(this.refreshItems.bind(this), 10000);
} }
};
function clearRefreshInterval(instance, isPausing) {
if (instance.refreshInterval) {
clearInterval(instance.refreshInterval);
instance.refreshInterval = null;
if (!isPausing) {
instance.refreshIntervalEndTime = null;
}
}
} }
function resetRefreshInterval(instance, intervalMs) { destroy() {
clearRefreshInterval(instance);
if (!intervalMs) {
var options = instance.options;
if (options) {
intervalMs = options.refreshIntervalMs;
}
}
if (intervalMs) {
instance.refreshInterval = setInterval(instance.notifyRefreshNeeded.bind(instance), intervalMs);
instance.refreshIntervalEndTime = new Date().getTime() + intervalMs;
}
}
function onDataFetched(result) {
resetRefreshInterval(this);
if (this.afterRefresh) {
this.afterRefresh(result);
}
}
ItemsRefresher.prototype.destroy = function () {
clearRefreshInterval(this); clearRefreshInterval(this);
removeNotificationEvent(this, 'UserDataChanged'); removeNotificationEvent(this, 'UserDataChanged');
@ -245,7 +209,42 @@ define(['playbackManager', 'serverNotifications', 'events'], function (playbackM
this.fetchData = null; this.fetchData = null;
this.options = null; this.options = null;
}; }
}
return ItemsRefresher; function clearRefreshInterval(instance, isPausing) {
}); if (instance.refreshInterval) {
clearInterval(instance.refreshInterval);
instance.refreshInterval = null;
if (!isPausing) {
instance.refreshIntervalEndTime = null;
}
}
}
function resetRefreshInterval(instance, intervalMs) {
clearRefreshInterval(instance);
if (!intervalMs) {
const options = instance.options;
if (options) {
intervalMs = options.refreshIntervalMs;
}
}
if (intervalMs) {
instance.refreshInterval = setInterval(instance.notifyRefreshNeeded.bind(instance), intervalMs);
instance.refreshIntervalEndTime = new Date().getTime() + intervalMs;
}
}
function onDataFetched(result) {
resetRefreshInterval(this);
if (this.afterRefresh) {
this.afterRefresh(result);
}
}
export default ItemsRefresher;

View File

@ -1,23 +1,19 @@
define(['browser', 'appSettings', 'events'], function (browser, appSettings, events) { import browser from 'browser';
'use strict'; import appSettings from 'appSettings';
import events from 'events';
browser = browser.default || browser; function setLayout(instance, layout, selectedLayout) {
if (layout === selectedLayout) {
function setLayout(instance, layout, selectedLayout) { instance[layout] = true;
if (layout === selectedLayout) { document.documentElement.classList.add('layout-' + layout);
instance[layout] = true; } else {
document.documentElement.classList.add('layout-' + layout); instance[layout] = false;
} else { document.documentElement.classList.remove('layout-' + layout);
instance[layout] = false;
document.documentElement.classList.remove('layout-' + layout);
}
} }
}
function LayoutManager() { class LayoutManager {
setLayout(layout, save) {
}
LayoutManager.prototype.setLayout = function (layout, save) {
if (!layout || layout === 'auto') { if (!layout || layout === 'auto') {
this.autoLayout(); this.autoLayout();
@ -35,13 +31,13 @@ define(['browser', 'appSettings', 'events'], function (browser, appSettings, eve
} }
events.trigger(this, 'modechange'); events.trigger(this, 'modechange');
}; }
LayoutManager.prototype.getSavedLayout = function (layout) { getSavedLayout(layout) {
return appSettings.get('layout'); return appSettings.get('layout');
}; }
LayoutManager.prototype.autoLayout = function () { autoLayout() {
// Take a guess at initial layout. The consuming app can override // Take a guess at initial layout. The consuming app can override
if (browser.mobile) { if (browser.mobile) {
this.setLayout('mobile', false); this.setLayout('mobile', false);
@ -50,16 +46,16 @@ define(['browser', 'appSettings', 'events'], function (browser, appSettings, eve
} else { } else {
this.setLayout(this.defaultLayout || 'tv', false); this.setLayout(this.defaultLayout || 'tv', false);
} }
}; }
LayoutManager.prototype.init = function () { init() {
var saved = this.getSavedLayout(); const saved = this.getSavedLayout();
if (saved) { if (saved) {
this.setLayout(saved, false); this.setLayout(saved, false);
} else { } else {
this.autoLayout(); this.autoLayout();
} }
}; }
}
return new LayoutManager(); export default new LayoutManager();
});

View File

@ -1,6 +1,7 @@
define(['dialogHelper', 'globalize', 'layoutManager', 'mediaInfo', 'apphost', 'connectionManager', 'require', 'loading', 'scrollHelper', 'datetime', 'imageLoader', 'recordingFields', 'events', 'emby-checkbox', 'emby-button', 'emby-collapse', 'emby-input', 'paper-icon-button-light', 'css!./../formdialog', 'css!./recordingcreator', 'material-icons'], function (dialogHelper, globalize, layoutManager, mediaInfo, appHost, connectionManager, require, loading, scrollHelper, datetime, imageLoader, recordingFields, events) { define(['dialogHelper', 'globalize', 'layoutManager', 'mediaInfo', 'apphost', 'connectionManager', 'require', 'loading', 'scrollHelper', 'datetime', 'imageLoader', 'recordingFields', 'events', 'emby-checkbox', 'emby-button', 'emby-collapse', 'emby-input', 'paper-icon-button-light', 'css!./../formdialog', 'css!./recordingcreator', 'material-icons'], function (dialogHelper, globalize, layoutManager, mediaInfo, appHost, connectionManager, require, loading, scrollHelper, datetime, imageLoader, recordingFields, events) {
'use strict'; 'use strict';
layoutManager = layoutManager.default || layoutManager;
scrollHelper = scrollHelper.default || scrollHelper; scrollHelper = scrollHelper.default || scrollHelper;
var currentDialog; var currentDialog;

View File

@ -3,6 +3,7 @@ define(['dialogHelper', 'globalize', 'layoutManager', 'mediaInfo', 'apphost', 'c
scrollHelper = scrollHelper.default || scrollHelper; scrollHelper = scrollHelper.default || scrollHelper;
loading = loading.default || loading; loading = loading.default || loading;
layoutManager = layoutManager.default || layoutManager;
var currentDialog; var currentDialog;
var recordingDeleted = false; var recordingDeleted = false;

View File

@ -2,6 +2,7 @@ define(['browser', 'datetime', 'backdrop', 'libraryBrowser', 'listView', 'imageL
'use strict'; 'use strict';
playbackManager = playbackManager.default || playbackManager; playbackManager = playbackManager.default || playbackManager;
layoutManager = layoutManager.default || layoutManager;
var showMuteButton = true; var showMuteButton = true;
var showVolumeSlider = true; var showVolumeSlider = true;

View File

@ -1,6 +1,8 @@
define(['backdrop', 'mainTabsManager', 'layoutManager', 'emby-tabs'], function (backdrop, mainTabsManager, layoutManager) { define(['backdrop', 'mainTabsManager', 'layoutManager', 'emby-tabs'], function (backdrop, mainTabsManager, layoutManager) {
'use strict'; 'use strict';
layoutManager = layoutManager.default || layoutManager;
function onViewDestroy(e) { function onViewDestroy(e) {
var tabControllers = this.tabControllers; var tabControllers = this.tabControllers;

View File

@ -3,6 +3,7 @@ define(['dialogHelper', 'dom', 'layoutManager', 'connectionManager', 'globalize'
browser = browser.default || browser; browser = browser.default || browser;
loading = loading.default || loading; loading = loading.default || loading;
layoutManager = layoutManager.default || layoutManager;
focusManager = focusManager.default || focusManager; focusManager = focusManager.default || focusManager;
scrollHelper = scrollHelper.default || scrollHelper; scrollHelper = scrollHelper.default || scrollHelper;

View File

@ -1,6 +1,8 @@
define(['require', 'dialogHelper', 'loading', 'apphost', 'layoutManager', 'connectionManager', 'appRouter', 'globalize', 'userSettings', 'emby-checkbox', 'emby-input', 'paper-icon-button-light', 'emby-select', 'material-icons', 'css!./../formdialog', 'emby-button', 'flexStyles'], function (require, dialogHelper, loading, appHost, layoutManager, connectionManager, appRouter, globalize, userSettings) { define(['require', 'dialogHelper', 'loading', 'apphost', 'layoutManager', 'connectionManager', 'appRouter', 'globalize', 'userSettings', 'emby-checkbox', 'emby-input', 'paper-icon-button-light', 'emby-select', 'material-icons', 'css!./../formdialog', 'emby-button', 'flexStyles'], function (require, dialogHelper, loading, appHost, layoutManager, connectionManager, appRouter, globalize, userSettings) {
'use strict'; 'use strict';
layoutManager = layoutManager.default || layoutManager;
function onSubmit(e) { function onSubmit(e) {
e.preventDefault(); e.preventDefault();
return false; return false;

View File

@ -2,6 +2,7 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
'use strict'; 'use strict';
loading = loading.default || loading; loading = loading.default || loading;
layoutManager = layoutManager.default || layoutManager;
function enableScrollX() { function enableScrollX() {
return !layoutManager.desktop; return !layoutManager.desktop;

View File

@ -4,6 +4,7 @@ define(['dom', 'layoutManager', 'inputManager', 'connectionManager', 'events', '
viewManager = viewManager.default || viewManager; viewManager = viewManager.default || viewManager;
playbackManager = playbackManager.default || playbackManager; playbackManager = playbackManager.default || playbackManager;
browser = browser.default || browser; browser = browser.default || browser;
layoutManager = layoutManager.default || layoutManager;
function renderHeader() { function renderHeader() {
var html = ''; var html = '';

View File

@ -1,6 +1,8 @@
define(['layoutManager', 'datetime', 'cardBuilder', 'apphost'], function (layoutManager, datetime, cardBuilder, appHost) { define(['layoutManager', 'datetime', 'cardBuilder', 'apphost'], function (layoutManager, datetime, cardBuilder, appHost) {
'use strict'; 'use strict';
layoutManager = layoutManager.default || layoutManager;
function enableScrollX() { function enableScrollX() {
return !layoutManager.desktop; return !layoutManager.desktop;
} }

View File

@ -350,6 +350,7 @@ function initClient() {
} }
function getLayoutManager(layoutManager, appHost) { function getLayoutManager(layoutManager, appHost) {
layoutManager = layoutManager.default || layoutManager;
if (appHost.getDefaultLayout) { if (appHost.getDefaultLayout) {
layoutManager.defaultLayout = appHost.getDefaultLayout(); layoutManager.defaultLayout = appHost.getDefaultLayout();
} }