import { Injectable } from '@angular/core' ; import { RedditUserInfo } from '../models/mainwindow/reddit-user-info' ; import { TwitterUserInfo } from '../models/mainwindow/twitter-user-info' ; import { ActiveSubscriptionPlan } from '../models/overwolf/profile/active-subscription-plan' ; import { CurrentUser } from '../models/overwolf/profile/current-user' ; import { Preferences } from '../models/preferences' ; declare let overwolf ; const HEARTHSTONE_GAME_ID = 9898 ; const NO_AD_PLAN = 13 ; @ Injectable ( ) export class OverwolfService { public static MAIN_WINDOW = 'MainWindow' ; public static COLLECTION_WINDOW = 'CollectionWindow' ; public static COLLECTION_WINDOW_OVERLAY = 'CollectionOverlayWindow' ; public static SETTINGS_WINDOW = 'SettingsWindow' ; public static SETTINGS_WINDOW_OVERLAY = 'SettingsOverlayWindow' ; public static LOADING_WINDOW = 'LoadingWindow' ; public static NOTIFICATIONS_WINDOW = 'NotificationsWindow' ; public static BATTLEGROUNDS_WINDOW = 'BattlegroundsWindow' ; public static BATTLEGROUNDS_WINDOW_OVERLAY = 'BattlegroundsOverlayWindow' ; public static FULL_SCREEN_OVERLAYS_WINDOW = 'FullScreenOverlaysWindow' ; public static FULL_SCREEN_OVERLAYS_CLICKTHROUGH_WINDOW = 'FullScreenOverlaysClickthroughWindow' ; public isOwEnabled ( ) { try { return overwolf && overwolf . windows ; } catch ( e ) { return false ; } } public getMainWindow ( ) { return overwolf . windows . getMainWindow ( ) ; } public getCollectionWindow ( prefs ) { const windowName = this . getCollectionWindowName ( prefs ) ; return this . obtainDeclaredWindow ( windowName ) ; } public getBattlegroundsWindow ( prefs ) { const windowName = this . getBattlegroundsWindowName ( prefs ) ; return this . obtainDeclaredWindow ( windowName ) ; } public getSettingsWindow ( prefs ) { const windowName = this . getSettingsWindowName ( prefs ) ; return this . obtainDeclaredWindow ( windowName ) ; } public getCollectionWindowName ( prefs ) { return prefs . collectionUseOverlay ? OverwolfService . COLLECTION_WINDOW_OVERLAY : OverwolfService . COLLECTION_WINDOW ; } public getBattlegroundsWindowName ( prefs ) { return prefs . bgsUseOverlay ? OverwolfService . BATTLEGROUNDS_WINDOW_OVERLAY : OverwolfService . BATTLEGROUNDS_WINDOW ; } public getSettingsWindowName ( prefs ) { return prefs . collectionUseOverlay ? OverwolfService . SETTINGS_WINDOW_OVERLAY : OverwolfService . SETTINGS_WINDOW ; } public addStateChangedListener ( targetWindowName , callback ) { const listener = ( message ) => { if ( message . window_name !== targetWindowName && message . window_id !== targetWindowName ) { return ; } callback ( message ) ; } ; overwolf . windows . onStateChanged . addListener ( listener ) ; return listener ; } public removeStateChangedListener ( listener ) { overwolf . windows . onStateChanged . removeListener ( listener ) ; } public addAppLaunchTriggeredListener ( callback ) { overwolf . extensions . onAppLaunchTriggered . addListener ( callback ) ; } public addGameInfoUpdatedListener ( callback ) { overwolf . games . onGameInfoUpdated . addListener ( callback ) ; return callback ; } public removeGameInfoUpdatedListener ( listener ) { overwolf . games . onGameInfoUpdated . removeListener ( listener ) ; } public addGameEventsErrorListener ( callback ) { overwolf . games . events . onError . addListener ( callback ) ; } public addGameEventInfoUpdates2Listener ( callback ) { overwolf . games . events . onInfoUpdates2 . addListener ( callback ) ; } public addGameEventsListener ( callback ) { overwolf . games . events . onNewEvents . addListener ( callback ) ; } deprecated public addMessageReceivedListener ( callback ) { overwolf . windows . onMessageReceived . addListener ( callback ) ; return callback ; } public removeMessageReceivedListener ( listener ) { overwolf . windows . onMessageReceived . removeListener ( listener ) ; } public setWindowPassthrough ( windowId ) { return new Promise < void > ( ( resolve ) => { overwolf . windows . setWindowStyle ( windowId , overwolf . windows . enums . WindowStyle . InputPassThrough , ( data ) => { resolve ( ) ; } ) ; } ) ; } public addVideoCaptureSettingsChangedListener ( callback ) { overwolf . settings . OnVideoCaptureSettingsChanged . addListener ( callback ) ; return callback ; } public removeVideoCaptureSettingsChangedListener ( listener ) { overwolf . settings . OnVideoCaptureSettingsChanged . removeListener ( listener ) ; } public addHotKeyPressedListener ( hotkey , callback ) { overwolf . settings . hotkeys . onPressed . addListener ( ( hotkeyPressed ) => { if ( hotkeyPressed ?. name === hotkey ) { callback ( ) ; } } ) ; } public addHotkeyChangedListener ( callback ) { const listener = ( message ) => { callback ( message ) ; } ; overwolf . settings . hotkeys . onChanged . addListener ( listener ) ; return listener ; } public removeHotkeyChangedListener ( listener ) { overwolf . settings . hotkeys . onChanged . removeListener ( listener ) ; } public addMouseUpListener ( callback ) { overwolf . games . inputTracking . onMouseUp . addListener ( callback ) ; } public addKeyUpListener ( callback ) { overwolf . games . inputTracking . onKeyUp . addListener ( callback ) ; } public addUncaughtExceptionHandler ( handler ) { overwolf . extensions . onUncaughtException . addListener ( handler ) ; } public openUrlInOverwolfBrowser ( url ) { overwolf . utils . openUrlInOverwolfBrowser ( url ) ; } public openUrlInDefaultBrowser ( url ) { overwolf . utils . openUrlInDefaultBrowser ( url ) ; } public addSessionInfoChangedLisetner ( callback ) { overwolf . egs . onSessionInfoChanged . addListener ( callback ) ; } public addMatchSelectionInfoChangedListener ( callback ) { overwolf . egs . onMatchSelectionChanged . addListener ( callback ) ; } public async getOpenWindows ( ) { return new Promise < any > ( ( resolve ) => { overwolf . windows . getOpenWindows ( ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async getWindowState ( windowName ) { return new Promise < any > ( ( resolve ) => { overwolf . windows . getWindowState ( windowName , ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async getWindowsStates ( ) { return new Promise < any > ( ( resolve ) => { overwolf . windows . getWindowsStates ( ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async getManifest ( ) { return new Promise < Manifest > ( ( resolve ) => { overwolf . extensions . getManifest ( 'lnknbakkpommmjjdnelmfbjjdbocfpnpbkijjnob' , ( result ) => { resolve ( result ) ; } ) ; } ) ; } public async getAppVersion ( extensionId ) { return new Promise < string > ( ( resolve ) => { overwolf . extensions . getManifest ( extensionId , ( result ) => { resolve ( result . meta . version ) ; } ) ; } ) ; } public async getSelectedMatch ( ) { return new Promise < { gameId : number ; matchId : string ; sessionId : string ; } > ( ( resolve ) => { overwolf . egs . getSelectedMatch ( ( selectedMatchInfo ) => { resolve ( selectedMatchInfo ) ; } ) ; } ) ; } public async getCurrentUser ( ) { return new Promise < CurrentUser > ( ( resolve ) => { overwolf . profile . getCurrentUser ( ( user ) => { resolve ( user ) ; } ) ; } ) ; } public openLoginDialog ( ) { overwolf . profile . openLoginDialog ( ) ; } public addLoginStateChangedListener ( callback ) { overwolf . profile . onLoginStateChanged . addListener ( callback ) ; } public async closeWindow ( windowId ) { return new Promise < any > ( ( resolve ) => { overwolf . windows . close ( windowId , ( result ) => { resolve ( result ) ; } ) ; } ) ; } deprecated public async closeWindowFromName ( windowName ) { const window = await this . obtainDeclaredWindow ( windowName ) ; return new Promise < any > ( ( resolve ) => { overwolf . windows . close ( window . id , ( result ) => { resolve ( result ) ; } ) ; } ) ; } public async restoreWindow ( windowId ) { return new Promise < any > ( ( resolve ) => { try { overwolf . windows . restore ( windowId , async ( result ) => { resolve ( result ) ; } ) ; } catch ( e ) { console . warn ( 'Exception while restoring window' , e ) ; resolve ( null ) ; } } ) ; } public async setTopmost ( windowId ) { return new Promise < any > ( ( resolve ) => { try { overwolf . windows . setTopmost ( windowId , true , ( result ) => { resolve ( result ) ; } ) ; } catch ( e ) { console . warn ( 'exception when setting topmost' , windowId , e ) ; resolve ( null ) ; } } ) ; } public async bringToFront ( windowId ) { return new Promise < any > ( ( resolve ) => { try { overwolf . windows . bringToFront ( windowId , false , ( result ) => { resolve ( result ) ; } ) ; } catch ( e ) { console . warn ( 'exception when bringing to front' , windowId , e ) ; resolve ( null ) ; } } ) ; } public async sendToBack ( windowId ) { return new Promise < any > ( ( resolve ) => { try { overwolf . windows . sendToBack ( windowId , false , ( result ) => { resolve ( result ) ; } ) ; } catch ( e ) { console . warn ( 'exception when sending to back' , windowId , e ) ; resolve ( null ) ; } } ) ; } public async hideWindow ( windowId ) { return new Promise < any > ( ( resolve ) => { try { overwolf . windows . hide ( windowId , ( result ) => { resolve ( result ) ; } ) ; } catch ( e ) { console . warn ( 'Exception while hiding window' , e ) ; resolve ( null ) ; } } ) ; } public async hideCollectionWindow ( prefs ) { const collectionWindow = await this . getCollectionWindow ( prefs ) ; const settingsWindow = await this . getSettingsWindow ( prefs ) ; return new Promise < void > ( async ( resolve ) => { await Promise . all ( [ this . hideWindow ( collectionWindow . id ) , this . hideWindow ( settingsWindow . id ) ] ) ; resolve ( ) ; } ) ; } public minimizeWindow ( windowId ) { return new Promise < any > ( ( resolve ) => { overwolf . windows . minimize ( windowId , ( result ) => { resolve ( result ) ; } ) ; } ) ; } public maximizeWindow ( windowId ) { return new Promise < any > ( ( resolve ) => { overwolf . windows . maximize ( windowId , ( result ) => { resolve ( result ) ; } ) ; } ) ; } public dragMove ( windowId , callback ? ) { overwolf . windows . dragMove ( windowId , callback ) ; } public async dragResize ( windowId , edge ) { return new Promise < void > ( ( resolve ) => { overwolf . windows . dragResize ( windowId , edge , null , ( result ) => { resolve ( result ) ; } ) ; } ) ; } public async inGame ( ) { return new Promise < boolean > ( ( resolve ) => { overwolf . games . getRunningGameInfo ( ( res ) => { if ( this . gameRunning ( res ) ) { resolve ( true ) ; } resolve ( false ) ; } ) ; } ) ; } public inAnotherGame ( gameInfoResult ) { return ( gameInfoResult && gameInfoResult . gameInfo && gameInfoResult . gameInfo . isRunning && Math . floor ( gameInfoResult . gameInfo . id / 10 ) !== HEARTHSTONE_GAME_ID ) ; } public exitGame ( gameInfoResult ) { return ( ! gameInfoResult || ! gameInfoResult . gameInfo || ! gameInfoResult . gameInfo . isRunning || Math . floor ( gameInfoResult . gameInfo . id / 10 ) !== HEARTHSTONE_GAME_ID ) ; } public async getRunningGameInfo ( ) { return new Promise < any > ( ( resolve ) => { try { overwolf . games . getRunningGameInfo ( ( res ) => { resolve ( res ) ; } ) ; } catch ( e ) { console . warn ( 'Exception while getting running game info' , e ) ; resolve ( null ) ; } } ) ; } public async getSessionInfo ( ) { return new Promise < any > ( ( resolve ) => { overwolf . egs . getSessionInfo ( ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async getGameEventsInfo ( ) { return new Promise < any > ( ( resolve ) => { overwolf . games . events . getInfo ( ( info ) => { resolve ( info ) ; } ) ; } ) ; } public async setGameEventsRequiredFeatures ( features ) { return new Promise < any > ( ( resolve ) => { overwolf . games . events . setRequiredFeatures ( features , ( info ) => { resolve ( info ) ; } ) ; } ) ; } public async getHotKey ( hotkeyName ) { return new Promise < any > ( ( resolve ) => { overwolf . settings . hotkeys . get ( ( res ) => { const game = res . games [ HEARTHSTONE_GAME_ID ] ; const hotkey = game ?. find ( ( key ) => key . name === hotkeyName ) ; resolve ( hotkey ) ; } ) ; } ) ; } public async setVideoCaptureSettings ( resolution , fps ) { return new Promise < boolean > ( ( resolve ) => { overwolf . settings . setVideoCaptureSettings ( resolution , fps , ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async getVideoCaptureSettings ( ) { return new Promise < boolean > ( ( resolve ) => { overwolf . settings . getVideoCaptureSettings ( ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async setAudioCaptureSettings ( captureSystemSound , captureMicrophoneSound ) { return new Promise < boolean > ( ( resolve ) => { overwolf . settings . setAudioCaptureSettings ( captureSystemSound , captureMicrophoneSound , ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async getAudioCaptureSettings ( ) { return new Promise < boolean > ( ( resolve ) => { overwolf . settings . getAudioCaptureSettings ( ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async sendMessageWithName ( windowName , messageType , messageBody ? ) { const window = await this . obtainDeclaredWindow ( windowName ) ; return new Promise < void > ( ( resolve ) => { overwolf . windows . sendMessage ( window . id , messageType , messageBody , ( ) => { resolve ( ) ; } ) ; } ) ; } public async sendMessage ( windowId , messageType , messageBody ? ) { return new Promise < void > ( ( resolve ) => { overwolf . windows . sendMessage ( windowId , messageType , messageBody , ( ) => { resolve ( ) ; } ) ; } ) ; } public async obtainDeclaredWindow ( windowName ) { return new Promise < any > ( ( resolve , reject ) => { overwolf . windows . obtainDeclaredWindow ( windowName , ( res ) => { if ( res . status === 'success' ) { resolve ( res . window ) ; } else { resolve ( res ) ; } } ) ; } ) ; } public async getCurrentWindow ( ) { return new Promise < any > ( ( resolve ) => { try { overwolf . windows . getCurrentWindow ( ( res ) => { resolve ( res . window ) ; } ) ; } catch ( e ) { console . warn ( 'Exception while getting current window window' ) ; resolve ( null ) ; } } ) ; } public async getAppVideoCaptureFolderSize ( ) { return new Promise < boolean > ( ( resolve ) => { overwolf . media . getAppVideoCaptureFolderSize ( ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async getOverwolfVideosFolder ( ) { return new Promise < boolean > ( ( resolve ) => { overwolf . settings . getOverwolfVideosFolder ( ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async openWindowsExplorer ( path ) { return new Promise < boolean > ( ( resolve ) => { overwolf . utils . openWindowsExplorer ( path , ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async changeWindowPosition ( windowId , newX , newY ) { return new Promise < void > ( ( resolve ) => { try { overwolf . windows . changePosition ( windowId , Math . round ( newX ) , Math . round ( newY ) ) ; } catch ( e ) { console . error ( 'Exception while trying to changePosition' , windowId , newX , newY , e ) ; } resolve ( ) ; } ) ; } public async changeWindowSize ( windowId , width , height ) { return new Promise < void > ( ( resolve ) => { try { overwolf . windows . changeSize ( windowId , Math . round ( width ) , Math . round ( height ) ) ; } catch ( e ) { console . error ( 'Exception while trying to changeSize' , windowId , width , height , e ) ; } resolve ( ) ; } ) ; } public async turnOnReplays ( settings ) { return new Promise < any > ( ( resolve ) => { overwolf . media . replays . turnOn ( settings , ( result ) => { resolve ( result ) ; } ) ; } ) ; } public async turnOffReplays ( ) { return new Promise < void > ( ( resolve ) => { overwolf . media . replays . turnOff ( ( res ) => { resolve ( ) ; } ) ; } ) ; } public async startReplayCapture ( captureDuration ) { return new Promise < any > ( ( resolve , reject ) => { overwolf . media . replays . startCapture ( captureDuration , ( status ) => { if ( status === 'error' ) { console . warn ( '[overwolf-service] could not start capture' , status ) ; reject ( status ) ; } else { resolve ( status ) ; } } ) ; } ) ; } public async stopReplayCapture ( replayId ) { return new Promise < any > ( ( resolve ) => { overwolf . media . replays . stopCapture ( replayId , ( result ) => { resolve ( result ) ; } ) ; } ) ; } public async getReplayMediaState ( ) { return new Promise < boolean > ( ( resolve ) => { overwolf . media . replays . getState ( ( res ) => { resolve ( res . isOn ) ; } ) ; } ) ; } public async isGSEnabled ( ) { return new Promise < any > ( ( resolve ) => { overwolf . egs . isEnabled ( ( egsEnabledResult ) => { resolve ( egsEnabledResult ) ; } ) ; } ) ; } public async requestGSDisplay ( ) { return new Promise < any > ( ( resolve ) => { overwolf . egs . requestToDisplay ( ( displayRequestResult ) => { resolve ( displayRequestResult ) ; } ) ; } ) ; } public async getExtensionInfo ( extensionId ) { return new Promise < any > ( ( resolve ) => { overwolf . extensions . getInfo ( 'nafihghfcpikebhfhdhljejkcifgbdahdhngepfb' , ( callbackInfo ) => { resolve ( callbackInfo ) ; } ) ; } ) ; } public async setExtensionInfo ( info ) { return new Promise < void > ( ( resolve ) => { overwolf . extensions . setInfo ( info ) ; resolve ( ) ; } ) ; } public async registerInfo ( id , eventsCallback ) { return new Promise < void > ( ( resolve ) => { overwolf . extensions . registerInfo ( id , eventsCallback , ( ) => { resolve ( ) ; } ) ; } ) ; } public async setShelfStatusReady ( ) { return new Promise < void > ( ( resolve ) => { if ( ! overwolf || ! overwolf . egs || ! overwolf . egs . setStatus ) { setTimeout ( ( ) => { this . setShelfStatusReady ( ) ; } , 100 ) ; return ; } overwolf . egs . setStatus ( overwolf . egs . enums . ShelfStatus . Ready , ( result ) => { resolve ( ) ; } ) ; } ) ; } public setZoom ( zoomFactor ) { overwolf . windows . setZoom ( zoomFactor ) ; } public async getActiveSubscriptionPlans ( ) { return new Promise < ActiveSubscriptionPlan > ( ( resolve ) => { if ( ! overwolf . profile . subscriptions ) { resolve ( { } as ActiveSubscriptionPlan ) ; return ; } overwolf . profile . subscriptions . getActivePlans ( ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async shouldShowAds ( ) { return new Promise < boolean > ( ( resolve ) => { if ( ! overwolf . profile . subscriptions ) { resolve ( true ) ; return ; } overwolf . profile . subscriptions . getActivePlans ( ( activePlans ) => { const hideAds = activePlans && activePlans . plans && activePlans . plans . includes ( NO_AD_PLAN ) ; resolve ( ! hideAds ) ; } ) ; } ) ; } private twitterUserInfo : TwitterUserInfo = null ; public addTwitterLoginStateChangedListener ( callback ) { overwolf . social . twitter . onLoginStateChanged . addListener ( async ( result ) => { callback ( result ) ; this . twitterUserInfo = await this . getTwitterUserInfo ( true ) ; } ) ; } public async getTwitterUserInfo ( forceRefresh = false ) { if ( ! forceRefresh && this . twitterUserInfo && this . twitterUserInfo . id ) { return this . twitterUserInfo ; } return new Promise < TwitterUserInfo > ( ( resolve ) => { overwolf . social . twitter . getUserInfo ( ( res ) => { if ( res . status !== 'success' || ! res . userInfo ) { const result = { network : 'twitter' , avatarUrl : undefined , id : undefined , name : undefined , screenName : undefined , } ; this . twitterUserInfo = result ; resolve ( result ) ; return ; } const result = { network : 'twitter' , avatarUrl : res . userInfo . avatar , id : res . userInfo . id , name : res . userInfo . name , screenName : res . userInfo . screenName , } ; this . twitterUserInfo = result ; resolve ( result ) ; } ) ; } ) ; } public async twitterShare ( filePathOnDisk , message ) { return new Promise < boolean > ( ( resolve ) => { const shareParam = { file : filePathOnDisk , message : message , } ; overwolf . social . twitter . share ( shareParam , ( res , error ) => { resolve ( res ) ; } ) ; } ) ; } public async twitterLogin ( ) { overwolf . social . twitter . performUserLogin ( ) ; } public async twitterLogout ( ) { return new Promise < void > ( ( resolve ) => { overwolf . social . twitter . performLogout ( ( info ) => { this . twitterUserInfo = null ; resolve ( info ) ; } ) ; } ) ; } private redditUserInfo : RedditUserInfo = null ; public addRedditLoginStateChangedListener ( callback ) { overwolf . social . reddit . onLoginStateChanged . addListener ( async ( result ) => { callback ( result ) ; this . redditUserInfo = await this . getRedditUserInfo ( true ) ; } ) ; } public async getRedditUserInfo ( forceRefresh = false ) { if ( ! forceRefresh && this . redditUserInfo && this . redditUserInfo . id ) { return this . redditUserInfo ; } return new Promise < RedditUserInfo > ( ( resolve ) => { overwolf . social . reddit . getUserInfo ( ( res ) => { if ( res . status !== 'success' || ! res . userInfo ) { const result = { network : 'reddit' , avatarUrl : undefined , id : undefined , name : undefined , screenName : undefined , } ; this . redditUserInfo = result ; resolve ( result ) ; return ; } const result = { network : 'reddit' , avatarUrl : res . userInfo . avatar , id : res . userInfo . name , name : res . userInfo . name , screenName : res . userInfo . displayName , } ; this . redditUserInfo = result ; resolve ( result ) ; } ) ; } ) ; } public async getSubredditFlairs ( subreddit ) { return new Promise < readonly Flair [ ] > ( ( resolve ) => { overwolf . social . reddit . getSubredditFlairs ( subreddit , ( res , error ) => { resolve ( res ?. flairs ) ; } ) ; } ) ; } public async redditShare ( filePathOnDisk , message , subreddit , flair ? ) { return new Promise < boolean > ( ( resolve ) => { const shareParam = { file : filePathOnDisk , title : message , subreddit : subreddit , flair_id : flair , } ; overwolf . social . reddit . share ( shareParam , ( res , error ) => { resolve ( res ) ; } ) ; } ) ; } public async redditLogin ( ) { overwolf . social . reddit . performUserLogin ( ) ; } public async redditLogout ( ) { return new Promise < void > ( ( resolve ) => { overwolf . social . reddit . performLogout ( ( info ) => { this . redditUserInfo = null ; resolve ( info ) ; } ) ; } ) ; } public async listFilesInAppDirectory ( appName ) { return new Promise < any > ( ( resolve ) => { overwolf . io . dir ( `${ overwolf . io . paths . localAppData }/overwolf/Log/Apps/${ appName }` , ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async fileExists ( filePathOnDisk ) { return new Promise < boolean > ( ( resolve ) => { overwolf . io . fileExists ( filePathOnDisk , ( res , error ) => { resolve ( res . found ) ; } ) ; } ) ; } public async writeFileContents ( filePathOnDisk , content ) { return new Promise < string > ( ( resolve ) => { overwolf . io . writeFileContents ( filePathOnDisk , content , 'UTF8' , false , ( res , error ) => { resolve ( res . success ? res . content : null ) ; } ) ; } ) ; } public async readTextFile ( filePathOnDisk ) { return new Promise < string > ( ( resolve ) => { overwolf . io . readTextFile ( filePathOnDisk , { encoding : 'UTF8' } , ( res , error ) => { resolve ( res . success ? res . content : null ) ; } ) ; } ) ; } public async deleteFile ( filePathOnDisk ) { return new Promise < boolean > ( ( resolve ) => { overwolf . io . writeFileContents ( filePathOnDisk , '' , 'UTF8' , false , ( res , error ) => { resolve ( res . status === 'success' ) ; } ) ; } ) ; } public openStore ( ) { overwolf . utils . openStore ( { page : overwolf . utils . enums . eStorePage . SubscriptionPage , } ) ; } public async getFromClipboard ( ) { return new Promise < string > ( ( resolve ) => { overwolf . utils . getFromClipboard ( ( res , error ) => { resolve ( res ) ; } ) ; } ) ; } public async placeOnClipboard ( value ) { return new Promise < void > ( ( resolve ) => { overwolf . utils . placeOnClipboard ( value ) ; resolve ( ) ; } ) ; } public async getMonitorsList ( ) { return new Promise < any > ( ( resolve ) => { overwolf . utils . getMonitorsList ( ( res ) => { resolve ( res ) ; } ) ; } ) ; } public async getSystemInformation ( ) { return new Promise < any > ( ( resolve ) => { overwolf . utils . getSystemInformation ( ( res ) => { resolve ( res . systemInfo ) ; } ) ; } ) ; } public listenOnFile ( id , path , options , callback ) { overwolf . io . listenOnFile ( id , path , ! ! options ? { ... options , encoding : 'UTF8' } : null , callback ) ; } public stopFileListener ( id ) { console . log ( '[ow-service] stopping file listener' , id ) ; overwolf . io . stopFileListener ( id ) ; } public checkForExtensionUpdate ( ) { return new Promise < boolean > ( ( resolve ) => { overwolf . extensions . checkForExtensionUpdate ( ( res ) => { resolve ( res . updateVersion != null ) ; } ) ; } ) ; } public updateExtension ( ) { return new Promise < boolean > ( ( resolve ) => { overwolf . extensions . updateExtension ( ( res ) => { resolve ( ! res . error ) ; } ) ; } ) ; } public relaunchApp ( ) { overwolf . extensions . relaunch ( ) ; } public gameRunning ( gameInfo ) { if ( ! gameInfo ) { return false ; } if ( ! gameInfo . isRunning ) { return false ; } if ( Math . floor ( gameInfo . id / 10 ) !== HEARTHSTONE_GAME_ID ) { return false ; } return true ; } public gameLaunched ( gameInfoResult ) { if ( ! gameInfoResult ) { return false ; } if ( ! gameInfoResult . gameInfo ) { return false ; } if ( ! gameInfoResult . gameInfo . isRunning ) { return false ; } if ( Math . floor ( gameInfoResult . gameInfo . id / 10 ) !== HEARTHSTONE_GAME_ID ) { return false ; } return gameInfoResult . runningChanged || gameInfoResult . gameChanged ; } public static getAppFolder ( ) { return `${ overwolf . io . paths . localAppData }/overwolf/Log/Apps/Firestone` ; } public static getLocalAppDataFolder ( ) { return `${ overwolf . io . paths . localAppData }` ; } } export interface ListenObject { readonly success : boolean ; readonly error : string ; readonly state : 'running' | 'terminated' | 'truncated' ; readonly content : string ; readonly info : string ; } export interface Flair { readonly id : string ; readonly text : string ; readonly mod_only : boolean ; readonly allowable_content : string ; } interface CheckForUpdateResult { readonly success : boolean ; readonly error : string ; readonly state : ExtensionUpdateState ; readonly updateVersion : string ; } type ExtensionUpdateState = 'UpToDate' | 'UpdateAvailable' | 'PendingRestart' ; interface UpdateExtensionResult { readonly success : boolean ; readonly error : string ; readonly state : string ; readonly info : string ; readonly version : string ; } interface Manifest { data : { windows : { [ windowName ] : { min_size : { width : number ; height : number ; } ; } ; } ; } ; }