From 5918a1e6e0d24d4df3a0fb51020a3a84d159b2f9 Mon Sep 17 00:00:00 2001 From: Joshua Toliver Date: Wed, 11 Oct 2023 09:55:26 -0400 Subject: [PATCH 1/2] R2-2598: Going to application when push notification clicked --- app/javascript/worker.js | 41 +++++++++++++++++----------------------- public/manifest.json | 2 +- 2 files changed, 18 insertions(+), 25 deletions(-) diff --git a/app/javascript/worker.js b/app/javascript/worker.js index 742cd197a0..a671971bce 100644 --- a/app/javascript/worker.js +++ b/app/javascript/worker.js @@ -104,38 +104,31 @@ self.addEventListener("push", event => { body: message.body, image, icon: image, - data: { url: message.link }, - actions: [{ action: ACTIONS.GOTO, title: message.action_label }] + data: { url: message.link } }) ); }); self.addEventListener( "notificationclick", - async event => { + event => { event.notification.close(); - if (event.action === ACTIONS.GOTO) { - event.waitUntil( - self.clients - .matchAll({ - type: "window" - }) - .then(clientList => { - const link = `${self.location.protocol}//${event.notification.data.url}`; - - for (let clientCounter = 0; clientCounter < clientList.length; clientCounter += 1) { - const client = clientList[clientCounter]; - - if (client.url === link && "focus" in client) { - return client.focus(); - } - } - - return self.clients.openWindow(link); - }) - ); - } + event.waitUntil( + self.clients.matchAll().then(clientList => { + const link = `${self.location.protocol}//${event.notification.data.url}`; + + for (let clientCounter = 0; clientCounter < clientList.length; clientCounter += 1) { + const client = clientList[clientCounter]; + + if (client.url === link && "focus" in client) { + return client.focus(); + } + } + + return self.clients.openWindow(link); + }) + ); }, false ); diff --git a/public/manifest.json b/public/manifest.json index 961ef8ae76..1f33db1613 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -4,7 +4,7 @@ "description": "Primero is an open source software platform that helps social services, humanitarian and development workers manage protection-related data, with tools that facilitate case management, incident monitoring and family tracing and reunification.", "start_url": "v2/", "background_color": "#ffffff", - "display": "fullscreen", + "display": "standalone", "theme_color": "#0093ba", "icons": [ { From fc946e6ab26617a7ad70f95d0e530c4cca4af857 Mon Sep 17 00:00:00 2001 From: Joshua Toliver Date: Wed, 11 Oct 2023 10:12:31 -0400 Subject: [PATCH 2/2] Removing unused var --- app/javascript/worker.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/javascript/worker.js b/app/javascript/worker.js index a671971bce..c957e6a3bc 100644 --- a/app/javascript/worker.js +++ b/app/javascript/worker.js @@ -19,10 +19,6 @@ const METHODS = { DELETE: "DELETE" }; -const ACTIONS = { - GOTO: "goto" -}; - const isNav = event => event.request.mode === "navigate"; // TODO: This pr would allow passing strategies to workbox way of handling navigation routes