diff --git a/client/main.ts b/client/main.ts index 88b38d71..73fe0c73 100644 --- a/client/main.ts +++ b/client/main.ts @@ -18,6 +18,7 @@ import absolute from './absolute'; async function main() { console.log(await absolute.push.register('key')); + console.log(await absolute.push.unregister()); } main(); diff --git a/client/push/push_manager.ts b/client/push/push_manager.ts index 7831e7a7..d4c949f7 100644 --- a/client/push/push_manager.ts +++ b/client/push/push_manager.ts @@ -26,8 +26,6 @@ export default class PushManager { } async register(key: string): Promise { - // Not implemented yet - if (navigator.serviceWorker) { navigator.serviceWorker.register('/push_service_worker.js') .then((registration: ServiceWorkerRegistration) => { @@ -66,7 +64,28 @@ export default class PushManager { } async unregister(): Promise { - // Not implemented yet + if (!navigator.serviceWorker) { + return false; + } + + navigator.serviceWorker.ready + .then((registration: ServiceWorkerRegistration) => { + registration.pushManager.getSubscription() + .then((subscription: PushSubscription) => { + if (subscription) { + subscription.unsubscribe(); + return true; + } + return false; + }) + .catch((error: Error) => { + // Not implemented yet + }) + }) + .catch((error: Error) => { + // Not implemented yet + }) + return false; } }