apps/remix-ide/src/app/files/remixd-handle.js
/**
    * connect to localhost if no connection and render the explorer
    * disconnect from localhost if connected and remove the explorer
    *
    * @param {String} txHash - hash of the transaction
    */
connect to localhost if no connection and render the explorer
disconnect from localhost if connected and remove the explorer

@param {String} txHash - hash of the transaction
connect to localhost if no connection and render the explorer disconnect from localhost if connected and remove the explorer @param { String } txHash - hash of the transaction
async connectToLocalhost () {
    const connection = (error) => {
      if (error) {
        console.log(error)
        modalDialogCustom.alert(
          'Cannot connect to the remixd daemon.' +
          'Please make sure you have the remixd running in the background.'
        )
        this.canceled()
      } else {
        const intervalId = setInterval(() => {
          if (!this.socket || (this.socket && this.socket.readyState === 3)) { 
            clearInterval(intervalId)
            console.log(error)
            modalDialogCustom.alert(
              'Connection to remixd terminated' +
              'Please make sure remixd is still running in the background.'
            )
            this.canceled()
          }
        }, 3000)
        this.locahostProvider.init(() => {
          this.fileSystemExplorer.show()
        })
        this.call('manager', 'activatePlugin', 'git')
      }
    }
    if (this.locahostProvider.isConnected()) {
      this.deactivate()
    } else if (!isElectron()) {
      modalDialog(
        'Connect to localhost',
        remixdDialog(),
        {
          label: 'Connect',
          fn: () => {
            try {
              super.activate()
              setTimeout(() => {
                if (!this.socket || (this.socket && this.socket.readyState === 3)) { 
                  connection(new Error('Connection with daemon failed.'))
                } else {
                  connection()
                }
              }, 3000)
            } catch (error) {
              connection(error)
            }
          }
        },
        {
          label: 'Cancel',
          fn: () => {
            this.canceled()
          }
        }
      )
    } else {
      try {
        super.activate()
        setTimeout(() => { connection() }, 2000)
      } catch (error) {
        connection(error)
      }
    }
  }
async connectToLocalhost ( ) { const connection = ( error ) => { if ( error ) { console . log ( error ) modalDialogCustom . alert ( 'Cannot connect to the remixd daemon.' + 'Please make sure you have the remixd running in the background.' ) this . canceled ( ) } else { const intervalId = setInterval ( ( ) => { if ( ! this . socket || ( this . socket && this . socket . readyState === 3 ) ) { clearInterval ( intervalId ) console . log ( error ) modalDialogCustom . alert ( 'Connection to remixd terminated' + 'Please make sure remixd is still running in the background.' ) this . canceled ( ) } } , 3000 ) this . locahostProvider . init ( ( ) => { this . fileSystemExplorer . show ( ) } ) this . call ( 'manager' , 'activatePlugin' , 'git' ) } } if ( this . locahostProvider . isConnected ( ) ) { this . deactivate ( ) } else if ( ! isElectron ( ) ) { modalDialog ( 'Connect to localhost' , remixdDialog ( ) , { label : 'Connect' , fn : ( ) => { try { super . activate ( ) setTimeout ( ( ) => { if ( ! this . socket || ( this . socket && this . socket . readyState === 3 ) ) { connection ( new Error ( 'Connection with daemon failed.' ) ) } else { connection ( ) } } , 3000 ) } catch ( error ) { connection ( error ) } } } , { label : 'Cancel' , fn : ( ) => { this . canceled ( ) } } ) } else { try { super . activate ( ) setTimeout ( ( ) => { connection ( ) } , 2000 ) } catch ( error ) { connection ( error ) } } }
connect to localhost if no connection and render the explorer
 disconnect from localhost if connected and remove the explorer
connect to localhost if no connection and render the explorer disconnect from localhost if connected and remove the explorer
// 3 means connection closed // warn the user only if he/she is in the browser context // 3 means connection closed