blazor-components icon indicating copy to clipboard operation
blazor-components copied to clipboard

guide me to Get action in serviceworker plz!

Open shaahin18 opened this issue 1 year ago • 1 comments

hi majorimi in your blazor-component notification, i can make notification appearing with 2 actions( copy paste your code!). but when clicking on notification buttons nothing happened. i know i must get that actions(action1,action2) in service worker.but can you explain or reference me to document for understanding how to do things such as go to a page or etc when user clicked on action buttons in notification popup. thanks alot

shaahin18 avatar Jul 04 '24 08:07 shaahin18

The example in the demo code is here: https://github.com/majorimi/blazor-components/blob/master/src/Majorsoft.Blazor.Components.TestApps.Common/wwwroot/sw.js

The actions you specify must be handled in the notificationclick event as described in related documentation:

https://docs.w3cub.com/dom/serviceworkerglobalscope/notificationclick_event

So in the example code you would do various things in JavaScript based on the action clicked:

self.addEventListener('notificationclick', event => {
    let action = event.action;
    let customData = event.notification.data;

    if (action = "action1") {
        !!!DoSomeJavaScriptHere!!!
    }

    let notification = event.notification;
    console.log("Notification clicked: " +  notification);
});

This is why you are passing the URL to a JavaScript file to the HtmlServiceWorkerNotificationOptions. That is where the action handlers live.

A9G-Data-Droid avatar Aug 21 '24 22:08 A9G-Data-Droid