Merge pull request #12733 from atom/ns-as-restart-application

Add atom.restartApplication
This commit is contained in:
Nathan Sobo
2016-09-20 15:06:55 -07:00
committed by GitHub
3 changed files with 30 additions and 9 deletions

View File

@@ -57,6 +57,9 @@ class ApplicationDelegate
reloadWindow: ->
ipcRenderer.send("call-window-method", "reload")
restartApplication: ->
ipcRenderer.send("restart-application")
minimizeWindow: ->
ipcRenderer.send("call-window-method", "minimize")

View File

@@ -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()

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 = []
@@ -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)
@@ -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)
@@ -731,13 +734,24 @@ class AtomApplication
dialog.showOpenDialog(parentWindow, openOptions, callback)
promptForRelaunch: ->
promptForRestart: ->
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.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()