Check whether the socket file exists before connecting.

By removing the socket file when the browser process of Atom quits and
checking it's existence before trying to connect it, we can greatly
reduce the startup time of the first instance of Atom.
This commit is contained in:
Cheng Zhao
2013-05-30 22:02:35 +08:00
parent 2135de059f
commit ee046f1c25

View File

@@ -82,11 +82,15 @@ class AtomApplication
process.env['NODE_PATH'] = resourcePaths.join path.delimiter
sendArgumentsToExistingProcess: (pidToKillWhenClosed, callback) ->
if not fs.existsSync(@socketPath)
callback(false)
return
client = net.connect {path: @socketPath}, (args...) =>
client.write(JSON.stringify({@pathsToOpen, pidToKillWhenClosed}))
callback(true)
client.on 'error', (args...) -> callback(false)
client.on 'error', (error) -> console.log(error); callback(false)
listenForArgumentsFromNewProcess: ->
fs.unlinkSync @socketPath if fs.existsSync(@socketPath)
@@ -155,6 +159,10 @@ class AtomApplication
app.on 'window-all-closed', ->
app.quit()
# Clean the socket file when quit normally.
app.on 'will-quit', =>
fs.unlinkSync @socketPath if fs.existsSync(@socketPath)
ipc.on 'close-without-confirm', (processId, routingId) ->
window = BrowserWindow.fromProcessIdAndRoutingId processId, routingId
window.removeAllListeners 'close'