Skip to content

Commit

Permalink
Add default team to config
Browse files Browse the repository at this point in the history
  • Loading branch information
jarredwitt authored and David Meza committed Sep 8, 2017
1 parent b5d4b2c commit de3c4cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/common/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const fs = require('fs');
const path = require('path');
const deepmerge = require('deepmerge').default;

const settingsVersion = 1;
Expand All @@ -11,7 +12,7 @@ function merge(base, target) {
return Object.assign({}, base, target);
}

function deepMergeArray(dest) {
function deepMergeArray(source, dest) {
return dest;
}

Expand All @@ -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'
Expand Down Expand Up @@ -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');
},
Expand Down
6 changes: 6 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit de3c4cc

Please sign in to comment.