Skip to content

Commit

Permalink
feat: add notification
Browse files Browse the repository at this point in the history
  • Loading branch information
DerStimmler committed Mar 12, 2024
1 parent 7964d2d commit 1f7296c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,19 @@ if ("serviceWorker" in navigator) {
.register("./sw.js");
});
}

//Notification
async function notify() {
if (!("Notification" in window)) {
alert("Notifications not suported");
return;
}

if (Notification.permission !== "granted") {
await Notification.requestPermission();
}

const serviceWorker = await navigator.serviceWorker.ready;

serviceWorker.showNotification("Current count: " + count);
}
6 changes: 6 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
<h1 class="title">PWA Showcase</h1>
</header>
<main class="main">
<div class="card">
<div class="card__title">Notification</div>
<div class="card__content">
<button onclick="notify()">Notify Me!</button>
</div>
</div>
<div class="card">
<div class="card__title">Sample Text 1</div>
<div class="card__content">
Expand Down

0 comments on commit 1f7296c

Please sign in to comment.