Skip to content

Commit 2b3e22a

Browse files
committed
Allow independent Atom instances
By having an $ATOM_HOME-dependent part in the socket name, Atom instances that have different homes will run in independent processes. Fixes the current behaviour where starting Atom with a new $ATOM_HOME "opens" an Atom window with settings and packages from the original $ATOM_HOME. Useful for IDEs.
1 parent 3482f8f commit 2b3e22a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/main-process/atom-application.coffee

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ FileRecoveryService = require './file-recovery-service'
88
ipcHelpers = require '../ipc-helpers'
99
{BrowserWindow, Menu, app, dialog, ipcMain, shell, screen} = require 'electron'
1010
{CompositeDisposable, Disposable} = require 'event-kit'
11+
crypto = require 'crypto'
1112
fs = require 'fs-plus'
1213
path = require 'path'
1314
os = require 'os'
@@ -33,11 +34,16 @@ class AtomApplication
3334
# Public: The entry point into the Atom application.
3435
@open: (options) ->
3536
unless options.socketPath?
37+
username = if process.platform is 'win32' then process.env.USERNAME else process.env.USER
38+
# Lowercasing the ATOM_HOME to make sure that we don't get multiple sockets
39+
# on case-insensitive filesystems due to arbitrary case differences in paths.
40+
atomHomeUnique = path.resolve(process.env.ATOM_HOME).toLowerCase()
41+
hash = crypto.createHash('sha1').update(username).update('|').update(atomHomeUnique)
42+
atomInstanceDigest = hash.digest('hex').substring(0, 32)
3643
if process.platform is 'win32'
37-
userNameSafe = new Buffer(process.env.USERNAME).toString('base64')
38-
options.socketPath = "\\\\.\\pipe\\atom-#{options.version}-#{userNameSafe}-#{process.arch}-sock"
44+
options.socketPath = "\\\\.\\pipe\\atom-#{options.version}-#{process.arch}-#{atomInstanceDigest}-sock"
3945
else
40-
options.socketPath = path.join(os.tmpdir(), "atom-#{options.version}-#{process.env.USER}.sock")
46+
options.socketPath = path.join(os.tmpdir(), "atom-#{options.version}-#{process.arch}-#{atomInstanceDigest}.sock")
4147

4248
# FIXME: Sometimes when socketPath doesn't exist, net.connect would strangely
4349
# take a few seconds to trigger 'error' event, it could be a bug of node

0 commit comments

Comments
 (0)