From 49392a984ba590b34b1da6174d2c200b24c81dee Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sat, 12 Dec 2015 20:32:06 +0900 Subject: [PATCH] Add `--config-file=FILE` option for testing --- src/index.js | 5 +++-- src/main.js | 11 ++++++++++- src/package.json | 3 ++- src/settings.html | 2 +- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index f7d904f8..e74dba8c 100644 --- a/src/index.js +++ b/src/index.js @@ -12,8 +12,9 @@ var contextMenu = require('./menus/context'); var webView = document.getElementById('mainWebview'); try { - var configFile = electron.remote.app.getPath('userData') + '/config.json'; - var config = require(configFile); + var configFile = remote.getGlobal('config-file'); + var str = fs.readFileSync(configFile); + var config = JSON.parse(str); if (config.url) { webView.setAttribute('src', config.url); } diff --git a/src/main.js b/src/main.js index 55e70bf7..bce6eb52 100644 --- a/src/main.js +++ b/src/main.js @@ -10,14 +10,23 @@ const fs = require('fs'); var appMenu = require('./menus/app'); +var argv = require('yargs').argv; + var client = null; -if (process.argv.indexOf('--livereload') > 0) { +if (argv.livereload) { client = require('electron-connect').client.create(); client.on('stop', function() { app.quit(); }); } +if (argv['config-file']) { + global['config-file'] = argv['config-file']; +} +else { + global['config-file'] = app.getPath('userData') + '/config.json' +} + // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. var mainWindow = null; diff --git a/src/package.json b/src/package.json index 0cf73a5d..7d355904 100644 --- a/src/package.json +++ b/src/package.json @@ -9,6 +9,7 @@ "electron-connect": "^0.3.3" }, "dependencies": { - "os-locale": "^1.4.0" + "os-locale": "^1.4.0", + "yargs": "^3.31.0" } } diff --git a/src/settings.html b/src/settings.html index 85931cd7..865bee27 100644 --- a/src/settings.html +++ b/src/settings.html @@ -19,7 +19,7 @@ var fs = require('fs'); var saveSettings = function() { - var configFile = remote.app.getPath('userData') + '/config.json'; + var configFile = remote.getGlobal('config-file'); var urlInput = document.getElementById('url'); var config = { url: urlInput.value