       $spawnStatus.text(if code? then "exited with code #{code}" else "received #{signal}")
       enableSpawnAndListen true; return
     .on '*listenError', ({err}) ->
-      $listenDialog?.dialog 'close'; $.alert err, 'Error'
-      enableSpawnAndListen true; return
+      if $listenDialog then $listenDialog.dialog 'close'; $listenDialog = null
+      $.alert err, 'Error'; enableSpawnAndListen true; return
 
   $('#fav-list').resizable handles: 's,e'
 

  $spawn       = $ '#spawn'        ; $cancel      = $ '#fav-cancel'
  $spawnStatus = $ '#spawn-status' ; $listen      = $ '#listen'
  $about       = $ '#about'        ; $listenPort  = $ '#listen-port'
  $listenDialog = null

  enableSpawnAndListen = (b) ->
    $('#spawn, #listen').button if b then 'enable' else 'disable'

        ]
      return
    .on '*hijacked', ({addr}) -> $.alert "#{addr} has taken over usage of this proxy.", 'Disconnected'; return
    .on '*connected', ({host, port}) ->
      if $listenDialog  then $listenDialog.dialog  'close'; $listenDialog  = null
      if $connectDialog then $connectDialog.dialog 'close'; $connectDialog = null
      ideInstance = ide(); ideInstance.setHostAndPort host, port; return
    .on '*connectError', ({err}) ->
      if $connectDialog then $connectDialog.dialog 'close'; $connectDialog = null
      $.alert err, 'Error'; return
    .on '*spawned', ({pid}) ->
      $spawnStatus.text "PID: #{pid}"
      enableSpawnAndListen false; return
