Create configfile on first startup

Hide cfg.json from git
This commit is contained in:
Matt 2016-04-15 18:16:14 -04:00
parent b36082d0e7
commit c91baebfc4
6 changed files with 27 additions and 11 deletions

1
app/.gitignore vendored
View File

@ -1,2 +1,3 @@
data/cfg.json
node_modules/*
logs/*

View File

@ -126,7 +126,7 @@ footer {
color: #dcdcdc;
}
#actions {
padding: 20px;
padding: 20px 0 0 55px;
}
#seq_stats {
width: 40%;

View File

@ -2446,7 +2446,7 @@ var remote = require('remote'),
log = {};
//console.log(ipcRenderer.sendSync('light', { 'fuck' : true }) );
mcopy.cfg = JSON.parse(fs.readFileSync('./cfg.json'), 'utf8');
mcopy.cfg = JSON.parse(fs.readFileSync('./data/cfg.json'), 'utf8');
/******
State shared by ALL interfaces
@ -2546,7 +2546,7 @@ gui.grid = {};
gui.grid.layout = function () {
'use strict';
gui.grid.refresh();
mcopy.seq.stats();
//mcopy.seq.stats();
};
gui.grid.state = function (i) {
'use strict';
@ -2747,7 +2747,7 @@ nav.init = function () {
$('#toolbar').w2toolbar({
name: 'toolbar',
items: [
{ type: 'radio', id: 'sequence', group: '1', caption: 'Sequence', icon: 'fa fa-th', checked: true },
{ type: 'radio', id: 'sequencer', group: '1', caption: 'Sequencer', icon: 'fa fa-th', checked: true },
{ type: 'radio', id: 'script', group: '1', caption: 'Script', icon: 'fa fa-code' },
{ type: 'radio', id: 'controls', group: '1', caption: 'Controls', icon: 'fa fa-tasks' },
{ type: 'radio', id: 'light', group: '1', caption: 'Light', icon: 'mcopy-light' },

View File

@ -10,15 +10,30 @@ var electron = require('electron'),
Q = require('q'),
mcopy = {};
mcopy.cfg = JSON.parse(fs.readFileSync('./cfg.json', 'utf8'));
mcopy.arduino = require('./lib/mcopy-arduino.js')(mcopy.cfg);
mcopy.cfg = {};
mcopy.cfgFile = './data/cfg.json';
mcopy.cfgInit = function () {
if (!fs.existsSync(mcopy.cfgFile)) {
console.log('Using default configuration...');
fs.writeFileSync(mcopy.cfgFile, fs.readFileSync('./data/cfg.json.default'));
}
mcopy.cfg = JSON.parse(fs.readFileSync(mcopy.cfgFile, 'utf8'));
};
mcopy.cfgStore = function () {
var data = JSON.stringify(mcopy.cfg);
fs.writeFileSync(mcopy.cfgFile, data, 'utf8');
};
var arduino;
var mainWindow;
var init = function () {
'use strict';
mcopy.cfgInit();
createWindow();
log.init();
arduino = require('./lib/mcopy-arduino.js')(mcopy.cfg);
setTimeout(function () {
mcopy.arduino.init(function (err, device) {
if (err) {
@ -75,11 +90,11 @@ light.set = function (rgb) {
'use strict';
var str = rgb.join(','),
deferred = Q.defer();
mcopy.arduino.send(mcopy.cfg.arduino.cmd.light, function () {
arduino.send(mcopy.cfg.arduino.cmd.light, function () {
log.info('Light set to ' + str, 'LIGHT', true, true);
return deferred.resolve(mcopy.cfg.arduino.cmd.light);
});
mcopy.arduino.string(str);
arduino.string(str);
return deferred.promise;
};

View File

@ -9,7 +9,7 @@ var remote = require('remote'),
log = {};
//console.log(ipcRenderer.sendSync('light', { 'fuck' : true }) );
mcopy.cfg = JSON.parse(fs.readFileSync('./cfg.json'), 'utf8');
mcopy.cfg = JSON.parse(fs.readFileSync('./data/cfg.json'), 'utf8');
/******
State shared by ALL interfaces
@ -109,7 +109,7 @@ gui.grid = {};
gui.grid.layout = function () {
'use strict';
gui.grid.refresh();
mcopy.seq.stats();
//mcopy.seq.stats();
};
gui.grid.state = function (i) {
'use strict';
@ -310,7 +310,7 @@ nav.init = function () {
$('#toolbar').w2toolbar({
name: 'toolbar',
items: [
{ type: 'radio', id: 'sequence', group: '1', caption: 'Sequence', icon: 'fa fa-th', checked: true },
{ type: 'radio', id: 'sequencer', group: '1', caption: 'Sequencer', icon: 'fa fa-th', checked: true },
{ type: 'radio', id: 'script', group: '1', caption: 'Script', icon: 'fa fa-code' },
{ type: 'radio', id: 'controls', group: '1', caption: 'Controls', icon: 'fa fa-tasks' },
{ type: 'radio', id: 'light', group: '1', caption: 'Light', icon: 'mcopy-light' },