import { Message , MessageFactory , MessageType , DispatchHandler , messageJumpContext , browserSubscribeDispatch , browserSubscribeOnce , } from './communication' ; import { send , subscribe , } from './backend/connection' ; import { loadOptions , SimpleOptions } from './options' ; const scriptInjection = new Set < string > ( ) ; const inject = ( fn ) => { const script = document . createElement ( 'script' ) ; fn ( script ) ; document . documentElement . appendChild ( script ) ; script . parentNode . removeChild ( script ) ; } ; const injectScript = ( path ) => { if ( scriptInjection . has ( path ) ) { return ; } inject ( script => { script . src = chrome . extension . getURL ( path ) ; } ) ; scriptInjection . add ( path ) ; } ; export const injectSettings = ( options ) => { inject ( script => { const serialized = JSON . stringify ( options ) ; script . textContent = `this.treeRenderOptions = ${ serialized };` ; } ) ; } ; if ( document instanceof HTMLDocument ) { browserSubscribeOnce ( MessageType . FrameworkLoaded , < DispatchHandler > ( ( ) => { loadOptions ( ) . then ( options => { injectSettings ( options ) ; injectScript ( 'build/backend.js' ) ; } ) ; return true ; } ) ) ; browserSubscribeDispatch ( < DispatchHandler > ( ( message ) => { if ( message . messageType === MessageType . DispatchWrapper ) { send ( message . content ) . then ( response => { messageJumpContext ( MessageFactory . response ( message , response , true ) ) ; } ) . catch ( error => { messageJumpContext ( MessageFactory . response ( message , error , false ) ) ; } ) ; } } ) ) ; subscribe ( ( message ) => messageJumpContext ( message ) ) ; Promise . resolve ( ) . then ( ( ) => { injectScript ( 'build/ng-validate.js' ) ; } ) . catch ( error => { console . error ( 'Augury initialization has failed' , error ) ; } ) ; const propertyKey = '$$el' ; const warningText = `$$el will only be set in the 'top' execution context, \
    which you can select via the dropdown in the console pane \
    (https://developers.google.com/web/tools/chrome-devtools/console/\
    #execution-context).` ; Object . defineProperty ( window , propertyKey , { value : warningText } ) ; }