diff --git a/src/app/app.config.ts b/src/app/app.config.ts new file mode 100644 index 000000000..65f72f698 --- /dev/null +++ b/src/app/app.config.ts @@ -0,0 +1,89 @@ +import { DOCUMENT } from '@angular/common'; +import { provideHttpClient } from '@angular/common/http'; +import { ApplicationConfig } from '@angular/core'; +import { APP_INITIALIZER, Provider, importProvidersFrom } from '@angular/core'; +import { MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field'; +import { + MAT_TOOLTIP_DEFAULT_OPTIONS, + MatTooltipDefaultOptions +} from '@angular/material/tooltip'; +import { BrowserModule } from '@angular/platform-browser'; +import { provideAnimations } from '@angular/platform-browser/animations'; +import { provideRouter } from '@angular/router'; +import { ServiceWorkerModule } from '@angular/service-worker'; + +import { provideAuthentification } from '@igo2/auth'; +import { withMicrosoftSupport } from '@igo2/auth/microsoft'; +import { provideIcon } from '@igo2/common/icon'; +import { IgoCoreModule } from '@igo2/core'; +import { ConfigService, provideConfig } from '@igo2/core/config'; +import { provideTranslation, withAsyncConfig } from '@igo2/core/language'; +import { IgoMessageModule } from '@igo2/core/message'; +import { RouteService } from '@igo2/core/route'; +import { provideOffline } from '@igo2/geo'; +import { loadTheme } from '@igo2/utils'; + +import { first } from 'rxjs'; +import { environment } from 'src/environments'; + +import { PortalModule } from './pages'; + +const DEFAULT_THEME = 'blue-theme'; + +const TOOLTIP_OPTIONS: MatTooltipDefaultOptions = { + showDelay: 500, + hideDelay: 0, + touchendHideDelay: 0, + disableTooltipInteractivity: true +}; + +export const appConfig: ApplicationConfig = { + providers: [ + importProvidersFrom( + BrowserModule, + IgoCoreModule, + IgoMessageModule, + PortalModule, + ServiceWorkerModule.register('ngsw-worker.js', { + enabled: environment.igo.app.pwa.enabled, + registrationStrategy: 'registerWithDelay:5000' + }) + ), + provideHttpClient(), + provideAnimations(), + provideRouter([]), + provideConfig({ + default: environment.igo, + path: './config/config.json' + }), + provideTranslation(withAsyncConfig()), + provideAuthentification( + withMicrosoftSupport('add'), + withMicrosoftSupport('b2c') + ), + provideOffline(environment.igo.app.offline), + provideIcon(), + provideTheme(), + RouteService, + { provide: MAT_TOOLTIP_DEFAULT_OPTIONS, useValue: TOOLTIP_OPTIONS }, + { + provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, + useValue: { appearance: 'fill' } + } + ] +}; + +function provideTheme(): Provider { + return { + provide: APP_INITIALIZER, + useFactory: (configService: ConfigService, document: Document) => () => + configService.isLoaded$ + .pipe(first((isLoaded) => isLoaded)) + .subscribe(() => { + const theme = configService.getConfig('theme', DEFAULT_THEME); + loadTheme(document, theme); + }), + deps: [ConfigService, DOCUMENT], + multi: true + }; +} diff --git a/src/main.ts b/src/main.ts index 5801c455b..8a19c25fd 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,99 +1,14 @@ -import { DOCUMENT } from '@angular/common'; -import { provideHttpClient } from '@angular/common/http'; -import { - APP_INITIALIZER, - Provider, - enableProdMode, - importProvidersFrom -} from '@angular/core'; -import { MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field'; -import { - MAT_TOOLTIP_DEFAULT_OPTIONS, - MatTooltipDefaultOptions -} from '@angular/material/tooltip'; -import { BrowserModule, bootstrapApplication } from '@angular/platform-browser'; -import { provideAnimations } from '@angular/platform-browser/animations'; -import { provideRouter } from '@angular/router'; -import { ServiceWorkerModule } from '@angular/service-worker'; - -import { provideAuthentification } from '@igo2/auth'; -import { withMicrosoftSupport } from '@igo2/auth/microsoft'; -import { provideIcon } from '@igo2/common/icon'; -import { IgoCoreModule } from '@igo2/core'; -import { ConfigService, provideConfig } from '@igo2/core/config'; -import { provideTranslation, withAsyncConfig } from '@igo2/core/language'; -import { IgoMessageModule } from '@igo2/core/message'; -import { RouteService } from '@igo2/core/route'; -import { provideOffline } from '@igo2/geo'; -import { loadTheme } from '@igo2/utils'; +import { enableProdMode } from '@angular/core'; +import { bootstrapApplication } from '@angular/platform-browser'; import 'hammerjs'; -import { first } from 'rxjs'; import { AppComponent } from './app/app.component'; -import { PortalModule } from './app/pages'; +import { appConfig } from './app/app.config'; import { environment } from './environments/environment'; -const DEFAULT_THEME = 'blue-theme'; - -const TOOLTIP_OPTIONS: MatTooltipDefaultOptions = { - showDelay: 500, - hideDelay: 0, - touchendHideDelay: 0, - disableTooltipInteractivity: true -}; - if (environment.production) { enableProdMode(); } -bootstrapApplication(AppComponent, { - providers: [ - importProvidersFrom( - BrowserModule, - IgoCoreModule, - IgoMessageModule, - PortalModule, - ServiceWorkerModule.register('ngsw-worker.js', { - enabled: environment.igo.app.pwa.enabled, - registrationStrategy: 'registerWithDelay:5000' - }) - ), - provideHttpClient(), - provideAnimations(), - provideRouter([]), - provideConfig({ - default: environment.igo, - path: './config/config.json' - }), - provideTranslation(withAsyncConfig()), - provideAuthentification( - withMicrosoftSupport('add'), - withMicrosoftSupport('b2c') - ), - provideOffline(environment.igo.app.offline), - provideIcon(), - provideTheme(), - RouteService, - { provide: MAT_TOOLTIP_DEFAULT_OPTIONS, useValue: TOOLTIP_OPTIONS }, - { - provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, - useValue: { appearance: 'fill' } - } - ] -}).catch((err) => console.log(err)); - -function provideTheme(): Provider { - return { - provide: APP_INITIALIZER, - useFactory: (configService: ConfigService, document: Document) => () => - configService.isLoaded$ - .pipe(first((isLoaded) => isLoaded)) - .subscribe(() => { - const theme = configService.getConfig('theme', DEFAULT_THEME); - loadTheme(document, theme); - }), - deps: [ConfigService, DOCUMENT], - multi: true - }; -} +bootstrapApplication(AppComponent, appConfig).catch((err) => console.log(err));