diff --git a/package.json b/package.json
index fb48d9a8..22d5b09d 100644
--- a/package.json
+++ b/package.json
@@ -8,7 +8,7 @@
"scripts": {
"postinstall": "cd src && npm install",
"start": "gulp build && electron src",
- "test": "mocha"
+ "test": "gulp build && mocha"
},
"devDependencies": {
"babel-preset-react": "^6.3.13",
diff --git a/src/browser/index.jsx b/src/browser/index.jsx
index 8084ae04..9e512115 100644
--- a/src/browser/index.jsx
+++ b/src/browser/index.jsx
@@ -166,13 +166,17 @@ var MattermostView = React.createClass({
// 'disablewebsecurity' is necessary to display external images.
// However, it allows also CSS/JavaScript.
// So webview should use 'allowDisplayingInsecureContent' as same as BrowserWindow.
- return ();
+ return ();
}
});
-
-var configFile = remote.getGlobal('config-file');
-var config = settings.readFileSync(configFile);
+var config;
+try {
+ var configFile = remote.getGlobal('config-file');
+ config = settings.readFileSync(configFile);
+} catch (e) {
+ window.location = 'settings.html';
+}
var contextMenu = require('./menus/context');
var menu = contextMenu.createDefault();
diff --git a/src/main.js b/src/main.js
index f76dfa5f..1dc0bbeb 100644
--- a/src/main.js
+++ b/src/main.js
@@ -8,6 +8,7 @@ const Tray = electron.Tray;
const ipc = electron.ipcMain;
const fs = require('fs');
+var settings = require('./common/settings');
var appMenu = require('./menus/app');
var argv = require('yargs').argv;
@@ -27,6 +28,18 @@ else {
global['config-file'] = app.getPath('userData') + '/config.json'
}
+try {
+ var configFile = global['config-file'];
+ var config = settings.readFileSync(configFile);
+ if (config.version != settings.version) {
+ config = settings.upgrade(config);
+ settings.writeFileSync(configFile, config);
+ }
+}
+catch (e) {
+ console.log('Failed to read or upgrade 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/test/browser_test.js b/test/browser_test.js
index 24c3daf7..1a1361ab 100644
--- a/test/browser_test.js
+++ b/test/browser_test.js
@@ -80,18 +80,30 @@ describe('electron-mattermost', function() {
});
describe('index.html', function() {
- before(function() {
- fs.writeFileSync(config_file_path, JSON.stringify({
+ const config = {
+ version: 1,
+ teams: [{
+ name: 'example_1',
url: mattermost_url
- }));
+ }, {
+ name: 'example_2',
+ url: mattermost_url
+ }]
+ };
+
+ before(function() {
+ fs.writeFileSync(config_file_path, JSON.stringify(config));
});
- it('should set src of #mainWebview from config file', function(done) {
+ it('should set src of webview from config file', function(done) {
var client = webdriverio.remote(options);
client
.init()
- .getAttribute('#mainWebview', 'src').then(function(attribute) {
- attribute.should.equal(mattermost_url);
+ .getAttribute('.mattermostView', 'src').then(function(attribute) {
+ console.log(attribute);
+ attribute.forEach(function(attr, index) {
+ attr.should.equal(config.teams[index].url);
+ });
})
.end().then(function() {
done();