             setTimeout ->
                 resolve()
             , 1000
-    .catch ->
+    .catch (e)->
+        # slash is running; focus it and quit self
         app.quit()
+        throw e
     .then ->
         require('./server/doc-server').run(defaultDocPort, args.docsetdir)
     .then ->

defaultApiPort = args.apiport or 33400
args.docsetdir = args.docsetdir or path.join(process.cwd(), "Docsets")

# check if there is already an Slash is running
mainWindow = null


app.on 'ready', ->
    new Promise (resolve, reject)->
        fs.readFile path.join(args.profiledir, 'api.port'), (err, data)->
            return reject(err) if err

        mainWindow.openDevTools() if args.debug
        mainWindow.loadUrl 'file://' + __dirname + '/../browser/index.html'
app.on 'window-all-closed', ->
    fs.unlinkSync path.join(args.profiledir, 'api.port')
    app.quit()
ipc.on 'showMainWindow', ->
    args.mainWindow.focus()
    args.mainWindow.focusOnWebView()