2019-11-12 09:54:21 +00:00
|
|
|
import { NgModule, APP_INITIALIZER, Type } from '@angular/core';
|
|
|
|
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
|
|
|
|
|
|
|
import { UCAP_NATIVE_SERVICE, NativeService } from '@ucap-webmessenger/native';
|
2019-09-18 06:02:21 +00:00
|
|
|
|
2019-09-19 05:15:43 +00:00
|
|
|
import { RESOLVERS } from './resolvers';
|
2019-09-19 01:40:16 +00:00
|
|
|
import { SERVICES } from './services';
|
|
|
|
import { AppService } from './services/app.service';
|
2019-11-12 09:54:21 +00:00
|
|
|
|
2019-11-11 06:53:39 +00:00
|
|
|
import { environment } from '../environments/environment';
|
2019-11-12 09:54:21 +00:00
|
|
|
import { BrowserNativeService } from '@ucap-webmessenger/native-browser';
|
|
|
|
import { ElectronNativeService } from '@ucap-webmessenger/native-electron';
|
2019-09-19 01:40:16 +00:00
|
|
|
|
2019-11-12 09:54:21 +00:00
|
|
|
export function initializeApp(
|
|
|
|
appService: AppService,
|
|
|
|
nativeService: NativeService
|
|
|
|
) {
|
2019-09-19 01:40:16 +00:00
|
|
|
return (): Promise<any> => {
|
|
|
|
return appService.postInit();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-11-12 09:54:21 +00:00
|
|
|
// export function nativeServiceFactory(httpClient: HttpClient) {
|
|
|
|
// if ('browser' === environment.runtime) {
|
|
|
|
// return import('@ucap-webmessenger/native-browser').then(
|
|
|
|
// m => new m.BrowserNativeService(httpClient)
|
|
|
|
// );
|
|
|
|
// } else {
|
|
|
|
// return import('@ucap-webmessenger/native-electron').then(
|
|
|
|
// m => new m.ElectronNativeService()
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2019-09-18 06:02:21 +00:00
|
|
|
@NgModule({
|
|
|
|
imports: [],
|
|
|
|
exports: [],
|
|
|
|
providers: [
|
2019-11-11 06:53:39 +00:00
|
|
|
{
|
|
|
|
provide: UCAP_NATIVE_SERVICE,
|
2019-11-12 09:54:21 +00:00
|
|
|
// useFactory: nativeServiceFactory,
|
|
|
|
useClass:
|
|
|
|
'browser' === environment.runtime
|
|
|
|
? BrowserNativeService
|
|
|
|
: ElectronNativeService,
|
|
|
|
deps: [HttpClient],
|
2019-11-11 06:53:39 +00:00
|
|
|
},
|
2019-11-12 09:54:21 +00:00
|
|
|
...SERVICES,
|
|
|
|
...RESOLVERS,
|
2019-09-19 01:40:16 +00:00
|
|
|
{
|
|
|
|
provide: APP_INITIALIZER,
|
|
|
|
useFactory: initializeApp,
|
2019-11-11 09:09:47 +00:00
|
|
|
deps: [AppService, UCAP_NATIVE_SERVICE],
|
2019-11-12 09:54:21 +00:00
|
|
|
multi: true,
|
|
|
|
},
|
|
|
|
],
|
2019-09-18 06:02:21 +00:00
|
|
|
})
|
|
|
|
export class AppProviderModule {}
|