From 9ddb713a1bc2ccf26a267ea0a3a74b34808f95ef Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 28 Sep 2016 17:39:25 -0700 Subject: [PATCH] fix(window-state): Per electron#7278, save state in beforeunload Related: https://github.com/electron/electron/issues/7278 https://github.com/atom/atom/pull/3223/files As of Chromium 36, unload is async and @zcbenz does not think it happens reliabily in Electron. Move saving of window state to beforeunload, following suit with Atom. --- src/window-event-handler.coffee | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 8e9c8128b..7d52d3134 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -39,14 +39,13 @@ class WindowEventHandler # throttled in case more work needs to be done before closing # In Electron, returning any value other than undefined cancels the close. - canCloseWindow = @runUnloadCallbacks() - return undefined if canCloseWindow + if @runUnloadCallbacks() + # Good to go! Window will be closing... + NylasEnv.storeWindowDimensions() + NylasEnv.saveStateAndUnloadWindow() + return undefined return false - window.onunload = => - NylasEnv.storeWindowDimensions() - NylasEnv.saveStateAndUnloadWindow() - NylasEnv.commands.add document.body, 'window:toggle-full-screen', -> NylasEnv.toggleFullScreen()