mirror of
https://github.com/home-assistant/frontend.git
synced 2025-06-20 09:06:34 +00:00
40 lines
891 B
Cheetah
40 lines
891 B
Cheetah
self.addEventListener("push", function(event) {
|
|
var data;
|
|
if (event.data) {
|
|
data = event.data.json();
|
|
event.waitUntil(self.registration.showNotification(data.title, data));
|
|
}
|
|
});
|
|
self.addEventListener('notificationclick', function(event) {
|
|
var url;
|
|
|
|
if (!event.notification.data || !event.notification.data.url) {
|
|
return;
|
|
}
|
|
|
|
event.notification.close();
|
|
url = event.notification.data.url;
|
|
|
|
if (!url) return;
|
|
|
|
event.waitUntil(
|
|
clients.matchAll({
|
|
type: 'window',
|
|
})
|
|
.then(function (windowClients) {
|
|
var i;
|
|
var client;
|
|
for (i = 0; i < windowClients.length; i++) {
|
|
client = windowClients[i];
|
|
if (client.url === url && 'focus' in client) {
|
|
return client.focus();
|
|
}
|
|
}
|
|
if (clients.openWindow) {
|
|
return clients.openWindow(url);
|
|
}
|
|
return undefined;
|
|
})
|
|
);
|
|
});
|