From 6aa8d33a054dbce58b546258de37c56ad1ed20a9 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 20 Sep 2016 11:37:34 -0600 Subject: [PATCH 1/4] Add atom.restartApplication Signed-off-by: Max Brunsfeld --- src/application-delegate.coffee | 4 ++++ src/atom-environment.coffee | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index 18fb59f54..db86de66c 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -57,6 +57,10 @@ class ApplicationDelegate reloadWindow: -> ipcRenderer.send("call-window-method", "reload") + restartApplication: -> + remote.app.relaunch({args: []}) + remote.app.quit() + minimizeWindow: -> ipcRenderer.send("call-window-method", "minimize") diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index f84e90469..63bb7141c 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -545,6 +545,10 @@ class AtomEnvironment extends Model reload: -> @applicationDelegate.reloadWindow() + # Extended: Relaunch the entire application. + restartApplication: -> + @applicationDelegate.restartApplication() + # Extended: Returns a {Boolean} that is `true` if the current window is maximized. isMaximized: -> @applicationDelegate.isWindowMaximized() From 1d740b41694f3e77e65ac53b7939431bb38c8e56 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 20 Sep 2016 11:39:58 -0600 Subject: [PATCH 2/4] Relaunch Atom when changing the title bar style Now that we have the required API Signed-off-by: Max Brunsfeld --- src/main-process/atom-application.coffee | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main-process/atom-application.coffee b/src/main-process/atom-application.coffee index 8969a1763..a4c094285 100644 --- a/src/main-process/atom-application.coffee +++ b/src/main-process/atom-application.coffee @@ -734,10 +734,9 @@ class AtomApplication promptForRelaunch: -> chosen = dialog.showMessageBox BrowserWindow.getFocusedWindow(), type: 'warning' - title: 'Relaunch required' - message: "You will need to relaunch Atom for this change to take effect." - buttons: ['Quit Atom', 'Cancel'] + title: 'Restart required' + message: "You will need to restart Atom for this change to take effect." + buttons: ['Restart Atom', 'Cancel'] if chosen is 0 - # once we're using electron v.1.2.2 - # app.relaunch() + app.relaunch({args: []}) app.quit() From fe9a7d1db3836930411b4054def300a0f175fe6c Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 20 Sep 2016 15:13:46 -0600 Subject: [PATCH 3/4] 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 --- src/application-delegate.coffee | 3 +-- src/main-process/atom-application.coffee | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index db86de66c..e174b2254 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -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") diff --git a/src/main-process/atom-application.coffee b/src/main-process/atom-application.coffee index a4c094285..3013d312e 100644 --- a/src/main-process/atom-application.coffee +++ b/src/main-process/atom-application.coffee @@ -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() From 7872875c5736199392e970e7176796346c78b7ed Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Tue, 20 Sep 2016 15:15:55 -0600 Subject: [PATCH 4/4] :art: --- src/main-process/atom-application.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main-process/atom-application.coffee b/src/main-process/atom-application.coffee index 3013d312e..b98ab1c5b 100644 --- a/src/main-process/atom-application.coffee +++ b/src/main-process/atom-application.coffee @@ -83,7 +83,7 @@ class AtomApplication initialize: (options) -> global.atomApplication = this - @config.onDidChange 'core.useCustomTitleBar', @promptForRelaunch + @config.onDidChange 'core.useCustomTitleBar', @promptForRestart @autoUpdateManager = new AutoUpdateManager(@version, options.test, @resourcePath, @config) @applicationMenu = new ApplicationMenu(@version, @autoUpdateManager) @@ -734,7 +734,7 @@ class AtomApplication dialog.showOpenDialog(parentWindow, openOptions, callback) - promptForRelaunch: -> + promptForRestart: -> chosen = dialog.showMessageBox BrowserWindow.getFocusedWindow(), type: 'warning' title: 'Restart required'