1. notification via SW 2.manifest json for home screen app 3. icons for mobile/desktop shortcut app
This commit is contained in:
parent
44dd4e9562
commit
2087c2897f
19 changed files with 217 additions and 51 deletions
29
src/plugins/notificationAndServiceWorker.js
Normal file
29
src/plugins/notificationAndServiceWorker.js
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
const registerServiceWorker = async () => {
|
||||
const swRegistration = await navigator.serviceWorker.register("/sw.js");
|
||||
return swRegistration;
|
||||
};
|
||||
|
||||
const requestNotificationPermission = async () => {
|
||||
// return value: 'granted', 'default', 'denied'
|
||||
return await window.Notification.requestPermission();
|
||||
};
|
||||
|
||||
export async function requestNotificationAndServiceWorker() {
|
||||
if (!("serviceWorker" in navigator)) {
|
||||
throw new Error("No Service Worker support!");
|
||||
}
|
||||
if (!("PushManager" in window)) {
|
||||
throw new Error("No Push API Support!");
|
||||
}
|
||||
const permission = await requestNotificationPermission();
|
||||
if(permission==='granted') await registerServiceWorker();
|
||||
return permission
|
||||
}
|
||||
|
||||
export function windowNotificationPermission() {
|
||||
return window.Notification.permission
|
||||
}
|
||||
|
||||
export function notificationCount() {
|
||||
return this.$matrix.notificationCount
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue