import { APP_INITIALIZER , NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; import { ServiceWorkerModule , SwUpdate } from '@angular/service-worker' ; import { MatSnackBar } from '@angular/material/snack-bar' ; import { environment } from '@environments/environment' ; import { AppRoutingModule } from './app-routing.module' ; import { AppComponent } from './app.component' ; import { CoreModule } from './core/core.module' ; import { SettingsService } from './core/settings' ; import { getIndexedDBState , BotStorageService , LocalStorageService } from './core/storage' ; import { UiService } from './core/ui' ; import { DocModule } from './doc' ; import { DocsModule } from './docs/docs.module' ; import { HistoryModule } from './history/history.module' ; import { SharedModule } from './shared/shared.module' ; @ NgModule ( { imports : [ BrowserModule , ServiceWorkerModule . register ( '/ngsw-worker.js' , { enabled : environment . production } ) , BrowserAnimationsModule , CoreModule , AppRoutingModule , DocsModule , DocModule , HistoryModule , SharedModule , ] , declarations : [ AppComponent ] , providers : [ { provide : APP_INITIALIZER , useFactory : ( settings , localStorage , botStorage ) => async ( ) => { await getIndexedDBState ( ) ; await settings . init ( ) ; await localStorage . init ( settings ) ; } , deps : [ SettingsService , LocalStorageService , BotStorageService ] , multi : true , } , ] , bootstrap : [ AppComponent ] , } ) export class AppModule { constructor ( sw , ui , snackBar ) { sw . available . subscribe ( ( event ) => { const version = ( event . available . appData as any ) . version ; ui . appUpdate . next ( { version } ) ; } ) ; window . addEventListener ( 'beforeinstallprompt' , ( e ) => { e . preventDefault ( ) ; ui . appInstall . next ( true ) ; ui . appInstallEvent = e ; } ) ; window . addEventListener ( 'appinstalled' , ( evt ) => { snackBar . open ( 'Application has successfully been installed' , 'Close' , { duration : 3000 } ) ; } ) ; } }