2019-11-11 18:09:47 +09:00
|
|
|
import { Injectable, Inject } from '@angular/core';
|
2019-09-27 12:53:21 +09:00
|
|
|
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';
|
2019-11-11 15:53:39 +09:00
|
|
|
import { AppNotificationService } from './notification.service';
|
2019-11-11 18:09:47 +09:00
|
|
|
import { NativeService, UCAP_NATIVE_SERVICE } from '@ucap-webmessenger/native';
|
2019-09-19 17:03:39 +09:00
|
|
|
|
2019-09-19 10:40:16 +09:00
|
|
|
@Injectable()
|
|
|
|
export class AppService {
|
2019-09-27 12:53:21 +09:00
|
|
|
constructor(
|
|
|
|
private enviromentUtilService: EnviromentUtilService,
|
|
|
|
private sessionStorageService: SessionStorageService,
|
2019-11-11 18:09:47 +09:00
|
|
|
private appNotificationService: AppNotificationService,
|
|
|
|
@Inject(UCAP_NATIVE_SERVICE) private nativeService: NativeService
|
2019-09-27 12:53:21 +09:00
|
|
|
) {}
|
2019-09-19 10:40:16 +09:00
|
|
|
|
2019-11-11 15:53:39 +09:00
|
|
|
public postInit(): Promise<any> {
|
|
|
|
const initPromise = new Promise<void>((resolve, reject) => {
|
2019-09-27 12:53:21 +09:00
|
|
|
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<EnvironmentsInfo>(
|
|
|
|
KEY_ENVIRONMENTS_INFO,
|
|
|
|
{
|
|
|
|
deviceType
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
this.appNotificationService.subscribe();
|
2019-11-11 18:09:47 +09:00
|
|
|
this.nativeService.postAppInit();
|
2019-09-27 12:53:21 +09:00
|
|
|
resolve();
|
|
|
|
} catch (error) {
|
|
|
|
reject();
|
|
|
|
}
|
2019-09-19 10:40:16 +09:00
|
|
|
});
|
2019-11-11 15:53:39 +09:00
|
|
|
|
|
|
|
return Promise.all([initPromise]);
|
2019-09-19 10:40:16 +09:00
|
|
|
}
|
|
|
|
}
|