mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-03-13 08:44:37 +08:00
fix(drafts): drafts save when they close
Summary: Closes T1264: Drafts save when they close Test Plan: edgehill --test Reviewers: bengotow Reviewed By: bengotow Maniphest Tasks: T1264 Differential Revision: https://review.inboxapp.com/D1515
This commit is contained in:
parent
a237d69327
commit
d029e8b959
4 changed files with 23 additions and 10 deletions
|
@ -365,14 +365,14 @@ describe "DraftStore", ->
|
|||
}}
|
||||
|
||||
it "should return false and call window.close itself", ->
|
||||
spyOn(window, 'close')
|
||||
spyOn(atom, 'close')
|
||||
expect(DraftStore._onBeforeUnload()).toBe(false)
|
||||
runs ->
|
||||
@resolve()
|
||||
waitsFor ->
|
||||
window.close.callCount > 0
|
||||
atom.close.callCount > 0
|
||||
runs ->
|
||||
expect(window.close).toHaveBeenCalled()
|
||||
expect(atom.close).toHaveBeenCalled()
|
||||
|
||||
describe "when no drafts return unresolved commit promises", ->
|
||||
beforeEach ->
|
||||
|
|
|
@ -217,7 +217,8 @@ class Atom extends Model
|
|||
@subscribe @packages.onDidActivateInitialPackages => @watchThemes()
|
||||
@windowEventHandler = new WindowEventHandler
|
||||
|
||||
window.onbeforeunload = => @onBeforeUnload()
|
||||
window.onbeforeunload = => @_unloading()
|
||||
@_unloadCallbacks = []
|
||||
|
||||
# Start our error reporting to the backend and attach error handlers
|
||||
# to the window and the Bluebird Promise library, converting things
|
||||
|
@ -847,6 +848,18 @@ class Atom extends Model
|
|||
ipc.send('call-window-method', 'setAutoHideMenuBar', autoHide)
|
||||
ipc.send('call-window-method', 'setMenuBarVisibility', !autoHide)
|
||||
|
||||
onBeforeUnload: ->
|
||||
Actions = require './flux/actions'
|
||||
Actions.unloading()
|
||||
# Lets multiple components register callbacks.
|
||||
# The callbacks are expected to return either true or false
|
||||
onBeforeUnload: (callback) -> @_unloadCallbacks.push(callback)
|
||||
|
||||
_unloading: ->
|
||||
continueUnload = true
|
||||
for callback in @_unloadCallbacks
|
||||
returnValue = callback()
|
||||
if returnValue is true
|
||||
continue
|
||||
else if returnValue is false
|
||||
continueUnload = false
|
||||
else
|
||||
console.warn "You registered an `onBeforeUnload` callback that does not return either exactly `true` or `false`. It returned #{returnValue}", callback
|
||||
return continueUnload
|
||||
|
|
|
@ -441,7 +441,6 @@ class Actions
|
|||
@metadataError: ActionScopeWindow
|
||||
@metadataCreated: ActionScopeWindow
|
||||
@metadataDestroyed: ActionScopeWindow
|
||||
@unloading: ActionScopeWindow
|
||||
|
||||
|
||||
# Read the actions we declared on the dummy Actions object above
|
||||
|
|
|
@ -58,7 +58,8 @@ class DraftStore
|
|||
|
||||
@listenTo Actions.sendDraftError, @_onSendDraftError
|
||||
@listenTo Actions.sendDraftSuccess, @_onSendDraftSuccess
|
||||
@listenTo Actions.unloading, @_onBeforeUnload
|
||||
|
||||
atom.onBeforeUnload @_onBeforeUnload
|
||||
|
||||
@_draftSessions = {}
|
||||
@_sendingState = {}
|
||||
|
@ -163,7 +164,7 @@ class DraftStore
|
|||
if promises.length > 0
|
||||
Promise.settle(promises).then =>
|
||||
@_draftSessions = {}
|
||||
window.close()
|
||||
atom.close()
|
||||
|
||||
# Stop and wait before closing
|
||||
return false
|
||||
|
|
Loading…
Reference in a new issue