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

serialize app state saves #3632

Merged
merged 1 commit into from
Sep 3, 2016
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
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to require only async/queue so it doesn't pull in everything, pls do in a follow up, I won't block merging this though on it.


// 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