1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Migrate shell, serverNotifications to ES6 + remove searchtab

This commit is contained in:
MrTimscampi 2020-07-26 22:45:00 +02:00
parent 18a84eeb32
commit 8fb8dacdf1
15 changed files with 239 additions and 312 deletions

View file

@ -250,9 +250,11 @@
"src/scripts/inputManager.js",
"src/scripts/keyboardNavigation.js",
"src/scripts/playlists.js",
"src/scripts/serverNotifications.js",
"src/scripts/settings/appSettings.js",
"src/scripts/settings/userSettings.js",
"src/scripts/settings/webSettings.js",
"src/scripts/shell.js",
"src/scripts/taskbutton.js",
"src/scripts/themeLoader.js",
"src/scripts/touchHelper.js"

View file

@ -236,12 +236,6 @@
text-align: center;
}
.layout-desktop .searchTabButton,
.layout-mobile .searchTabButton,
.layout-tv .headerSearchButton {
display: none !important;
}
.mainDrawer-scrollContainer {
padding-bottom: 10vh;
}

View file

@ -1,6 +1,8 @@
define(['require', 'inputManager', 'browser', 'globalize', 'connectionManager', 'scrollHelper', 'serverNotifications', 'loading', 'datetime', 'focusManager', 'playbackManager', 'userSettings', 'imageLoader', 'events', 'layoutManager', 'itemShortcuts', 'dom', 'css!./guide.css', 'programStyles', 'material-icons', 'scrollStyles', 'emby-programcell', 'emby-button', 'paper-icon-button-light', 'emby-tabs', 'emby-scroller', 'flexStyles', 'webcomponents'], function (require, inputManager, browser, globalize, connectionManager, scrollHelper, serverNotifications, loading, datetime, focusManager, playbackManager, userSettings, imageLoader, events, layoutManager, itemShortcuts, dom) {
'use strict';
serverNotifications = serverNotifications.default || serverNotifications;
function showViewSettings(instance) {
require(['guide-settings-dialog'], function (guideSettingsDialog) {

View file

@ -1,6 +1,8 @@
define(['playbackManager', 'serverNotifications', 'events'], function (playbackManager, serverNotifications, events) {
'use strict';
serverNotifications = serverNotifications.default || serverNotifications;
function onUserDataChanged(e, apiClient, userData) {
var instance = this;

View file

@ -1,6 +1,8 @@
define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'require'], function (serverNotifications, playbackManager, events, globalize, require) {
'use strict';
serverNotifications = serverNotifications.default || serverNotifications;
function onOneDocumentClick() {
document.removeEventListener('click', onOneDocumentClick);
document.removeEventListener('keydown', onOneDocumentClick);

View file

@ -3455,6 +3455,7 @@ define(['events', 'datetime', 'appSettings', 'itemHelper', 'pluginManager', 'pla
if (apphost.supports('remotecontrol')) {
require(['serverNotifications'], function (serverNotifications) {
serverNotifications = serverNotifications.default || serverNotifications;
events.on(serverNotifications, 'ServerShuttingDown', self.setDefaultPlayerActive.bind(self));
events.on(serverNotifications, 'ServerRestarting', self.setDefaultPlayerActive.bind(self));
});

View file

@ -1,6 +1,8 @@
define(['globalize', 'connectionManager', 'serverNotifications', 'require', 'loading', 'apphost', 'dom', 'recordingHelper', 'events', 'paper-icon-button-light', 'emby-button', 'css!./recordingfields', 'flexStyles'], function (globalize, connectionManager, serverNotifications, require, loading, appHost, dom, recordingHelper, events) {
'use strict';
serverNotifications = serverNotifications.default || serverNotifications;
function loadData(parent, program, apiClient) {
if (program.IsSeries) {
parent.querySelector('.recordSeriesContainer').classList.remove('hide');

View file

@ -167,9 +167,6 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
name: globalize.translate('HeaderSchedule')
}, {
name: globalize.translate('TabSeries')
}, {
name: globalize.translate('ButtonSearch'),
cssClass: 'searchTabButton'
}];
}
@ -253,9 +250,6 @@ define(['layoutManager', 'userSettings', 'inputManager', 'loading', 'globalize',
case 5:
depends.push('controllers/livetv/livetvseriestimers');
break;
case 6:
depends.push('scripts/searchtab');
}
require(depends, function (controllerFactory) {

View file

@ -222,9 +222,6 @@ define(['events', 'layoutManager', 'inputManager', 'userSettings', 'libraryMenu'
name: globalize.translate('TabCollections')
}, {
name: globalize.translate('TabGenres')
}, {
name: globalize.translate('ButtonSearch'),
cssClass: 'searchTabButton'
}];
}
@ -291,9 +288,6 @@ define(['events', 'layoutManager', 'inputManager', 'userSettings', 'libraryMenu'
case 5:
depends.push('controllers/movies/moviegenres');
break;
case 6:
depends.push('scripts/searchtab');
}
require(depends, function (controllerFactory) {

View file

@ -180,9 +180,6 @@ define(['browser', 'layoutManager', 'userSettings', 'inputManager', 'loading', '
name: globalize.translate('TabSongs')
}, {
name: globalize.translate('TabGenres')
}, {
name: globalize.translate('ButtonSearch'),
cssClass: 'searchTabButton'
}];
}
@ -283,9 +280,6 @@ define(['browser', 'layoutManager', 'userSettings', 'inputManager', 'loading', '
case 6:
depends.push('controllers/music/musicgenres');
break;
case 7:
depends.push('scripts/searchtab');
}
require(depends, function (controllerFactory) {

View file

@ -30,9 +30,6 @@ import 'emby-button';
name: globalize.translate('TabNetworks')
}, {
name: globalize.translate('TabEpisodes')
}, {
name: globalize.translate('ButtonSearch'),
cssClass: 'searchTabButton'
}];
}
@ -217,10 +214,6 @@ import 'emby-button';
case 6:
depends = 'controllers/shows/episodes';
break;
case 7:
depends = 'scripts/searchtab';
break;
}
import(depends).then(({default: controllerFactory}) => {

View file

@ -1,6 +1,8 @@
define(['playbackManager', 'events', 'serverNotifications', 'connectionManager'], function (playbackManager, events, serverNotifications, connectionManager) {
'use strict';
serverNotifications = serverNotifications.default || serverNotifications;
function getActivePlayerId() {
var info = playbackManager.getPlayerInfo();
return info ? info.id : null;

View file

@ -1,57 +0,0 @@
define(['searchFields', 'searchResults', 'events'], function (SearchFields, SearchResults, events) {
'use strict';
SearchFields = SearchFields.default || SearchFields;
SearchResults = SearchResults.default || SearchResults;
function init(instance, tabContent, options) {
tabContent.innerHTML = '<div class="padded-left padded-right searchFields"></div><div class="searchResults padded-top" style="padding-top:1.5em;"></div>';
instance.searchFields = new SearchFields({
element: tabContent.querySelector('.searchFields')
});
instance.searchResults = new SearchResults({
element: tabContent.querySelector('.searchResults'),
serverId: ApiClient.serverId(),
parentId: options.parentId,
collectionType: options.collectionType
});
events.on(instance.searchFields, 'search', function (e, value) {
instance.searchResults.search(value);
});
}
function SearchTab(view, tabContent, options) {
var self = this;
options = options || {};
init(this, tabContent, options);
self.preRender = function () {};
self.renderTab = function () {
var searchFields = this.searchFields;
if (searchFields) {
searchFields.focus();
}
};
}
SearchTab.prototype.destroy = function () {
var searchFields = this.searchFields;
if (searchFields) {
searchFields.destroy();
}
this.searchFields = null;
var searchResults = this.searchResults;
if (searchResults) {
searchResults.destroy();
}
this.searchResults = null;
};
return SearchTab;
});

View file

@ -1,211 +1,216 @@
define(['connectionManager', 'playbackManager', 'syncPlayManager', 'events', 'inputManager', 'focusManager', 'appRouter'], function (connectionManager, playbackManager, syncPlayManager, events, inputManager, focusManager, appRouter) {
'use strict';
import connectionManager from 'connectionManager';
import playbackManager from 'playbackManager';
import syncPlayManager from 'syncPlayManager';
import events from 'events';
import inputManager from 'inputManager';
import focusManager from 'focusManager';
import appRouter from 'appRouter';
var serverNotifications = {};
const serverNotifications = {};
function notifyApp() {
inputManager.notify();
}
function notifyApp() {
inputManager.notify();
}
function displayMessage(cmd) {
var args = cmd.Arguments;
if (args.TimeoutMs) {
require(['toast'], function (toast) {
toast({ title: args.Header, text: args.Text });
});
} else {
require(['alert'], function (alert) {
alert.default({ title: args.Header, text: args.Text });
});
}
}
function displayContent(cmd, apiClient) {
if (!playbackManager.isPlayingLocally(['Video', 'Book'])) {
appRouter.showItem(cmd.Arguments.ItemId, apiClient.serverId());
}
}
function playTrailers(apiClient, itemId) {
apiClient.getItem(apiClient.getCurrentUserId(), itemId).then(function (item) {
playbackManager.playTrailers(item);
function displayMessage(cmd) {
const args = cmd.Arguments;
if (args.TimeoutMs) {
require(['toast'], function (toast) {
toast({ title: args.Header, text: args.Text });
});
} else {
require(['alert'], function (alert) {
alert.default({ title: args.Header, text: args.Text });
});
}
}
function processGeneralCommand(cmd, apiClient) {
console.debug('Received command: ' + cmd.Name);
switch (cmd.Name) {
case 'Select':
inputManager.handleCommand('select');
return;
case 'Back':
inputManager.handleCommand('back');
return;
case 'MoveUp':
inputManager.handleCommand('up');
return;
case 'MoveDown':
inputManager.handleCommand('down');
return;
case 'MoveLeft':
inputManager.handleCommand('left');
return;
case 'MoveRight':
inputManager.handleCommand('right');
return;
case 'PageUp':
inputManager.handleCommand('pageup');
return;
case 'PageDown':
inputManager.handleCommand('pagedown');
return;
case 'PlayTrailers':
playTrailers(apiClient, cmd.Arguments.ItemId);
break;
case 'SetRepeatMode':
playbackManager.setRepeatMode(cmd.Arguments.RepeatMode);
break;
case 'SetShuffleQueue':
playbackManager.setQueueShuffleMode(cmd.Arguments.ShuffleMode);
break;
case 'VolumeUp':
inputManager.handleCommand('volumeup');
return;
case 'VolumeDown':
inputManager.handleCommand('volumedown');
return;
case 'ChannelUp':
inputManager.handleCommand('channelup');
return;
case 'ChannelDown':
inputManager.handleCommand('channeldown');
return;
case 'Mute':
inputManager.handleCommand('mute');
return;
case 'Unmute':
inputManager.handleCommand('unmute');
return;
case 'ToggleMute':
inputManager.handleCommand('togglemute');
return;
case 'SetVolume':
notifyApp();
playbackManager.setVolume(cmd.Arguments.Volume);
break;
case 'SetAudioStreamIndex':
notifyApp();
playbackManager.setAudioStreamIndex(parseInt(cmd.Arguments.Index));
break;
case 'SetSubtitleStreamIndex':
notifyApp();
playbackManager.setSubtitleStreamIndex(parseInt(cmd.Arguments.Index));
break;
case 'ToggleFullscreen':
inputManager.handleCommand('togglefullscreen');
return;
case 'GoHome':
inputManager.handleCommand('home');
return;
case 'GoToSettings':
inputManager.handleCommand('settings');
return;
case 'DisplayContent':
displayContent(cmd, apiClient);
break;
case 'GoToSearch':
inputManager.handleCommand('search');
return;
case 'DisplayMessage':
displayMessage(cmd);
break;
case 'ToggleOsd':
// todo
break;
case 'ToggleContextMenu':
// todo
break;
case 'TakeScreenShot':
// todo
break;
case 'SendKey':
// todo
break;
case 'SendString':
// todo
focusManager.sendText(cmd.Arguments.String);
break;
default:
console.debug('processGeneralCommand does not recognize: ' + cmd.Name);
break;
}
notifyApp();
function displayContent(cmd, apiClient) {
if (!playbackManager.isPlayingLocally(['Video', 'Book'])) {
appRouter.showItem(cmd.Arguments.ItemId, apiClient.serverId());
}
}
function onMessageReceived(e, msg) {
var apiClient = this;
if (msg.MessageType === 'Play') {
notifyApp();
var serverId = apiClient.serverInfo().Id;
if (msg.Data.PlayCommand === 'PlayNext') {
playbackManager.queueNext({ ids: msg.Data.ItemIds, serverId: serverId });
} else if (msg.Data.PlayCommand === 'PlayLast') {
playbackManager.queue({ ids: msg.Data.ItemIds, serverId: serverId });
} else {
playbackManager.play({
ids: msg.Data.ItemIds,
startPositionTicks: msg.Data.StartPositionTicks,
mediaSourceId: msg.Data.MediaSourceId,
audioStreamIndex: msg.Data.AudioStreamIndex,
subtitleStreamIndex: msg.Data.SubtitleStreamIndex,
startIndex: msg.Data.StartIndex,
serverId: serverId
});
}
} else if (msg.MessageType === 'Playstate') {
if (msg.Data.Command === 'Stop') {
inputManager.handleCommand('stop');
} else if (msg.Data.Command === 'Pause') {
inputManager.handleCommand('pause');
} else if (msg.Data.Command === 'Unpause') {
inputManager.handleCommand('play');
} else if (msg.Data.Command === 'PlayPause') {
inputManager.handleCommand('playpause');
} else if (msg.Data.Command === 'Seek') {
playbackManager.seek(msg.Data.SeekPositionTicks);
} else if (msg.Data.Command === 'NextTrack') {
inputManager.handleCommand('next');
} else if (msg.Data.Command === 'PreviousTrack') {
inputManager.handleCommand('previous');
} else {
notifyApp();
}
} else if (msg.MessageType === 'GeneralCommand') {
var cmd = msg.Data;
processGeneralCommand(cmd, apiClient);
} else if (msg.MessageType === 'UserDataChanged') {
if (msg.Data.UserId === apiClient.getCurrentUserId()) {
for (var i = 0, length = msg.Data.UserDataList.length; i < length; i++) {
events.trigger(serverNotifications, 'UserDataChanged', [apiClient, msg.Data.UserDataList[i]]);
}
}
} else if (msg.MessageType === 'SyncPlayCommand') {
syncPlayManager.processCommand(msg.Data, apiClient);
} else if (msg.MessageType === 'SyncPlayGroupUpdate') {
syncPlayManager.processGroupUpdate(msg.Data, apiClient);
} else {
events.trigger(serverNotifications, msg.MessageType, [apiClient, msg.Data]);
}
}
function bindEvents(apiClient) {
events.off(apiClient, 'message', onMessageReceived);
events.on(apiClient, 'message', onMessageReceived);
}
connectionManager.getApiClients().forEach(bindEvents);
events.on(connectionManager, 'apiclientcreated', function (e, newApiClient) {
bindEvents(newApiClient);
function playTrailers(apiClient, itemId) {
apiClient.getItem(apiClient.getCurrentUserId(), itemId).then(function (item) {
playbackManager.playTrailers(item);
});
return serverNotifications;
}
function processGeneralCommand(cmd, apiClient) {
console.debug('Received command: ' + cmd.Name);
switch (cmd.Name) {
case 'Select':
inputManager.handleCommand('select');
return;
case 'Back':
inputManager.handleCommand('back');
return;
case 'MoveUp':
inputManager.handleCommand('up');
return;
case 'MoveDown':
inputManager.handleCommand('down');
return;
case 'MoveLeft':
inputManager.handleCommand('left');
return;
case 'MoveRight':
inputManager.handleCommand('right');
return;
case 'PageUp':
inputManager.handleCommand('pageup');
return;
case 'PageDown':
inputManager.handleCommand('pagedown');
return;
case 'PlayTrailers':
playTrailers(apiClient, cmd.Arguments.ItemId);
break;
case 'SetRepeatMode':
playbackManager.setRepeatMode(cmd.Arguments.RepeatMode);
break;
case 'SetShuffleQueue':
playbackManager.setQueueShuffleMode(cmd.Arguments.ShuffleMode);
break;
case 'VolumeUp':
inputManager.handleCommand('volumeup');
return;
case 'VolumeDown':
inputManager.handleCommand('volumedown');
return;
case 'ChannelUp':
inputManager.handleCommand('channelup');
return;
case 'ChannelDown':
inputManager.handleCommand('channeldown');
return;
case 'Mute':
inputManager.handleCommand('mute');
return;
case 'Unmute':
inputManager.handleCommand('unmute');
return;
case 'ToggleMute':
inputManager.handleCommand('togglemute');
return;
case 'SetVolume':
notifyApp();
playbackManager.setVolume(cmd.Arguments.Volume);
break;
case 'SetAudioStreamIndex':
notifyApp();
playbackManager.setAudioStreamIndex(parseInt(cmd.Arguments.Index));
break;
case 'SetSubtitleStreamIndex':
notifyApp();
playbackManager.setSubtitleStreamIndex(parseInt(cmd.Arguments.Index));
break;
case 'ToggleFullscreen':
inputManager.handleCommand('togglefullscreen');
return;
case 'GoHome':
inputManager.handleCommand('home');
return;
case 'GoToSettings':
inputManager.handleCommand('settings');
return;
case 'DisplayContent':
displayContent(cmd, apiClient);
break;
case 'GoToSearch':
inputManager.handleCommand('search');
return;
case 'DisplayMessage':
displayMessage(cmd);
break;
case 'ToggleOsd':
// todo
break;
case 'ToggleContextMenu':
// todo
break;
case 'TakeScreenShot':
// todo
break;
case 'SendKey':
// todo
break;
case 'SendString':
// todo
focusManager.sendText(cmd.Arguments.String);
break;
default:
console.debug('processGeneralCommand does not recognize: ' + cmd.Name);
break;
}
notifyApp();
}
function onMessageReceived(e, msg) {
const apiClient = this;
if (msg.MessageType === 'Play') {
notifyApp();
const serverId = apiClient.serverInfo().Id;
if (msg.Data.PlayCommand === 'PlayNext') {
playbackManager.queueNext({ ids: msg.Data.ItemIds, serverId: serverId });
} else if (msg.Data.PlayCommand === 'PlayLast') {
playbackManager.queue({ ids: msg.Data.ItemIds, serverId: serverId });
} else {
playbackManager.play({
ids: msg.Data.ItemIds,
startPositionTicks: msg.Data.StartPositionTicks,
mediaSourceId: msg.Data.MediaSourceId,
audioStreamIndex: msg.Data.AudioStreamIndex,
subtitleStreamIndex: msg.Data.SubtitleStreamIndex,
startIndex: msg.Data.StartIndex,
serverId: serverId
});
}
} else if (msg.MessageType === 'Playstate') {
if (msg.Data.Command === 'Stop') {
inputManager.handleCommand('stop');
} else if (msg.Data.Command === 'Pause') {
inputManager.handleCommand('pause');
} else if (msg.Data.Command === 'Unpause') {
inputManager.handleCommand('play');
} else if (msg.Data.Command === 'PlayPause') {
inputManager.handleCommand('playpause');
} else if (msg.Data.Command === 'Seek') {
playbackManager.seek(msg.Data.SeekPositionTicks);
} else if (msg.Data.Command === 'NextTrack') {
inputManager.handleCommand('next');
} else if (msg.Data.Command === 'PreviousTrack') {
inputManager.handleCommand('previous');
} else {
notifyApp();
}
} else if (msg.MessageType === 'GeneralCommand') {
const cmd = msg.Data;
processGeneralCommand(cmd, apiClient);
} else if (msg.MessageType === 'UserDataChanged') {
if (msg.Data.UserId === apiClient.getCurrentUserId()) {
for (let i = 0, length = msg.Data.UserDataList.length; i < length; i++) {
events.trigger(serverNotifications, 'UserDataChanged', [apiClient, msg.Data.UserDataList[i]]);
}
}
} else if (msg.MessageType === 'SyncPlayCommand') {
syncPlayManager.processCommand(msg.Data, apiClient);
} else if (msg.MessageType === 'SyncPlayGroupUpdate') {
syncPlayManager.processGroupUpdate(msg.Data, apiClient);
} else {
events.trigger(serverNotifications, msg.MessageType, [apiClient, msg.Data]);
}
}
function bindEvents(apiClient) {
events.off(apiClient, 'message', onMessageReceived);
events.on(apiClient, 'message', onMessageReceived);
}
connectionManager.getApiClients().forEach(bindEvents);
events.on(connectionManager, 'apiclientcreated', function (e, newApiClient) {
bindEvents(newApiClient);
});
export default serverNotifications;

View file

@ -1,24 +1,21 @@
define([], function () {
'use strict';
return {
openUrl: function (url, target) {
if (window.NativeShell) {
window.NativeShell.openUrl(url, target);
} else {
window.open(url, target || '_blank');
}
},
enableFullscreen: function () {
if (window.NativeShell) {
window.NativeShell.enableFullscreen();
}
},
disableFullscreen: function () {
if (window.NativeShell) {
window.NativeShell.disableFullscreen();
}
// TODO: This seems like a good candidate for deprecation
export default {
openUrl: function (url, target) {
if (window.NativeShell) {
window.NativeShell.openUrl(url, target);
} else {
window.open(url, target || '_blank');
}
};
});
},
enableFullscreen: function () {
if (window.NativeShell) {
window.NativeShell.enableFullscreen();
}
},
disableFullscreen: function () {
if (window.NativeShell) {
window.NativeShell.disableFullscreen();
}
}
};