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

Commit

Permalink
Merge pull request #3632 from brave/serialize-session-store
Browse files Browse the repository at this point in the history
serialize app state saves
  • Loading branch information
bbondy committed Sep 3, 2016
2 parents 0ace83f + 7a3600a commit 84ee6b8
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 @@ -64,6 +64,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')

if (!process.env.BRAVE_USER_DATA_DIR && ['development', 'test'].includes(process.env.NODE_ENV)) {
process.env.BRAVE_USER_DATA_DIR = path.join(app.getPath('appData'), app.getName() + '-' + process.env.NODE_ENV)
Expand Down Expand Up @@ -94,6 +95,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 @@ -173,24 +178,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 @@ -288,7 +303,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.58",
"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 84ee6b8

Please sign in to comment.