Skip to content

Commit

Permalink
Update notification handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
JanneMattila committed Jun 30, 2023
1 parent 64f4311 commit 22880fc
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/MyChess.Client/wwwroot/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ self.addEventListener('fetch', (event) => {
// be reflected on the first load after each change).
//self.addEventListener('fetch', () => { });

self.addEventListener('push', async (event) => {
self.addEventListener('push', (event) => {
console.log(`[My Chess Push] Push event`);

if (!self.Notification) {
Expand Down Expand Up @@ -157,23 +157,25 @@ self.addEventListener('push', async (event) => {
}
}

await self.registration.showNotification("My Chess", {
const showNotification = self.registration.showNotification("My Chess", {
body: notificationData.text,
vibrate: [250, 100, 250, 100, 250],
badge: '/logo_96x96_monochrome.png',
icon: '/logo_192x192.png',
data: notificationData.uri
});

event.waitUntil(showNotification);

const clientList = await clients.matchAll({
type: "all", includeUncontrolled: true
type: "window", includeUncontrolled: true
});
if (clientList.length > 0) {
let client = clientList[0];
for (let i = 0; i < clientList.length; i++) {
//if (clientList[i].focused) {
if (clientList[i].focused) {
client = clientList[i];
//}
}
}
client.postMessage(notificationData);
}
Expand Down

0 comments on commit 22880fc

Please sign in to comment.