From ab43b08739da2159e241460c5f0e2dfa2414775c Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 3 Feb 2015 15:16:22 -0800 Subject: [PATCH] Add hidden --socket-path flag This will allow integration tests to control which atom application instance they use when creating atom windows --- src/browser/atom-application.coffee | 17 ++++++++++------- src/browser/main.coffee | 4 +++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index f0674b43e..de5fda234 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -14,7 +14,7 @@ url = require 'url' {EventEmitter} = require 'events' _ = require 'underscore-plus' -socketPath = +DEFAULT_SOCKET_PATH = if process.platform is 'win32' '\\\\.\\pipe\\atom-sock' else @@ -31,17 +31,20 @@ class AtomApplication # Public: The entry point into the Atom application. @open: (options) -> + options.socketPath ?= DEFAULT_SOCKET_PATH + createAtomApplication = -> new AtomApplication(options) # FIXME: Sometimes when socketPath doesn't exist, net.connect would strangely # take a few seconds to trigger 'error' event, it could be a bug of node # or atom-shell, before it's fixed we check the existence of socketPath to # speedup startup. - if (process.platform isnt 'win32' and not fs.existsSync socketPath) or options.test + if (process.platform isnt 'win32' and not fs.existsSync options.socketPath) or options.test createAtomApplication() return - client = net.connect {path: socketPath}, -> + + client = net.connect {path: options.socketPath}, -> client.write JSON.stringify(options), -> client.end() app.terminate() @@ -57,7 +60,7 @@ class AtomApplication exit: (status) -> app.exit(status) constructor: (options) -> - {@resourcePath, @version, @devMode, @safeMode} = options + {@resourcePath, @version, @devMode, @safeMode, @socketPath} = options # Normalize to make sure drive letter case is consistent on Windows @resourcePath = path.normalize(@resourcePath) if @resourcePath @@ -119,15 +122,15 @@ class AtomApplication connection.on 'data', (data) => @openWithOptions(JSON.parse(data)) - server.listen socketPath + server.listen @socketPath server.on 'error', (error) -> console.error 'Application server failed', error deleteSocketFile: -> return if process.platform is 'win32' - if fs.existsSync(socketPath) + if fs.existsSync(@socketPath) try - fs.unlinkSync(socketPath) + fs.unlinkSync(@socketPath) catch error # Ignore ENOENT errors in case the file was deleted between the exists # check and the call to unlink sync. This occurred occasionally on CI diff --git a/src/browser/main.coffee b/src/browser/main.coffee index 40456d51c..54037ecd7 100644 --- a/src/browser/main.coffee +++ b/src/browser/main.coffee @@ -120,6 +120,7 @@ parseCommandLine = -> options.alias('t', 'test').boolean('t').describe('t', 'Run the specified specs and exit with error code on failures.') options.alias('v', 'version').boolean('v').describe('v', 'Print the version.') options.alias('w', 'wait').boolean('w').describe('w', 'Wait for window to be closed before returning.') + options.string('socket-path') args = options.argv if args.help @@ -140,6 +141,7 @@ parseCommandLine = -> newWindow = args['new-window'] pidToKillWhenClosed = args['pid'] if args['wait'] logFile = args['log-file'] + socketPath = args['socket-path'] if args['resource-path'] devMode = true @@ -164,6 +166,6 @@ parseCommandLine = -> # explicitly pass it by command line, see http://git.io/YC8_Ew. process.env.PATH = args['path-environment'] if args['path-environment'] - {resourcePath, pathsToOpen, executedFrom, test, version, pidToKillWhenClosed, devMode, safeMode, newWindow, specDirectory, logFile} + {resourcePath, pathsToOpen, executedFrom, test, version, pidToKillWhenClosed, devMode, safeMode, newWindow, specDirectory, logFile, socketPath} start()