diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index edc515e76..99dfec1bc 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -18,6 +18,7 @@ import { ExpedienteGdStore } from '../store/expedientegd-store.service'; import { InativityService } from '../services/inativity.service'; import { SessionStore } from '../store/session.service'; import { StorageService } from '../services/storage.service'; +import { WebNotificationPopupService } from '../services/notification/web-notification-popup.service'; @Component({ selector: 'app-home', @@ -72,7 +73,10 @@ export class HomePage implements OnInit { public documentCounterService: DocumentCounterService, private despachoRule: DespachoService, private inativityService: InativityService, - private storageService: StorageService,) { + private storageService: StorageService, + private webNotificationPopupService: WebNotificationPopupService) { + + this.webNotificationPopupService.askNotificationPermission() this.router.events.subscribe((val) => { document.querySelectorAll('ion-modal').forEach((e: any) => e.remove()) @@ -176,6 +180,8 @@ export class HomePage implements OnInit { synchro.registerCallback('Notification', (DataArray)=> { + this.webNotificationPopupService.sendNotification(DataArray.Object) + this.storageService.get('Notifications').then((data)=>{ data.push(DataArray) this.storageService.store("Notifications", data) diff --git a/src/app/services/notification/web-notification-popup.service.spec.ts b/src/app/services/notification/web-notification-popup.service.spec.ts new file mode 100644 index 000000000..e45f02163 --- /dev/null +++ b/src/app/services/notification/web-notification-popup.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { WebNotificationPopupService } from './web-notification-popup.service'; + +describe('WebNotificationPopupService', () => { + let service: WebNotificationPopupService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(WebNotificationPopupService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/notification/web-notification-popup.service.ts b/src/app/services/notification/web-notification-popup.service.ts new file mode 100644 index 000000000..9520630a9 --- /dev/null +++ b/src/app/services/notification/web-notification-popup.service.ts @@ -0,0 +1,47 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class WebNotificationPopupService { + + constructor() { } + + + askNotificationPermission() { + + // function to actually ask the permissions + function handlePermission(permission) {} + + // Let's check if the browser supports notifications + if (!('Notification' in window)) { + console.log("This browser does not support notifications."); + } else { + if(this.checkNotificationPromise()) { + Notification.requestPermission() + .then((permission) => { + handlePermission(permission); + }) + } else { + Notification.requestPermission(function(permission) { + handlePermission(permission); + }); + } + } + } + + + private checkNotificationPromise() { + try { + Notification.requestPermission().then(); + } catch(e) { + return false; + } + + return true; + } + + sendNotification(message) { + var n = new Notification(message); + } +}