From 93de5ccb79c4972e55bb7bf1edc241f8525ad8e9 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 12 Oct 2015 15:32:36 -0600 Subject: [PATCH] Assign window.onbeforeunload instead of addEventListener MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows us to cancel the unloading if the user doesn’t confirm the save dialog. --- src/window-event-handler.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 270650b2f..53c2aa2e2 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -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) ->