Loading configs asynchronously now as well as with better error logging for the user
This commit is contained in:
parent
4dd168303b
commit
60aee1dc07
@ -3,7 +3,7 @@
|
||||
# Script to help build and run this fucking thing because apparantly npm sucks for
|
||||
# projects that use cli arguments
|
||||
|
||||
[[ -z "$1" ]] && echo Options: run - make && exit 0
|
||||
[[ -z "$1" ]] && echo Options: run \| build && exit 0
|
||||
|
||||
run() {
|
||||
./node_modules/electron/dist/electron main.js $@
|
||||
|
@ -6,22 +6,29 @@ const fs = require('fs')
|
||||
* @returns {Config} { path }
|
||||
*/
|
||||
function get_config(parser) {
|
||||
|
||||
const a = parser.parse_args()
|
||||
const defaultcfg = `${process.env.HOME || process.env.USERPROFILE}/.config/freechat/config.json`
|
||||
|
||||
// we'll just assume that the config is there as per the installation process
|
||||
const path = (a['config']) ? a['config'] : defaultcfg
|
||||
const file_contents = fs.readFileSync(path)
|
||||
const file_json = JSON.parse(file_contents)
|
||||
|
||||
// now we'll just blindly construct the config object from here on out
|
||||
let ret = { path: path }
|
||||
|
||||
fs.readFile(path, (err, data) => {
|
||||
if(err) {
|
||||
console.log('No valid config found')
|
||||
process.exit()
|
||||
}
|
||||
const file_json = JSON.parse(data)
|
||||
for(const key of Object.keys(file_json)) {
|
||||
if(key == 'path') { continue } // don't overwrite the old path
|
||||
else {
|
||||
ret[key] = file_json[key]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// now we'll just blindly construct the config object from here on out
|
||||
return ret
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user