mirror of
https://github.com/aljazceru/meshcore-web.git
synced 2025-12-17 16:24:18 +01:00
open existing client if available
This commit is contained in:
@@ -10,6 +10,29 @@ self.addEventListener('notificationclick', function(event) {
|
|||||||
event.notification.close();
|
event.notification.close();
|
||||||
|
|
||||||
// open pwa
|
// open pwa
|
||||||
event.waitUntil(self.clients.openWindow("/"));
|
const url = "/";
|
||||||
|
event.waitUntil(findClientForUrl(url).then((client) => {
|
||||||
|
|
||||||
|
// if an existing client exists, focus it
|
||||||
|
if(client){
|
||||||
|
client.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise open a new window
|
||||||
|
return self.clients.openWindow(url);
|
||||||
|
|
||||||
|
}));
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const findClientForUrl = function(url) {
|
||||||
|
return self.clients.matchAll({
|
||||||
|
type: "window",
|
||||||
|
includeUncontrolled: true,
|
||||||
|
}).then(function (clientList) {
|
||||||
|
return clientList.find(function(client) {
|
||||||
|
return client.url.endsWith(url);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user