import { BattlegroundsState } from '../../../../models/battlegrounds/battlegrounds-state' ; import { Preferences } from '../../../../models/preferences' ; import { OverwolfService } from '../../../overwolf.service' ; import { PreferencesService } from '../../../preferences.service' ; import { isWindowClosed } from '../../../utils' ; import { BattlegroundsStoreEvent } from '../events/_battlegrounds-store-event' ; import { BattlegroundsOverlay } from './battlegrounds-overlay' ; export class BgsMainWindowOverlay implements BattlegroundsOverlay { private closedByUser : boolean ; private bgsActive = true ; constructor ( private readonly prefs , private readonly ow ) { } public async processEvent ( gameEvent ) { if ( gameEvent . type === 'BgsMatchStartEvent' ) { this . closedByUser = false ; } else if ( gameEvent . type === 'BgsCloseWindowEvent' ) { this . closedByUser = true ; } } public async handleDisplayPreferences ( preferences ) { this . bgsActive = preferences . bgsEnableApp && preferences . bgsFullToggle ; } public async updateOverlay ( state ) { const prefs = await this . prefs . getPreferences ( ) ; const windowId = prefs . bgsUseOverlay ? OverwolfService . BATTLEGROUNDS_WINDOW_OVERLAY : OverwolfService . BATTLEGROUNDS_WINDOW ; const battlegroundsWindow = await this . ow . getWindowState ( windowId ) ; if ( battlegroundsWindow . window_state_ex === 'minimized' && ! state . forceOpen ) { return ; } const inGame = state && state . inGame ; if ( state ?. forceOpen ) { this . closedByUser = false ; } if ( inGame && this . bgsActive && state . forceOpen ) { await this . ow . obtainDeclaredWindow ( windowId ) ; if ( battlegroundsWindow . window_state_ex !== 'maximized' && battlegroundsWindow . stateEx !== 'maximized' ) { await this . ow . restoreWindow ( windowId ) ; await this . ow . bringToFront ( windowId ) ; } } else if ( ! isWindowClosed ( battlegroundsWindow . window_state_ex ) && ! isWindowClosed ( battlegroundsWindow . stateEx ) && this . closedByUser ) { await this . ow . closeWindow ( windowId ) ; } } public async handleHotkeyPressed ( state , force = false ) { const prefs = await this . prefs . getPreferences ( ) ; const windowId = prefs . bgsUseOverlay ? OverwolfService . BATTLEGROUNDS_WINDOW_OVERLAY : OverwolfService . BATTLEGROUNDS_WINDOW ; const window = await this . ow . obtainDeclaredWindow ( windowId ) ; const inGame = state && state . inGame ; if ( ! force && ! inGame ) { return ; } if ( isWindowClosed ( window . stateEx ) || window . stateEx === 'minimized' ) { this . closedByUser = false ; await this . ow . obtainDeclaredWindow ( windowId ) ; await this . ow . restoreWindow ( windowId ) ; await this . ow . bringToFront ( windowId ) ; } else if ( ! isWindowClosed ( window . stateEx ) ) { this . closedByUser = true ; await this . ow . hideWindow ( windowId ) ; } } }