jellyfin-web/dashboard-ui/bower_components/emby-webcomponents/serviceworker/notifications.js

52 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-10-17 22:06:48 -07:00
(function () {
'use strict';
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
var connectionManager;
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
function getApiClient(serverId) {
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
if (connectionManager) {
return Promise.resolve(connectionManager.getApiClient(serverId));
}
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
//importScripts('serviceworker-cache-polyfill.js');
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
return Promise.reject();
}
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07: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 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
self.addEventListener('notificationclick', function (event) {
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
var notification = event.notification;
notification.close();
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
var data = notification.data;
var serverId = data.serverId;
var action = event.action;
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
if (!action) {
clients.openWindow("/");
event.waitUntil(Promise.resolve());
return;
}
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
event.waitUntil(executeAction(action, data, serverId));
2016-08-28 11:59:14 -07:00
2016-10-17 22:06:48 -07:00
}, false);
})();