Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Commit

Permalink
feat: support browser notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazyokd committed Apr 22, 2023
1 parent 87f0f8d commit 63f9433
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/utils/notification.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export function showNotification(title, message) {
if ("Notification" in window) {
if (Notification.permission !== "granted") {
Notification.requestPermission().then((permission) => {
if (permission === "granted") {
// 用户已同意授权
showNotification(title, message);
} else {
console.log("用户拒绝授权通知");
}
});
} else {
// 用户已经同意授权
new Notification(title, {
body: message,
icon: "/favicon.ico",
});
}
} else {
console.log("浏览器不支持通知");
}
}

0 comments on commit 63f9433

Please sign in to comment.