license import { AfterViewInit , Component , OnInit } from '@angular/core' ; import { AnalyticsService } from './@core/utils/analytics.service' ; import { SeoService } from './@core/utils/seo.service' ; import { TranslateService } from '@ngx-translate/core' ; import { ILanguage , LanguagesEnum } from '@gauzy/contracts' ; import { LanguagesService , Store } from './@core/services' ; import { environment } from '../environments/environment' ; import * as _ from 'underscore' ; import { UntilDestroy , untilDestroyed } from '@ngneat/until-destroy' ; @ UntilDestroy ( { checkProperties : true } ) @ Component ( { selector : 'ga-app' , template : '<router-outlet *ngIf="!loading"></router-outlet>' } ) export class AppComponent implements OnInit , AfterViewInit { loading : boolean = true ; constructor ( private readonly analytics , private readonly seoService , private readonly store , private readonly languagesService , public readonly translate ) { } async ngOnInit ( ) { if ( environment . CHATWOOT_SDK_TOKEN ) { this . loadChatwoot ( document , 'script' ) ; } this . analytics . trackPageViews ( ) ; this . seoService . trackCanonicalChanges ( ) ; this . store . systemLanguages$ . pipe ( untilDestroyed ( this ) ) . subscribe ( ( languages ) => { const browserLang = this . translate . getBrowserLang ( ) ; const defaultLanguages = Object . values ( LanguagesEnum ) ; const systemLanguages = _ . pluck ( languages , 'code' ) ; systemLanguages . concat ( defaultLanguages ) ; this . translate . setDefaultLang ( LanguagesEnum . ENGLISH ) ; this . translate . use ( systemLanguages . includes ( browserLang ) ? browserLang : LanguagesEnum . ENGLISH ) ; this . translate . onLangChange . subscribe ( ( ) => { this . loading = false ; } ) ; } ) ; if ( Number ( this . store . serverConnection ) === 0 ) { this . loading = false ; } } async ngAfterViewInit ( ) { await this . loadLanguages ( ) ; } private async loadLanguages ( ) { const { items = [ ] } = await this . languagesService . getSystemLanguages ( ) ; this . store . systemLanguages = items . filter ( ( item ) => item . is_system ) ; } private loadChatwoot ( d , t ) { var chatwootBaseUrl = 'https://app.chatwoot.com' ; var g = d . createElement ( t ) , s = d . getElementsByTagName ( t ) [ 0 ] ; g . src = chatwootBaseUrl + '/packs/js/sdk.js' ; s . parentNode . insertBefore ( g , s ) ; g . onload = function ( ) { window [ 'chatwootSDK' ] . run ( { websiteToken : environment . CHATWOOT_SDK_TOKEN , baseUrl : chatwootBaseUrl } ) ; } ; } }