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

44 lines
1.2 KiB
JavaScript
Raw Normal View History

(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:
clients.openWindow("/");
return Promise.resolve();
2018-10-23 01:05:09 +03:00
}
});
2018-10-23 01:05:09 +03:00
}
self.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) {
clients.openWindow("/");
event.waitUntil(Promise.resolve());
return;
}
event.waitUntil(executeAction(action, data, serverId));
}, false);
})();