import { Injectable } from '@angular/core'; import { SessionStorageService } from '@ucap-webmessenger/web-storage'; import { EnviromentUtilService } from '@ucap-webmessenger/util'; import { DeviceType } from '@ucap-webmessenger/core'; import { EnvironmentsInfo, KEY_ENVIRONMENTS_INFO } from '@app/types'; import { AppNotificationService } from './notification.service'; @Injectable() export class AppService { constructor( private enviromentUtilService: EnviromentUtilService, private sessionStorageService: SessionStorageService, private appNotificationService: AppNotificationService ) {} public postInit(): Promise { const initPromise = new Promise((resolve, reject) => { try { let deviceType: DeviceType; if (this.enviromentUtilService.nodeWebkit()) { deviceType = DeviceType.PC; } else if (this.enviromentUtilService.android()) { deviceType = DeviceType.Android; } else if (this.enviromentUtilService.ios()) { deviceType = DeviceType.iOS; } else { deviceType = DeviceType.Web; } this.sessionStorageService.set( KEY_ENVIRONMENTS_INFO, { deviceType } ); this.appNotificationService.subscribe(); resolve(); } catch (error) { reject(); } }); return Promise.all([initPromise]); } }