Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Last window closed should be immutable #10437

Merged
merged 1 commit into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions app/sessionStoreShutdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let sessionStateStoreCompleteCallback
let saveAppStateTimeout
let windowCloseRequestId
let shuttingDown
let lastWindowThatWasClosedState
let immutableLastWindowClosedState
let isAllWindowsClosed
let sessionStateSaveInterval
// Stores the last window state for each requested window in case a hung window happens,
Expand All @@ -42,7 +42,7 @@ const reset = () => {
saveAppStateTimeout = null
windowCloseRequestId = 0
shuttingDown = false
lastWindowThatWasClosedState = undefined
immutableLastWindowClosedState = undefined
isAllWindowsClosed = false
sessionStateSaveInterval = null
immutableWindowStateCache = Immutable.Map()
Expand Down Expand Up @@ -135,8 +135,8 @@ const initiateSessionStateSave = () => {
immutablePerWindowState = Immutable.List()

// quit triggered by window-all-closed should save last window state
if (isAllWindowsClosed && lastWindowThatWasClosedState) {
immutablePerWindowState = immutablePerWindowState.push(lastWindowThatWasClosedState)
if (isAllWindowsClosed && immutableLastWindowClosedState) {
immutablePerWindowState = immutablePerWindowState.push(immutableLastWindowClosedState)
saveAppState(true)
} else if (BrowserWindow.getAllWindows().length > 0) {
++windowCloseRequestId
Expand Down Expand Up @@ -213,15 +213,15 @@ ipcMain.on(messages.RESPONSE_WINDOW_STATE, (evt, data, id) => {

ipcMain.on(messages.LAST_WINDOW_STATE, (evt, data) => {
if (data) {
lastWindowThatWasClosedState = data
immutableLastWindowClosedState = Immutable.fromJS(data)
}
})

process.on(messages.UNDO_CLOSED_WINDOW, () => {
if (lastWindowThatWasClosedState) {
sessionStore.cleanPerWindowData(lastWindowThatWasClosedState)
appActions.newWindow(undefined, undefined, lastWindowThatWasClosedState)
lastWindowThatWasClosedState = undefined
if (immutableLastWindowClosedState) {
immutableLastWindowClosedState = sessionStore.cleanPerWindowData(immutableLastWindowClosedState)
appActions.newWindow(undefined, undefined, immutableLastWindowClosedState)
immutableLastWindowClosedState = undefined
}
})

Expand Down
10 changes: 5 additions & 5 deletions test/unit/app/sessionStoreShutdownTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,20 @@ describe('sessionStoreShutdown unit tests', function () {
})

it('works for first closed window', function () {
const windowState = Immutable.fromJS({ a: 1 })
const windowState = { a: 1, frames: [] }
fakeElectron.ipcMain.send(messages.LAST_WINDOW_STATE, {}, windowState)
process.emit(messages.UNDO_CLOSED_WINDOW)
assert(this.newWindowStub.calledOnce)
assert.deepEqual(this.newWindowStub.getCall(0).args[2], windowState)
assert.deepEqual(this.newWindowStub.getCall(0).args[2].toJS(), windowState)
})
it('works for subsequent windows', function () {
const windowState1 = Immutable.fromJS({ b: 1 })
const windowState2 = Immutable.fromJS({ x: 2 })
const windowState1 = { b: 1, frames: [] }
const windowState2 = { x: 2, frames: [] }
fakeElectron.ipcMain.send(messages.LAST_WINDOW_STATE, {}, windowState1)
fakeElectron.ipcMain.send(messages.LAST_WINDOW_STATE, {}, windowState2)
process.emit(messages.UNDO_CLOSED_WINDOW)
assert(this.newWindowStub.calledOnce)
assert.deepEqual(this.newWindowStub.getCall(0).args[2], windowState2)
assert.deepEqual(this.newWindowStub.getCall(0).args[2].toJS(), windowState2)
})
})

Expand Down