         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()
-app.on 'quit', ->
-    fs.unlinkSync path.join(args.profiledir, 'api.port')
 ipc.on 'showMainWindow', ->
     args.mainWindow.focus()
     args.mainWindow.focusOnWebView()
            setTimeout ->
                resolve()
            , 1000
    .catch ->
        app.quit()
    .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")

mainWindow = null

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