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

46 lines
1.3 KiB
JavaScript
Raw Normal View History

/* eslint-env serviceworker */
(function () {
'use strict';
var connectionManager;
2018-10-23 01:05:09 +03:00
function getApiClient(serverId) {
if (connectionManager) {
return Promise.resolve(connectionManager.getApiClient(serverId));
}
return Promise.reject();
2018-10-23 01:05:09 +03:00
}
function executeAction(action, data, serverId) {
return getApiClient(serverId).then(function (apiClient) {
2018-10-23 01:05:09 +03:00
switch (action) {
case 'cancel-install':
2018-10-23 01:05:09 +03:00
var id = data.id;
return apiClient.cancelPackageInstallation(id);
case 'restart':
2018-10-23 01:05:09 +03:00
return apiClient.restartServer();
default:
2020-05-04 12:44:12 +02:00
clients.openWindow('/');
return Promise.resolve();
2018-10-23 01:05:09 +03:00
}
});
2018-10-23 01:05:09 +03:00
}
2020-08-25 10:12:35 +09:00
window.addEventListener('notificationclick', function (event) {
2018-10-23 01:05:09 +03:00
var notification = event.notification;
notification.close();
var data = notification.data;
var serverId = data.serverId;
var action = event.action;
if (!action) {
2020-05-04 12:44:12 +02:00
clients.openWindow('/');
event.waitUntil(Promise.resolve());
return;
}
event.waitUntil(executeAction(action, data, serverId));
}, false);
})();