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/personEditor.js",
"src/components/multiSelect/multiSelect.js",
"src/components/notifications/notifications.js",
"src/components/nowPlayingBar/nowPlayingBar.js",
"src/components/playback/brightnessosd.js",
"src/components/playback/mediasession.js",

View file

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