diff --git a/desktop/main.js b/desktop/main.js index 96da77ce..8421eb92 100644 --- a/desktop/main.js +++ b/desktop/main.js @@ -97,7 +97,11 @@ const settingsPromise = loadSettingsEncryptionKey().then((key) => { logProgress('loading settings key'); return loadConfig('app-settings').then((settings) => { - appSettings = settings ? JSON.parse(settings) : {}; + try { + appSettings = settings ? JSON.parse(settings) : {}; + } catch (e) { + logStartupMessage(`Error loading app settings: ${e}`); + } logProgress('reading app settings'); }); }); @@ -444,7 +448,11 @@ function restoreMainWindowPosition() { const fileName = path.join(main.getPath('userData'), windowPositionFileName); fs.readFile(fileName, 'utf8', (e, data) => { if (data) { - mainWindowPosition = JSON.parse(data); + try { + mainWindowPosition = JSON.parse(data); + } catch (e) { + logStartupMessage(`Error loading main window position: ${e}`); + } if (mainWindow && mainWindowPosition) { if (mainWindowPosition.width && mainWindowPosition.height) { mainWindow.setBounds(mainWindowPosition); @@ -650,7 +658,9 @@ function setUserDataPaths() { } if (isDev && process.env.KEEWEB_IS_PORTABLE) { - isPortable = !!JSON.parse(process.env.KEEWEB_IS_PORTABLE); + try { + isPortable = !!JSON.parse(process.env.KEEWEB_IS_PORTABLE); + } catch {} } logProgress('portable check'); @@ -660,15 +670,22 @@ function setUserDataPaths() { const portableConfigPath = path.join(portableConfigDir, portableConfigFileName); if (fs.existsSync(portableConfigPath)) { - const portableConfig = JSON.parse(fs.readFileSync(portableConfigPath, 'utf8')); - const portableUserDataDir = path.resolve(portableConfigDir, portableConfig.userDataDir); + try { + const portableConfig = JSON.parse(fs.readFileSync(portableConfigPath, 'utf8')); + const portableUserDataDir = path.resolve( + portableConfigDir, + portableConfig.userDataDir + ); - if (!fs.existsSync(portableUserDataDir)) { - fs.mkdirSync(portableUserDataDir, { recursive: true }); + if (!fs.existsSync(portableUserDataDir)) { + fs.mkdirSync(portableUserDataDir, { recursive: true }); + } + + main.setPath('userData', portableUserDataDir); + usingPortableUserDataDir = true; + } catch (e) { + logStartupMessage(`Error loading portable config: ${e}`); } - - main.setPath('userData', portableUserDataDir); - usingPortableUserDataDir = true; } } @@ -914,7 +931,9 @@ function loadLocale() { if (appSettings?.locale === localeValues?.locale) { setLocale(localeValues); } - } catch {} + } catch (e) { + logStartupMessage(`Error loading locale: ${e}`); + } } locale.on('changed', () => { setMenu(); diff --git a/release-notes.md b/release-notes.md index 7e5eb408..4c340c01 100644 --- a/release-notes.md +++ b/release-notes.md @@ -3,6 +3,7 @@ Release notes ##### v1.18.3 (2021-05-09) `-` fix #1804: filling OTP in browser extensions `*` fix #1805: auto-unchecking auto-type filters if nothing found +`*` fix #1806: fixed a possible config loading error during startup ##### v1.18.2 (2021-05-08) `-` fix #1802: opening files with saved keyfiles