From 6100a2265ee22563e009b9348a4f38279c3c30af Mon Sep 17 00:00:00 2001 From: lodewiges Date: Sat, 26 Oct 2024 23:57:53 +0200 Subject: [PATCH] removed another file --- app/services/notification.js | 91 ------------------------------------ 1 file changed, 91 deletions(-) delete mode 100644 app/services/notification.js diff --git a/app/services/notification.js b/app/services/notification.js deleted file mode 100644 index bc2bf2b4f..000000000 --- a/app/services/notification.js +++ /dev/null @@ -1,91 +0,0 @@ -import Service from '@ember/service'; -import { tracked } from '@glimmer/tracking'; - -export default class NotificationService extends Service { - isSupported = null; - @tracked permissionIsGranted = null; - @tracked permissionIsDenied = null; - @tracked isEnabled = null; - @tracked isSoundEnabled = null; - notificationSound = new Audio('/sounds/notification.mp3'); - - constructor() { - super(...arguments); - - if ('Notification' in window) { - this.isSupported = true; - this.permissionIsGranted = Notification.permission === 'granted'; - this.permissionIsDenied = Notification.permission === 'denied'; - this.isEnabled = localStorage.getItem('notificationEnabled') === 'true'; - this.isSoundEnabled = - localStorage.getItem('notificationSoundEnabled') === 'true'; - } else { - this.isSupported = false; - this.permissionIsGranted = false; - this.permissionIsDenied = false; - this.isEnabled = false; - this.isSoundEnabled = false; - } - } - - getPermission() { - if (!this.isEnabled) { - Notification.requestPermission((permission) => { - if (permission === 'granted') { - this.permissionIsGranted = true; - this.new( - 'Notificaties zijn nu ingeschakeld', - 'Je zult ze ontvangen bij elk Quickpost bericht', - '/images/alphalogonotext.png' - ); - } else if (permission === 'denied') { - this.permissionIsGranted = false; - this.permissionIsDenied = true; - return false; - } - }); - } - - this.isEnabled = this.permissionIsGranted; - localStorage.setItem('notificationEnabled', this.permissionIsGranted); - this.isSoundEnabled = false; - localStorage.setItem('notificationSoundEnabled', this.isSoundEnabled); - } - - turnOff() { - this.isEnabled = false; - localStorage.setItem('notificationEnabled', false); - } - - new(title, body, icon) { - const options = { - body, - icon, - }; - if (this.permissionIsGranted && this.isEnabled) { - try { - return new Notification(title, options); - } catch (error) { - if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('sw.js').then((registration) => { - registration.showNotification(title, options); - }); - } - } finally { - if (this.isSoundEnabled) { - this.notificationSound.play(); - } - } - } - } - - toggleSound() { - this.isSoundEnabled = !this.isSoundEnabled; - localStorage.setItem('notificationSoundEnabled', this.isSoundEnabled); - } - - soundOn() { - this.isSoundEnabled = true; - localStorage.setItem('notificationSoundEnabled', this.isSoundEnabled); - } -}