From de3c4cc8f1b530e1ba16b13c110cbbe842efc5d0 Mon Sep 17 00:00:00 2001 From: Jarred Witt Date: Thu, 7 Sep 2017 16:20:48 -0700 Subject: [PATCH] Add default team to config --- src/common/settings.js | 11 +++++++++-- src/main.js | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/common/settings.js b/src/common/settings.js index 8761787f687..4b1d71a483a 100644 --- a/src/common/settings.js +++ b/src/common/settings.js @@ -1,6 +1,7 @@ 'use strict'; const fs = require('fs'); +const path = require('path'); const deepmerge = require('deepmerge').default; const settingsVersion = 1; @@ -11,7 +12,7 @@ function merge(base, target) { return Object.assign({}, base, target); } -function deepMergeArray(dest) { +function deepMergeArray(source, dest) { return dest; } @@ -24,7 +25,7 @@ function loadDefault(version, spellCheckerLocale) { const base = baseConfig[ver] || baseConfig.default; const override = overrideConfig[ver] || {}; - const defaults = deepmerge(base, override, {clone: true, arrayMerge: deepMergeArray}); + const defaults = deepmerge(base, override, {arrayMerge: deepMergeArray}); return Object.assign(defaults, { spellCheckerLocale: spellCheckerLocale || defaults.spellCheckerLocale || 'en-US' @@ -84,6 +85,12 @@ module.exports = { if (config.version != settingsVersion) { // eslint-disable-line throw new Error('version ' + config.version + ' is not equal to ' + settingsVersion); } + + const dir = path.dirname(configFile); + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } + var data = JSON.stringify(config, null, ' '); fs.writeFileSync(configFile, data, 'utf8'); }, diff --git a/src/main.js b/src/main.js index 319e005908a..65d3d31e6f2 100644 --- a/src/main.js +++ b/src/main.js @@ -71,6 +71,12 @@ try { const spellCheckerLocale = SpellChecker.getSpellCheckerLocale(app.getLocale()); config = settings.loadDefault(null, spellCheckerLocale); console.log('Failed to read or upgrade config.json', e); + if (!config.teams.length && config.defaultTeam) { + config.teams.push(config.defaultTeam); + + const configFile = app.getPath('userData') + '/config.json'; + settings.writeFileSync(configFile, config); + } } ipcMain.on('update-config', () => {