diff --git a/app/sessionStore.js b/app/sessionStore.js index 855f3973282..9c45103b723 100644 --- a/app/sessionStore.js +++ b/app/sessionStore.js @@ -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 @@ -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) {