import { Component , OnInit } from '@angular/core' ; import { Angulartics2GoogleAnalytics } from 'angulartics2/ga' ; import { environment } from '@env/environment' ; import { Logger , AuthenticationService } from '@app/core' ; import { ErrorHandlerService } from './core/error-handler.service' ; import { MatSnackBar } from '@angular/material' ; const log = new Logger ( 'App' ) ; @ Component ( { selector : 'app-root' , templateUrl : './app.component.html' , styleUrls : [ './app.component.scss' ] } ) export class AppComponent implements OnInit { constructor ( private angulartics2GoogleAnalytics , private errorHandler , private snackBar , private authService ) { this . authService . handleAuthentication ( ) ; angulartics2GoogleAnalytics . startTracking ( ) ; this . errorHandler . subj_notification . subscribe ( message => { let messageString = '' ; if ( typeof message === 'string' ) { messageString = message ; } else if ( ! message . message . indexOf ( 'Network' ) ) { messageString = 'There appears to be something wrong with your internet connection. Please check and try again.' ; } else { messageString = message . message ; } this . snackBar . open ( messageString , 'Okay' , { duration : 15000 } ) ; } ) ; } ngOnInit ( ) { if ( environment . production ) { Logger . enableProductionMode ( ) ; } this . angulartics2GoogleAnalytics . eventTrack ( environment . version , { category : 'App initialized' } ) ; if ( this . authService . isAuthenticated ( ) ) { this . authService . renewTokens ( ) ; } else { this . authService . softLogout ( ) ; } } }