import { ChangeDetectionStrategy , Component , Injector } from '@angular/core' ; import { AppBootstrapService } from '../services/app-bootstrap.service' ; import { CardsInitService } from '../services/cards-init.service' ; import { DebugService } from '../services/debug.service' ; import { OverwolfService } from '../services/overwolf.service' ; import { PreferencesService } from '../services/preferences.service' ; @ Component ( { selector : 'app-root' , styleUrls : [ `../../css/component/app.component.scss` ] , template : ` <div></div> ` , changeDetection : ChangeDetectionStrategy . OnPush , } ) export class AppComponent { constructor ( private readonly initCardsService , private readonly injector , private readonly debug , private readonly ow , private readonly prefs ) { this . init ( ) ; } private async init ( ) { console . debug ( 'init cards service' ) ; await this . initCardsService . init ( ) ; console . debug ( 'init done' ) ; const launchAppOnGameStart = ( await this . prefs . getPreferences ( ) ) . launchAppOnGameStart ; console . log ( 'should launch on game start?' , launchAppOnGameStart ) ; const appLaunchedByGameLaunch = this . isLaunchedByGameEvent ( ) ; console . log ( 'is app launched by a game event?' , appLaunchedByGameLaunch ) ; const shouldLaunchFullApp = launchAppOnGameStart || ! appLaunchedByGameLaunch ; console . log ( 'should launch app?' , shouldLaunchFullApp ) ; if ( shouldLaunchFullApp ) { try { this . injector . get ( AppBootstrapService ) . init ( ) ; } catch ( e ) { console . error ( e ) ; } } else { console . log ( 'not starting app, waiting for manual launch' ) ; this . ow . addAppLaunchTriggeredListener ( ( result ) => { console . log ( 'starting app' ) ; this . injector . get ( AppBootstrapService ) . init ( ) ; } ) ; } } private isLaunchedByGameEvent ( ) { console . log ( 'window location' , window . location . href ) ; if ( ! window . location . href ) { return false ; } const splitParams = window . location . href . split ( '?' ) ; if ( ! splitParams || splitParams . length < 2 ) { return false ; } const urlSearchParams = splitParams [ 1 ] ; if ( ! urlSearchParams ) { return false ; } const searchParams = urlSearchParams . split ( '&' ) ; if ( ! searchParams ) { return false ; } for ( const param of searchParams ) { const split = param . split ( '=' ) ; if ( ! split || split . length < 2 ) { return false ; } const key = split [ 0 ] ; if ( key === 'source' ) { return split [ 1 ] === 'gamelaunchevent' ; } } return false ; } }