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:
parent
3bafe0d621
commit
42ac558a17
2 changed files with 203 additions and 202 deletions
|
@ -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",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
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';
|
||||||
playbackManager = playbackManager.default || playbackManager;
|
import globalize from 'globalize';
|
||||||
|
|
||||||
function onOneDocumentClick() {
|
function onOneDocumentClick() {
|
||||||
document.removeEventListener('click', onOneDocumentClick);
|
document.removeEventListener('click', onOneDocumentClick);
|
||||||
|
@ -17,7 +17,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
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 () {
|
||||||
|
@ -31,7 +31,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
|
|
||||||
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;
|
||||||
|
@ -47,7 +47,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
|
|
||||||
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();
|
||||||
|
@ -67,7 +67,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
@ -89,13 +89,13 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
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, {
|
||||||
|
@ -117,7 +117,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
}
|
}
|
||||||
|
|
||||||
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,17 +140,17 @@ 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) {
|
||||||
|
@ -159,7 +159,7 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var notification = {
|
let notification = {
|
||||||
tag: 'install' + installation.Id,
|
tag: 'install' + installation.Id,
|
||||||
data: {}
|
data: {}
|
||||||
};
|
};
|
||||||
|
@ -188,12 +188,12 @@ 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);
|
||||||
});
|
});
|
||||||
|
@ -220,8 +220,8 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
});
|
});
|
||||||
|
|
||||||
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)
|
||||||
};
|
};
|
||||||
|
@ -229,8 +229,8 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
});
|
});
|
||||||
|
|
||||||
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)
|
||||||
};
|
};
|
||||||
|
@ -238,8 +238,8 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
});
|
});
|
||||||
|
|
||||||
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)
|
||||||
};
|
};
|
||||||
|
@ -255,4 +255,4 @@ define(['serverNotifications', 'playbackManager', 'events', 'globalize', 'requir
|
||||||
|
|
||||||
showNotification(notification, 0, apiClient);
|
showNotification(notification, 0, apiClient);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue