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

Commit

Permalink
check for valid data before upgrading and assign defaults after cleaning
Browse files Browse the repository at this point in the history
fixes #3550
  • Loading branch information
bridiver committed Aug 30, 2016
1 parent c9d3053 commit 7d2bbc9
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions app/sessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,30 +317,35 @@ module.exports.loadAppState = () => {
}

try {
data = Object.assign(module.exports.defaultAppState(), JSON.parse(data))
data = JSON.parse(data)
// autofill data migration
if (Array.isArray(data.autofill.addresses)) {
let addresses = exports.defaultAppState().autofill.addresses
data.autofill.addresses.forEach((guid) => {
addresses.guid.push(guid)
addresses.timestamp = new Date().getTime()
})
data.autofill.addresses = addresses
}
if (Array.isArray(data.autofill.creditCards)) {
let creditCards = exports.defaultAppState().autofill.creditCards
data.autofill.creditCards.forEach((guid) => {
creditCards.guid.push(guid)
creditCards.timestamp = new Date().getTime()
})
data.autofill.creditCards = creditCards
if (data.autofill) {
if (Array.isArray(data.autofill.addresses)) {
let addresses = exports.defaultAppState().autofill.addresses
data.autofill.addresses.forEach((guid) => {
addresses.guid.push(guid)
addresses.timestamp = new Date().getTime()
})
data.autofill.addresses = addresses
}
if (Array.isArray(data.autofill.creditCards)) {
let creditCards = exports.defaultAppState().autofill.creditCards
data.autofill.creditCards.forEach((guid) => {
creditCards.guid.push(guid)
creditCards.timestamp = new Date().getTime()
})
data.autofill.creditCards = creditCards
}
}

// xml migration
if (data.settings[settings.DEFAULT_SEARCH_ENGINE] === 'content/search/google.xml') {
data.settings[settings.DEFAULT_SEARCH_ENGINE] = 'Google'
}
if (data.settings[settings.DEFAULT_SEARCH_ENGINE] === 'content/search/duckduckgo.xml') {
data.settings[settings.DEFAULT_SEARCH_ENGINE] = 'DuckDuckGo'
if (data.settings) {
if (data.settings[settings.DEFAULT_SEARCH_ENGINE] === 'content/search/google.xml') {
data.settings[settings.DEFAULT_SEARCH_ENGINE] = 'Google'
}
if (data.settings[settings.DEFAULT_SEARCH_ENGINE] === 'content/search/duckduckgo.xml') {
data.settings[settings.DEFAULT_SEARCH_ENGINE] = 'DuckDuckGo'
}
}
} catch (e) {
// TODO: Session state is corrupted, maybe we should backup this
Expand All @@ -353,6 +358,7 @@ module.exports.loadAppState = () => {
if (data.cleanedOnShutdown !== true || data.lastAppVersion !== app.getVersion()) {
module.exports.cleanAppData(data, false)
}
data = Object.assign(module.exports.defaultAppState(), data)
data.cleanedOnShutdown = false
// Always recalculate the update status
if (data.updates) {
Expand Down

0 comments on commit 7d2bbc9

Please sign in to comment.