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

Commit

Permalink
serialize app state saves
Browse files Browse the repository at this point in the history
fixes #3543
  • Loading branch information
bridiver committed Sep 1, 2016
1 parent 980e664 commit 7a3600a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
49 changes: 32 additions & 17 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const flash = require('../js/flash')
const contentSettings = require('../js/state/contentSettings')
const privacy = require('../js/state/privacy')
const basicAuth = require('./browser/basicAuth')
const async = require('async')

// Used to collect the per window state when shutting down the application
let perWindowState = []
Expand All @@ -85,6 +86,10 @@ const prefsRestartLastValue = {}

const unsafeTestMasterKey = 'c66af15fc6555ebecf7cee3a5b82c108fd3cb4b587ab0b299d28e39c79ecc708'

const sessionStoreQueue = async.queue((task, callback) => {
task(callback)
}, 1)

/**
* Gets the master key for encrypting login credentials from the OS keyring.
*/
Expand Down Expand Up @@ -164,24 +169,34 @@ const saveIfAllCollected = (forceSave) => {
}
}
}
sessionStoreQueue.push(saveAppState.bind(null, appState))
}
}

const logSaveAppStateError = (e) => {
console.error('Error saving app state: ', e)
}
SessionStore.saveAppState(appState, shuttingDown).catch(logSaveAppStateError).then(() => {
if (shuttingDown) {
sessionStateStoreCompleteOnQuit = true
// If there's an update to apply, then do it here.
// Otherwise just quit.
if (appState.updates && (appState.updates.status === UpdateStatus.UPDATE_APPLYING_NO_RESTART ||
appState.updates.status === UpdateStatus.UPDATE_APPLYING_RESTART)) {
Updater.quitAndInstall()
} else {
app.quit()
}
const logSaveAppStateError = (e) => {
console.error('Error saving app state: ', e)
}

const saveAppState = (appState, cb) => {
SessionStore.saveAppState(appState, shuttingDown).catch((e) => {
logSaveAppStateError(e)
cb()
}).then(() => {
if (shuttingDown) {
sessionStateStoreCompleteOnQuit = true
// If there's an update to apply, then do it here.
// Otherwise just quit.
if (appState.updates && (appState.updates.status === UpdateStatus.UPDATE_APPLYING_NO_RESTART ||
appState.updates.status === UpdateStatus.UPDATE_APPLYING_RESTART)) {
Updater.quitAndInstall()
} else {
app.quit()
}
})
}
// no callback here because we don't want to get a partial write during shutdown
} else {
cb()
}
})
}

/**
Expand Down Expand Up @@ -279,7 +294,7 @@ app.on('ready', () => {

e.preventDefault()

clearTimeout(initiateSessionStateSave)
clearInterval(initiateSessionStateSave)
initiateSessionStateSave(true)

// Just in case a window is not responsive, we don't want to wait forever.
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"dependencies": {
"abp-filter-parser-cpp": "1.1.x",
"acorn": "3.2.0",
"async": "^2.0.1",
"electron-localshortcut": "^0.6.0",
"electron-prebuilt": "brave/electron-prebuilt",
"electron-squirrel-startup": "^1.0.0",
Expand All @@ -92,8 +93,8 @@
"ledger-client": "^0.8.55",
"ledger-publisher": "^0.8.57",
"lru_cache": "^1.0.0",
"random-lib": "2.1.0",
"qr-image": "^3.1.0",
"random-lib": "2.1.0",
"react": "^15.0.1",
"react-dom": "^15.0.1",
"react-stickynode": "1.1.x",
Expand Down

0 comments on commit 7a3600a

Please sign in to comment.