Beispiel #1
0
process.nextTick(function main(){
  driApp.model = Object.create(observableObject, {
    emit:{writable:false, enumerable:false, configurable:false, value:driApp.emit.bind(driApp)}
  })
  
  driApp.preferences = new preferences.constructor({ model:driApp.model, path:process.env.UserConfig })
  
  driApp.start()
  
  initAvailableSockets(driApp.model)
  
  // initStaticServer(process.env.HOME + '/Sites', 1232)
})
Beispiel #2
0
driApp.once('frontend::webserver::started', function startWebView(port){
  var ui = webview('http://localhost:' + port)
  ui.once('exit', function(exitCode){
    driApp.emit('ui::exit')
    driApp.emit('die')
  })
  driApp.on('die', function(){
    ui.kill()
  })
  setTimeout(function(){
    driApp.emit('ui::started')
  }, 100);
})
Beispiel #3
0
function initAvailableSockets(model){
  
  driApp.on('android-adb-portmap::port::forward::*::on', function(){
    var port = this.event.split('::')[3].split(':')[1]
    
    var interval = setInterval(intervalCallback, 1000)
    function intervalCallback(){
      request('http://localhost:'+port+'/json', function(error, response, body){
        if (error) {
          clearInterval(interval)
          model.set('available-sockets::' + port, null)
          return
        }
        var data = JSON.parse(body)
        model.set('available-sockets::' + port, data)
      })
    }
    intervalCallback()
  })

  getAvailableInspectorSockets.regex = /href="\?page=(\d+)">([^<]*)<\//g

  function getAvailableInspectorSockets(url, callback){
    var regex = getAvailableInspectorSockets.regex
    request(url, function(error, response, body){
      if (error) return callback(error)
      var match, data = [], name
      regex.lastIndex = 0
      while ((match = regex.exec(body))) {
        name = match[2]
        if (name.indexOf('data:') == 0) name = name.substr(0,32) + '...'
        data.push({
          name: name,
          host: response.request.uri.host,
          page: match[1],
          url: util.format('%s/devtools/page/%s', response.request.uri.host, match[1])
        })
      }
      callback(null, data)
    })
  }

}
Beispiel #4
0
 setTimeout(function(){
   driApp.emit('ui::started')
 }, 100);
Beispiel #5
0
 ui.once('exit', function(exitCode){
   driApp.emit('ui::exit')
   driApp.emit('die')
 })
Beispiel #6
0
driApp.once('frontend::loaded', function publishFrontendInfo(){
  driApp.emit('version', util.format("v%s %s", require(process.env.App + '/Contents/package.json').version, process.env.BuildString))
})
Beispiel #7
0
preferences.constructor.prototype = preferences

////////////////////////////////////////////////////////////////////////////////

var backendConfig = require('../SharedSupport/Hooks/Android.config.js')
var frontendConfig = {
  "src": require.resolve('../SharedSupport/lib/hook.io-webserver'),
  "name": "frontend",
  "port": 8182,
  "autoheal": false,
  "webroot": process.env.SharedSupport + "/Frontend"
}

////////////////////////////////////////////////////////////////////////////////

var driApp = new Herd({ "name":"Dri.app" })

driApp.on('hook::started', function dieIfAlreadyRunning(){
  if (driApp.name === "Dri.app") return
  throw Error('Looks like multiple versions are running at once')
})

driApp.once('hook::ready', function setupFrontend(){ driApp.spawn([ driApp.childConfigFrom(frontendConfig) ]) })
driApp.once('frontend::loaded', function setupBackend(){ driApp.spawn([ driApp.childConfigFrom(backendConfig) ]) })
  
driApp.once('frontend::loaded', function publishFrontendInfo(){
  driApp.emit('version', util.format("v%s %s", require(process.env.App + '/Contents/package.json').version, process.env.BuildString))
})

driApp.once('frontend::webserver::started', function startWebView(port){
  var ui = webview('http://localhost:' + port)