Skip to content

Commit

Permalink
Store app config in Application Data
Browse files Browse the repository at this point in the history
  • Loading branch information
remixz committed Mar 22, 2015
1 parent cb70ef8 commit 2527562
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
File renamed without changes.
29 changes: 20 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var Mongroup = require('mongroup')
var fs = require('fs')
var mkdir = require('mkdirp').sync
var debug = require('debug')('monu')
var open = require('open')

var icon, menu, configure, about

Expand Down Expand Up @@ -52,7 +53,7 @@ app.on('ready', function() {
})

ipc.on('open-dir', function openDir (ev) {
child.exec('open ' + conf.exec.cwd, function(err) {})
open(conf.exec.cwd)
})

ipc.on('get-all', function getAll (ev, data) {
Expand All @@ -77,18 +78,28 @@ app.on('ready', function() {
})

function loadConfig() {
var configFile = __dirname + '/config/config.json'
var conf

var dir = app.getPath('userData')
var configFile = dir + '/config.json'
var conf, data

try {
data = fs.readFileSync(configFile)
} catch (e) {
if (e.code === 'ENOENT') {
fs.writeFileSync(configFile, fs.readFileSync(__dirname + '/config.json'))
return loadConfig()
} else {
throw e
}
}

try {
conf = JSON.parse(fs.readFileSync(configFile))
conf = JSON.parse(data.toString())
} catch (e) {
throw new Error('Invalid configuration file -- could not parse JSON')
}

var dir = path.dirname(configFile)

conf.exec = {cwd: path.resolve(dir)}

conf.exec = {cwd: dir}
conf.logs = path.resolve(path.join(dir, conf.logs || 'logs'))
conf.pids = path.resolve(path.join(dir, conf.pids || 'pids'))

Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"app": "atom-shell ./"
},
"author": "",
"license": "BSD",
Expand All @@ -18,7 +19,11 @@
"ms": "^0.7.0",
"mustache": "^1.1.0",
"npm-execspawn": "^1.0.6",
"open": "0.0.5",
"page": "^1.6.1",
"ractive": "^0.7.1"
},
"devDependencies": {
"atom-shell": "^0.22.1"
}
}

0 comments on commit 2527562

Please sign in to comment.