Skip to content

Commit

Permalink
If crashing within first 2min don't lose windows
Browse files Browse the repository at this point in the history
Fix brave#10349

Auditors: @bsclifton

This happens because a save would happen on init before the initial window state was present
  • Loading branch information
bbondy authored and dfperry5 committed Aug 18, 2017
1 parent afa0070 commit 43d9fe5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 2 additions & 3 deletions app/sessionStoreShutdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,12 @@ app.on('before-quit', (e) => {
if (sessionStateSaveInterval !== undefined) {
clearInterval(sessionStateSaveInterval)
}
initiateSessionStateSave()
module.exports.initiateSessionStateSave()
})

const startSessionSaveInterval = () => {
// save app state every 5 minutes regardless of update frequency
initiateSessionStateSave()
sessionStateSaveInterval = setInterval(initiateSessionStateSave, appConfig.sessionSaveInterval)
sessionStateSaveInterval = setInterval(module.exports.initiateSessionStateSave, appConfig.sessionSaveInterval)
}

// User initiated exit using File->Quit
Expand Down
14 changes: 14 additions & 0 deletions test/unit/app/sessionStoreShutdownTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,18 @@ describe('sessionStoreShutdown unit tests', function () {
})
})
})
describe('startSessionSaveInterval', function () {
before(function () {
this.initiateSessionStateSave = sinon.spy(sessionStoreShutdown, 'initiateSessionStateSave')
})
after(function () {
this.initiateSessionStateSave.restore()
})
// We only care that initiateSessionStateSave is not called sync.
// Windows will be initialized for the non sync case.
it('does not call initiateSessionStateSave', function () {
sessionStoreShutdown.startSessionSaveInterval()
assert.equal(this.initiateSessionStateSave.notCalled, true)
})
})
})

0 comments on commit 43d9fe5

Please sign in to comment.