mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Create AtomApplication after app is finished launching
This commit is contained in:
@@ -16,7 +16,6 @@ class AtomApplication
|
||||
resourcePath: null
|
||||
pathsToOpen: null
|
||||
version: null
|
||||
launched: false
|
||||
socketPath: '/tmp/atom.sock'
|
||||
|
||||
constructor: ({@resourcePath, @pathsToOpen, @version, test, pidToKillWhenClosed}) ->
|
||||
@@ -24,33 +23,21 @@ class AtomApplication
|
||||
@pathsToOpen ?= []
|
||||
@windows = []
|
||||
|
||||
app.on 'open-file', (event, filePath) =>
|
||||
event.preventDefault()
|
||||
if @launched
|
||||
@openPath filePath
|
||||
@sendArgumentsToExistingProcess pidToKillWhenClosed, (success) =>
|
||||
app.terminate() if success # An Atom already exists, kill this process
|
||||
@listenForArgumentsFromNewProcess()
|
||||
@setupNodePath()
|
||||
@setupJavaScriptArguments()
|
||||
@buildApplicationMenu()
|
||||
@handleEvents()
|
||||
|
||||
if test
|
||||
@runSpecs(true)
|
||||
else if @pathsToOpen.length > 0
|
||||
@openPaths(@pathsToOpen, pidToKillWhenClosed)
|
||||
else
|
||||
# Delay opening until Atom has finished launching, this condition
|
||||
# happens when user double clicks a file in Finder to open it.
|
||||
@pathsToOpen.push filePath
|
||||
|
||||
app.on 'finish-launching', =>
|
||||
@launched = true
|
||||
|
||||
@sendArgumentsToExistingProcess pidToKillWhenClosed, (success) =>
|
||||
app.terminate() if success # An Atom already exists, kill this process
|
||||
@listenForArgumentsFromNewProcess()
|
||||
@setupNodePath()
|
||||
@setupJavaScriptArguments()
|
||||
@buildApplicationMenu()
|
||||
@handleEvents()
|
||||
|
||||
if test
|
||||
@runSpecs(true)
|
||||
else if @pathsToOpen.length > 0
|
||||
@openPaths(@pathsToOpen, pidToKillWhenClosed)
|
||||
else
|
||||
# Always open a editor window if this is the first instance of Atom.
|
||||
@openPath(null)
|
||||
# Always open a editor window if this is the first instance of Atom.
|
||||
@openPath(null)
|
||||
|
||||
removeWindow: (window) ->
|
||||
@windows.splice @windows.indexOf(window), 1
|
||||
@@ -82,10 +69,6 @@ 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)
|
||||
@@ -163,6 +146,11 @@ class AtomApplication
|
||||
app.on 'will-quit', =>
|
||||
fs.unlinkSync @socketPath if fs.existsSync(@socketPath)
|
||||
|
||||
app.on 'open-file', (event, filePath) =>
|
||||
event.preventDefault()
|
||||
@openPath filePath
|
||||
|
||||
|
||||
ipc.on 'close-without-confirm', (processId, routingId) ->
|
||||
window = BrowserWindow.fromProcessIdAndRoutingId processId, routingId
|
||||
window.removeAllListeners 'close'
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
delegate = require 'atom-delegate'
|
||||
app = require 'app'
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
delegate = require 'atom-delegate'
|
||||
optimist = require 'optimist'
|
||||
nslog = require 'nslog'
|
||||
AtomApplication = require './atom-application'
|
||||
@@ -12,7 +13,16 @@ require 'coffee-script'
|
||||
|
||||
delegate.browserMainParts.preMainMessageLoopRun = ->
|
||||
commandLineArgs = parseCommandLine()
|
||||
global.atomApplication = new AtomApplication(commandLineArgs)
|
||||
|
||||
addPathToOpen = (event, filePath) ->
|
||||
event.preventDefault()
|
||||
commandLineArgs.pathsToOpen ?= []
|
||||
commandLineArgs.pathsToOpen.push(filePath)
|
||||
|
||||
app.on 'open-file', addPathToOpen
|
||||
app.on 'finish-launching', ->
|
||||
app.removeListener 'open-file', addPathToOpen
|
||||
global.atomApplication = new AtomApplication(commandLineArgs)
|
||||
|
||||
getHomeDir = ->
|
||||
process.env[if process.platform is 'win32' then 'USERPROFILE' else 'HOME']
|
||||
|
||||
Reference in New Issue
Block a user