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:
Cheng Zhao
2013-05-20 14:19:12 +08:00
parent 5459f1e9db
commit 60fcb97a3e
3 changed files with 15 additions and 15 deletions

View File

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