import { RunningGameInfo } from './ow-types' ; export interface OWGameListenerDelegate { onGameStarted ? ( info ) : void ; onGameEnded ? ( info ) : void ; onGameResolutionChanged ? ( info ) : void ; } export class OWGameListener { constructor ( private readonly delegate ) { } public start ( ) { overwolf . games . onGameInfoUpdated . addListener ( this . onGameInfoUpdated ) ; overwolf . games . getRunningGameInfo ( this . onRunningGameInfo ) ; } public stop ( ) { overwolf . games . onGameInfoUpdated . removeListener ( this . onGameInfoUpdated ) ; } private onGameInfoUpdated = ( update ) : void => { if ( ! update ?. gameInfo ) { return ; } if ( update . resolutionChanged ) { if ( this . delegate . onGameResolutionChanged ) { this . delegate . onGameResolutionChanged ( { ... update . gameInfo } ) ; } } if ( ! update . runningChanged && ! update . gameChanged ) { return ; } if ( update . gameInfo . isRunning ) { if ( this . delegate . onGameStarted ) { this . delegate . onGameStarted ( { ... update . gameInfo } ) ; } } else { if ( this . delegate . onGameEnded ) { this . delegate . onGameEnded ( { ... update . gameInfo } ) ; } } } ; private onRunningGameInfo = ( info ) : void => { if ( ! info ) { return ; } if ( info . isRunning ) { if ( this . delegate . onGameStarted ) { this . delegate . onGameStarted ( { ... info } ) ; } } } ; }