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 Oct 11, 2017
1 parent 84dc9d9 commit b1200f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/common/settings.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

const fs = require('fs');

const path = require('path');
let deepmerge = require('deepmerge').default;
if (process.env.TEST) {
deepmerge = require('deepmerge'); // eslint-disable-line
Expand All @@ -14,7 +16,7 @@ function merge(base, target) {
return Object.assign({}, base, target);
}

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

Expand All @@ -27,7 +29,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 @@ -87,6 +89,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 b1200f4

Please sign in to comment.