Assign window.onbeforeunload instead of addEventListener

This allows us to cancel the unloading if the user doesn’t confirm the
save dialog.
This commit is contained in:
Nathan Sobo
2015-10-12 15:32:36 -06:00
parent b27c1140a7
commit 93de5ccb79

View File

@@ -16,9 +16,10 @@ class WindowEventHandler
@on(ipc, 'command', @handleIPCCommand)
@on(ipc, 'context-command', @handleIPCContextCommand)
@previousOnbeforeunloadHandler = window.onbeforeunload
window.onbeforeunload = @handleWindowBeforeunload
@addEventListener(window, 'focus', @handleWindowFocus)
@addEventListener(window, 'blur', @handleWindowBlur)
@addEventListener(window, 'beforeunload', @handleWindowBeforeunload)
@addEventListener(window, 'unload', @handleWindowUnload)
@addEventListener(document, 'keydown', @handleDocumentKeydown)
@@ -60,6 +61,7 @@ class WindowEventHandler
bindCommandToAction('core:cut', 'cut')
unsubscribe: ->
window.onbeforeunload = @previousOnbeforeunloadHandler
@subscriptions.dispose()
on: (target, eventName, handler) ->