Preserve command line flags when restarting

This performs restarts in the main process and uses ipc to request restarts from application windows. We preserve the following settings:

* dev mode
* custom resource path
* safe mode
* portable mode
* socket path
* log file path
* user data dir
This commit is contained in:
Nathan Sobo
2016-09-20 15:13:46 -06:00
parent 1d740b4169
commit fe9a7d1db3
2 changed files with 19 additions and 5 deletions

View File

@@ -58,8 +58,7 @@ class ApplicationDelegate
ipcRenderer.send("call-window-method", "reload")
restartApplication: ->
remote.app.relaunch({args: []})
remote.app.quit()
ipcRenderer.send("restart-application")
minimizeWindow: ->
ipcRenderer.send("call-window-method", "minimize")

View File

@@ -62,7 +62,7 @@ class AtomApplication
exit: (status) -> app.exit(status)
constructor: (options) ->
{@resourcePath, @devResourcePath, @version, @devMode, @safeMode, @socketPath, timeout, clearWindowState} = options
{@resourcePath, @devResourcePath, @version, @devMode, @safeMode, @socketPath, @logFile, @setPortable, @userDataDir, timeout, clearWindowState} = options
@socketPath = null if options.test
@pidsToOpenWindows = {}
@windows = []
@@ -254,6 +254,9 @@ class AtomApplication
event?.preventDefault()
@emit('application:new-window')
@disposable.add ipcHelpers.on ipcMain, 'restart-application', =>
@restart()
# A request from the associated render process to open a new render process.
@disposable.add ipcHelpers.on ipcMain, 'open', (event, options) =>
window = @windowForEvent(event)
@@ -738,5 +741,17 @@ class AtomApplication
message: "You will need to restart Atom for this change to take effect."
buttons: ['Restart Atom', 'Cancel']
if chosen is 0
app.relaunch({args: []})
app.quit()
@restart()
restart: ->
args = []
args.push("--safe") if @safeMode
args.push("--portable") if @setPortable
args.push("--log-file=#{@logFile}") if @logFile?
args.push("--socket-path=#{@socketPath}") if @socketPath?
args.push("--user-data-dir=#{@userDataDir}") if @userDataDir?
if @devMode
args.push('--dev')
args.push("--resource-path=#{@resourcePath}")
app.relaunch({args})
app.quit()