From 72808c3c7c10974eaea347947019d2ecd95690f8 Mon Sep 17 00:00:00 2001 From: gofnnp Date: Wed, 8 Mar 2023 01:36:27 +0400 Subject: [PATCH] =?UTF-8?q?dev=20#13882=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- angular/angular.json | 3 ++- angular/src/app/app.module.ts | 2 +- angular/src/app/services/messaging.service.ts | 3 --- angular/src/firebase-messaging-sw.js | 11 +++-------- angular/src/sw-custom.js | 8 ++++++++ angular/src/sw-master.js | 2 ++ 6 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 angular/src/sw-custom.js create mode 100644 angular/src/sw-master.js diff --git a/angular/angular.json b/angular/angular.json index ea8448c..1b1a0ab 100644 --- a/angular/angular.json +++ b/angular/angular.json @@ -30,7 +30,8 @@ "src/favicon.ico", "src/assets", "src/manifest.webmanifest", - "src/firebase-messaging-sw.js" + "src/firebase-messaging-sw.js", + "src/sw-master.js" ], "styles": [ "node_modules/primeng/resources/themes/bootstrap4-light-blue/theme.css", diff --git a/angular/src/app/app.module.ts b/angular/src/app/app.module.ts index 716954a..f714d39 100644 --- a/angular/src/app/app.module.ts +++ b/angular/src/app/app.module.ts @@ -69,7 +69,7 @@ import { DownloadAppDirective } from './directives/download-app.directive'; HttpClientModule, BrowserAnimationsModule, BrowserModule, - ServiceWorkerModule.register('ngsw-worker.js', { + ServiceWorkerModule.register('/sw-master.js', { enabled: environment.production, // Register the ServiceWorker as soon as the application is stable // or after 30 seconds (whichever comes first). diff --git a/angular/src/app/services/messaging.service.ts b/angular/src/app/services/messaging.service.ts index 33db477..59bc0ed 100644 --- a/angular/src/app/services/messaging.service.ts +++ b/angular/src/app/services/messaging.service.ts @@ -89,9 +89,6 @@ export class MessagingService { data: payload.data, icon: payload.notification.icon } - navigator.serviceWorker.getRegistration('/firebase-cloud-messaging-push-scope').then((registration: any) => { - registration.showNotification(payload.notification.title, NotificationOptions); - }); this.currentMessage.next(payload); }); } diff --git a/angular/src/firebase-messaging-sw.js b/angular/src/firebase-messaging-sw.js index 329818c..3468516 100644 --- a/angular/src/firebase-messaging-sw.js +++ b/angular/src/firebase-messaging-sw.js @@ -1,5 +1,5 @@ -importScripts('https://www.gstatic.com/firebasejs/9.17.1/firebase-app.js'); -importScripts('https://www.gstatic.com/firebasejs/9.17.1/firebase-messaging.js'); +importScripts('https://www.gstatic.com/firebasejs/3.6.9/firebase-app.js'); +importScripts('https://www.gstatic.com/firebasejs/3.6.9/firebase-messaging.js'); firebase.initializeApp({ apiKey: "AIzaSyCnKvln5itnrBj62POCPHxshAN_Vmd0zds", @@ -11,9 +11,4 @@ firebase.initializeApp({ measurementId: "G-RQF97ZK7R1" }); -const messaging = firebase.messaging(); - -self.addEventListener('notificationclick', function(event) { - event.notification.close(); - event.waitUntil(self.clients.openWindow(event.notification.data.url)); -}); \ No newline at end of file +const messaging = firebase.messaging(); \ No newline at end of file diff --git a/angular/src/sw-custom.js b/angular/src/sw-custom.js new file mode 100644 index 0000000..3027cb0 --- /dev/null +++ b/angular/src/sw-custom.js @@ -0,0 +1,8 @@ +(function () { + "use strict"; + + self.addEventListener("notificationclick", (event) => { + event.notification.close(); + console.log("notification details: ", event.notification); + }); +})(); diff --git a/angular/src/sw-master.js b/angular/src/sw-master.js new file mode 100644 index 0000000..62dbad5 --- /dev/null +++ b/angular/src/sw-master.js @@ -0,0 +1,2 @@ +importScripts('./ngsw-worker.js'); +importScripts('./sw-custom.js'); \ No newline at end of file