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,7 +1,7 @@
define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'require'], function (serverNotifications, playbackManager, events, globalize, require) {
'use strict';
playbackManager = playbackManager.default || playbackManager;
import serverNotifications from 'serverNotifications';
import playbackManager from 'playbackManager';
import events from 'events';
import globalize from 'globalize';
function onOneDocumentClick() {
document.removeEventListener('click', onOneDocumentClick);
@ -17,7 +17,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
document.addEventListener('click', onOneDocumentClick);
document.addEventListener('keydown', onOneDocumentClick);
var serviceWorkerRegistration;
let serviceWorkerRegistration;
function closeAfter(notification, timeoutMs) {
setTimeout(function () {
@ -31,7 +31,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
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;
@ -47,7 +47,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
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();
@ -67,7 +67,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
}
function showNotification(options, timeoutMs, apiClient) {
var title = options.title;
let title = options.title;
options.data = options.data || {};
options.data.serverId = apiClient.serverInfo().Id;
@ -89,13 +89,13 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
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, {
@ -117,7 +117,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
}
function onLibraryChanged(data, apiClient) {
var newItems = data.ItemsAdded;
let newItems = data.ItemsAdded;
if (!newItems.length) {
return;
@ -140,17 +140,17 @@ 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) {
name = name || 'notificationicon.png';
return require.toUrl('.').split('?')[0] + '/' + name;
return './components/notifications/' + name;
}
function showPackageInstallNotification(apiClient, installation, status) {
@ -159,7 +159,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
return;
}
var notification = {
let notification = {
tag: 'install' + installation.Id,
data: {}
};
@ -188,12 +188,12 @@ 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);
});
@ -220,8 +220,8 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
});
events.on(serverNotifications, 'ServerShuttingDown', function (e, apiClient, data) {
var serverId = apiClient.serverInfo().Id;
var notification = {
let serverId = apiClient.serverInfo().Id;
let notification = {
tag: 'restart' + serverId,
title: globalize.translate('ServerNameIsShuttingDown', apiClient.serverInfo().Name)
};
@ -229,8 +229,8 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
});
events.on(serverNotifications, 'ServerRestarting', function (e, apiClient, data) {
var serverId = apiClient.serverInfo().Id;
var notification = {
let serverId = apiClient.serverInfo().Id;
let notification = {
tag: 'restart' + serverId,
title: globalize.translate('ServerNameIsRestarting', apiClient.serverInfo().Name)
};
@ -238,8 +238,8 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
});
events.on(serverNotifications, 'RestartRequired', function (e, apiClient) {
var serverId = apiClient.serverInfo().Id;
var notification = {
let serverId = apiClient.serverInfo().Id;
let notification = {
tag: 'restart' + serverId,
title: globalize.translate('PleaseRestartServerName', apiClient.serverInfo().Name)
};
@ -255,4 +255,4 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
showNotification(notification, 0, apiClient);
});
});