mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Send window commands instead of invoking window APIs directly.
For some events generated on the browser side, like reloading, closing window, we should not handle those events directly, instead we should send the corresponding commands to the renderer and let the renderer deal with it. The window.reload() is also moved to atom.reload(), because I saw things like toggleFullScreen(), focus(), toggleDevTools() are also there.
This commit is contained in:
@@ -209,6 +209,10 @@ window.atom =
|
||||
toggleDevTools: ->
|
||||
remote.getCurrentWindow().toggleDevTools()
|
||||
|
||||
reload: ->
|
||||
# TODO Restart renderer process when needed
|
||||
remote.getCurrentWindow().reloadIgnoringCache()
|
||||
|
||||
focus: ->
|
||||
remote.getCurrentWindow().focus()
|
||||
|
||||
|
||||
@@ -111,13 +111,13 @@ window.unloadConfigWindow = ->
|
||||
$(window).off('focus blur before')
|
||||
|
||||
window.handleEvents = ->
|
||||
ipc.on 'close', -> $(window).trigger 'window:close'
|
||||
ipc.on 'command', (command) -> console.log command; $(window).trigger command
|
||||
|
||||
$(window).command 'window:toggle-full-screen', => atom.toggleFullScreen()
|
||||
$(window).on 'focus', -> $("body").removeClass('is-blurred')
|
||||
$(window).on 'blur', -> $("body").addClass('is-blurred')
|
||||
$(window).command 'window:close', => confirmClose()
|
||||
$(window).command 'window:reload', => reload()
|
||||
$(window).command 'window:reload', => atom.reload()
|
||||
|
||||
$(document).on 'click', 'a', (e) ->
|
||||
location = $(e.target).attr('href')
|
||||
@@ -224,16 +224,6 @@ window.applyStylesheet = (id, text, ttype = 'bundled') ->
|
||||
window.closeWithoutConfirm = ->
|
||||
ipc.sendChannel 'close-without-confirm'
|
||||
|
||||
window.reload = ->
|
||||
timesReloaded = process.global.timesReloaded ? 0
|
||||
++timesReloaded
|
||||
|
||||
if timesReloaded > 3
|
||||
atom.restartRendererProcess()
|
||||
else
|
||||
process.global.timesReloaded = timesReloaded
|
||||
$native.reload()
|
||||
|
||||
window.onerror = ->
|
||||
atom.openDevTools()
|
||||
|
||||
|
||||
@@ -89,8 +89,8 @@ class AtomApplication
|
||||
viewMenu =
|
||||
label: 'View'
|
||||
submenu:[
|
||||
{ label: 'Reload', accelerator: 'Command+R', click: -> BrowserWindow.getFocusedWindow()?.reloadIgnoringCache() }
|
||||
{ label: 'Toggle DevTools', accelerator: 'Alt+Command+I', click: -> BrowserWindow.getFocusedWindow()?.toggleDevTools() }
|
||||
{ label: 'Reload', accelerator: 'Command+R', click: => @sendCommand 'window:reload' }
|
||||
{ label: 'Toggle DevTools', accelerator: 'Alt+Command+I', click: => @sendCommand 'toggle-dev-tools' }
|
||||
]
|
||||
|
||||
windowMenu =
|
||||
@@ -129,6 +129,9 @@ class AtomApplication
|
||||
ipc.on 'new-window', =>
|
||||
@createAtomWindow()
|
||||
|
||||
sendCommand: (command) ->
|
||||
atomWindow.sendCommand command for atomWindow in @windows when atomWindow.browserWindow.isFocused()
|
||||
|
||||
createAtomWindow: (path) ->
|
||||
new AtomWindow
|
||||
path: path
|
||||
@@ -157,4 +160,7 @@ class AtomWindow
|
||||
|
||||
@browserWindow.on 'close', (event) =>
|
||||
event.preventDefault()
|
||||
ipc.sendChannel @browserWindow.getProcessId(), @browserWindow.getRoutingId(), 'close'
|
||||
@sendCommand 'window:close'
|
||||
|
||||
sendCommand: (command) ->
|
||||
ipc.sendChannel @browserWindow.getProcessId(), @browserWindow.getRoutingId(), 'command', command
|
||||
|
||||
Reference in New Issue
Block a user