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.
This commit is contained in:
Morten Piibeleht
2017-07-18 10:40:24 +12:00
parent 8952cd315d
commit 3bee363375

View File

@@ -8,6 +8,7 @@ FileRecoveryService = require './file-recovery-service'
ipcHelpers = require '../ipc-helpers'
{BrowserWindow, Menu, app, dialog, ipcMain, shell, screen} = require 'electron'
{CompositeDisposable, Disposable} = require 'event-kit'
crypto = require 'crypto'
fs = require 'fs-plus'
path = require 'path'
os = require 'os'
@@ -33,11 +34,16 @@ class AtomApplication
# Public: The entry point into the Atom application.
@open: (options) ->
unless options.socketPath?
username = if process.platform is 'win32' then process.env.USERNAME else process.env.USER
# Lowercasing the ATOM_HOME to make sure that we don't get multiple sockets
# on case-insensitive filesystems due to arbitrary case differences in paths.
atomHomeUnique = path.resolve(process.env.ATOM_HOME).toLowerCase()
hash = crypto.createHash('sha1').update(username).update('|').update(atomHomeUnique)
atomInstanceDigest = hash.digest('hex').substring(0, 32)
if process.platform is 'win32'
userNameSafe = new Buffer(process.env.USERNAME).toString('base64')
options.socketPath = "\\\\.\\pipe\\atom-#{options.version}-#{userNameSafe}-#{process.arch}-sock"
options.socketPath = "\\\\.\\pipe\\atom-#{options.version}-#{process.arch}-#{atomInstanceDigest}-sock"
else
options.socketPath = path.join(os.tmpdir(), "atom-#{options.version}-#{process.env.USER}.sock")
options.socketPath = path.join(os.tmpdir(), "atom-#{options.version}-#{process.arch}-#{atomInstanceDigest}.sock")
# 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