1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/serviceworker/notifications.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-10-18 01:06:48 -04:00
(function () {
'use strict';
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
var connectionManager;
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
function getApiClient(serverId) {
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
if (connectionManager) {
return Promise.resolve(connectionManager.getApiClient(serverId));
}
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
//importScripts('serviceworker-cache-polyfill.js');
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
return Promise.reject();
}
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
function executeAction(action, data, serverId) {
return getApiClient(serverId).then(function (apiClient) {
switch (action) {
case 'cancel-install':
var id = data.id;
return apiClient.cancelPackageInstallation(id);
case 'restart':
return apiClient.restartServer();
default:
clients.openWindow("/");
return Promise.resolve();
}
});
}
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
self.addEventListener('notificationclick', function (event) {
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
var notification = event.notification;
notification.close();
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
var data = notification.data;
var serverId = data.serverId;
var action = event.action;
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
if (!action) {
clients.openWindow("/");
event.waitUntil(Promise.resolve());
return;
}
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
event.waitUntil(executeAction(action, data, serverId));
2016-08-28 14:59:14 -04:00
2016-10-18 01:06:48 -04:00
}, false);
})();