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

Migration of notification to ES6 module

This commit is contained in:
Cameron 2020-08-06 11:41:18 +01:00
parent 3bafe0d621
commit 42ac558a17
2 changed files with 203 additions and 202 deletions

View file

@ -135,6 +135,7 @@
"src/components/metadataEditor/metadataEditor.js", "src/components/metadataEditor/metadataEditor.js",
"src/components/metadataEditor/personEditor.js", "src/components/metadataEditor/personEditor.js",
"src/components/multiSelect/multiSelect.js", "src/components/multiSelect/multiSelect.js",
"src/components/notifications/notifications.js",
"src/components/nowPlayingBar/nowPlayingBar.js", "src/components/nowPlayingBar/nowPlayingBar.js",
"src/components/playback/brightnessosd.js", "src/components/playback/brightnessosd.js",
"src/components/playback/mediasession.js", "src/components/playback/mediasession.js",

View file

@ -1,9 +1,9 @@
define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'require'], function (serverNotifications, playbackManager, events, globalize, require) { import serverNotifications from 'serverNotifications';
'use strict'; import playbackManager from 'playbackManager';
import events from 'events';
import globalize from 'globalize';
playbackManager = playbackManager.default || playbackManager; function onOneDocumentClick() {
function onOneDocumentClick() {
document.removeEventListener('click', onOneDocumentClick); document.removeEventListener('click', onOneDocumentClick);
document.removeEventListener('keydown', onOneDocumentClick); document.removeEventListener('keydown', onOneDocumentClick);
@ -12,14 +12,14 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
/* eslint-disable-next-line compat/compat */ /* eslint-disable-next-line compat/compat */
Notification.requestPermission(); Notification.requestPermission();
} }
} }
document.addEventListener('click', onOneDocumentClick); document.addEventListener('click', onOneDocumentClick);
document.addEventListener('keydown', onOneDocumentClick); document.addEventListener('keydown', onOneDocumentClick);
var serviceWorkerRegistration; let serviceWorkerRegistration;
function closeAfter(notification, timeoutMs) { function closeAfter(notification, timeoutMs) {
setTimeout(function () { setTimeout(function () {
if (notification.close) { if (notification.close) {
notification.close(); notification.close();
@ -27,27 +27,27 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
notification.cancel(); notification.cancel();
} }
}, timeoutMs); }, timeoutMs);
} }
function resetRegistration() { function resetRegistration() {
/* eslint-disable-next-line compat/compat */ /* eslint-disable-next-line compat/compat */
var serviceWorker = navigator.serviceWorker; let serviceWorker = navigator.serviceWorker;
if (serviceWorker) { if (serviceWorker) {
serviceWorker.ready.then(function (registration) { serviceWorker.ready.then(function (registration) {
serviceWorkerRegistration = registration; serviceWorkerRegistration = registration;
}); });
} }
} }
resetRegistration(); resetRegistration();
function showPersistentNotification(title, options, timeoutMs) { function showPersistentNotification(title, options, timeoutMs) {
serviceWorkerRegistration.showNotification(title, options); serviceWorkerRegistration.showNotification(title, options);
} }
function showNonPersistentNotification(title, options, timeoutMs) { function showNonPersistentNotification(title, options, timeoutMs) {
try { try {
var notif = new Notification(title, options); /* eslint-disable-line compat/compat */ let notif = new Notification(title, options); /* eslint-disable-line compat/compat */
if (notif.show) { if (notif.show) {
notif.show(); notif.show();
@ -64,10 +64,10 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
throw err; throw err;
} }
} }
} }
function showNotification(options, timeoutMs, apiClient) { function showNotification(options, timeoutMs, apiClient) {
var title = options.title; let title = options.title;
options.data = options.data || {}; options.data = options.data || {};
options.data.serverId = apiClient.serverInfo().Id; options.data.serverId = apiClient.serverInfo().Id;
@ -82,20 +82,20 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
} }
showNonPersistentNotification(title, options, timeoutMs); showNonPersistentNotification(title, options, timeoutMs);
} }
function showNewItemNotification(item, apiClient) { function showNewItemNotification(item, apiClient) {
if (playbackManager.isPlayingLocally(['Video'])) { if (playbackManager.isPlayingLocally(['Video'])) {
return; return;
} }
var body = item.Name; let body = item.Name;
if (item.SeriesName) { if (item.SeriesName) {
body = item.SeriesName + ' - ' + body; body = item.SeriesName + ' - ' + body;
} }
var notification = { let notification = {
title: 'New ' + item.Type, title: 'New ' + item.Type,
body: body, body: body,
vibrate: true, vibrate: true,
@ -103,7 +103,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
data: {} data: {}
}; };
var imageTags = item.ImageTags || {}; let imageTags = item.ImageTags || {};
if (imageTags.Primary) { if (imageTags.Primary) {
notification.icon = apiClient.getScaledImageUrl(item.Id, { notification.icon = apiClient.getScaledImageUrl(item.Id, {
@ -114,10 +114,10 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
} }
showNotification(notification, 15000, apiClient); showNotification(notification, 15000, apiClient);
} }
function onLibraryChanged(data, apiClient) { function onLibraryChanged(data, apiClient) {
var newItems = data.ItemsAdded; let newItems = data.ItemsAdded;
if (!newItems.length) { if (!newItems.length) {
return; return;
@ -140,26 +140,26 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
EnableTotalRecordCount: false EnableTotalRecordCount: false
}).then(function (result) { }).then(function (result) {
var items = result.Items; let items = result.Items;
for (var i = 0, length = items.length ; i < length; i++) { for (const item of items) {
showNewItemNotification(items[i], apiClient); showNewItemNotification(item, apiClient);
} }
}); });
} }
function getIconUrl(name) { function getIconUrl(name) {
name = name || 'notificationicon.png'; name = name || 'notificationicon.png';
return require.toUrl('.').split('?')[0] + '/' + name; return './components/notifications/' + name;
} }
function showPackageInstallNotification(apiClient, installation, status) { function showPackageInstallNotification(apiClient, installation, status) {
apiClient.getCurrentUser().then(function (user) { apiClient.getCurrentUser().then(function (user) {
if (!user.Policy.IsAdministrator) { if (!user.Policy.IsAdministrator) {
return; return;
} }
var notification = { let notification = {
tag: 'install' + installation.Id, tag: 'install' + installation.Id,
data: {} data: {}
}; };
@ -188,58 +188,58 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
} }
if (status === 'progress') { if (status === 'progress') {
var percentComplete = Math.round(installation.PercentComplete || 0); let percentComplete = Math.round(installation.PercentComplete || 0);
notification.body = percentComplete + '% complete.'; notification.body = percentComplete + '% complete.';
} }
var timeout = status === 'cancelled' ? 5000 : 0; let timeout = status === 'cancelled' ? 5000 : 0;
showNotification(notification, timeout, apiClient); showNotification(notification, timeout, apiClient);
}); });
} }
events.on(serverNotifications, 'LibraryChanged', function (e, apiClient, data) { events.on(serverNotifications, 'LibraryChanged', function (e, apiClient, data) {
onLibraryChanged(data, apiClient); onLibraryChanged(data, apiClient);
}); });
events.on(serverNotifications, 'PackageInstallationCompleted', function (e, apiClient, data) { events.on(serverNotifications, 'PackageInstallationCompleted', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, 'completed'); showPackageInstallNotification(apiClient, data, 'completed');
}); });
events.on(serverNotifications, 'PackageInstallationFailed', function (e, apiClient, data) { events.on(serverNotifications, 'PackageInstallationFailed', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, 'failed'); showPackageInstallNotification(apiClient, data, 'failed');
}); });
events.on(serverNotifications, 'PackageInstallationCancelled', function (e, apiClient, data) { events.on(serverNotifications, 'PackageInstallationCancelled', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, 'cancelled'); showPackageInstallNotification(apiClient, data, 'cancelled');
}); });
events.on(serverNotifications, 'PackageInstalling', function (e, apiClient, data) { events.on(serverNotifications, 'PackageInstalling', function (e, apiClient, data) {
showPackageInstallNotification(apiClient, data, 'progress'); showPackageInstallNotification(apiClient, data, 'progress');
}); });
events.on(serverNotifications, 'ServerShuttingDown', function (e, apiClient, data) { events.on(serverNotifications, 'ServerShuttingDown', function (e, apiClient, data) {
var serverId = apiClient.serverInfo().Id; let serverId = apiClient.serverInfo().Id;
var notification = { let notification = {
tag: 'restart' + serverId, tag: 'restart' + serverId,
title: globalize.translate('ServerNameIsShuttingDown', apiClient.serverInfo().Name) title: globalize.translate('ServerNameIsShuttingDown', apiClient.serverInfo().Name)
}; };
showNotification(notification, 0, apiClient); showNotification(notification, 0, apiClient);
}); });
events.on(serverNotifications, 'ServerRestarting', function (e, apiClient, data) { events.on(serverNotifications, 'ServerRestarting', function (e, apiClient, data) {
var serverId = apiClient.serverInfo().Id; let serverId = apiClient.serverInfo().Id;
var notification = { let notification = {
tag: 'restart' + serverId, tag: 'restart' + serverId,
title: globalize.translate('ServerNameIsRestarting', apiClient.serverInfo().Name) title: globalize.translate('ServerNameIsRestarting', apiClient.serverInfo().Name)
}; };
showNotification(notification, 0, apiClient); showNotification(notification, 0, apiClient);
}); });
events.on(serverNotifications, 'RestartRequired', function (e, apiClient) { events.on(serverNotifications, 'RestartRequired', function (e, apiClient) {
var serverId = apiClient.serverInfo().Id; let serverId = apiClient.serverInfo().Id;
var notification = { let notification = {
tag: 'restart' + serverId, tag: 'restart' + serverId,
title: globalize.translate('PleaseRestartServerName', apiClient.serverInfo().Name) title: globalize.translate('PleaseRestartServerName', apiClient.serverInfo().Name)
}; };
@ -254,5 +254,5 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
]; ];
showNotification(notification, 0, apiClient); showNotification(notification, 0, apiClient);
});
}); });