From 3ea313743dd4b928b661a8087b1b8068c7fda8e4 Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Fri, 4 Mar 2016 01:51:34 +0900 Subject: [PATCH 1/4] Add error view when failed to load the URL --- src/browser/index.jsx | 44 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/browser/index.jsx b/src/browser/index.jsx index 059da87a..a9e4691f 100644 --- a/src/browser/index.jsx +++ b/src/browser/index.jsx @@ -10,6 +10,8 @@ const Col = ReactBootstrap.Col; const Nav = ReactBootstrap.Nav; const NavItem = ReactBootstrap.NavItem; const Badge = ReactBootstrap.Badge; +const ListGroup = ReactBootstrap.ListGroup; +const ListGroupItem = ReactBootstrap.ListGroupItem; const electron = require('electron'); const remote = electron.remote; @@ -204,6 +206,7 @@ var TabBar = React.createClass({ var MattermostView = React.createClass({ getInitialState: function() { return { + did_fail_load: null }; }, handleUnreadCountChange: function(unreadCount, mentionCount, isUnread, isMentioned) { @@ -216,6 +219,13 @@ var MattermostView = React.createClass({ var thisObj = this; var webview = ReactDOM.findDOMNode(this.refs.webview); + webview.addEventListener('did-fail-load', function(e) { + console.log(thisObj.props.name, 'webview did-fail-load', e); + thisObj.setState({ + did_fail_load: e + }); + }); + // Open link in browserWindow. for exmaple, attached files. webview.addEventListener('new-window', function(e) { var currentURL = url.parse(webview.getURL()); @@ -293,7 +303,39 @@ 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 (); + if (this.state.did_fail_load === null) { + return (); + } else { + return () + } + } +}); + +// ErrorCode: https://code.google.com/p/chromium/codesearch#chromium/src/net/base/net_error_list.h +var ErrorView = React.createClass({ + render: function() { + return ( + +

Failed to load the URL

+

+ { 'URL: ' } + { this.props.errorInfo.validatedURL } +

+

+ { 'Error code: ' } + { this.props.errorInfo.errorCode } +

+

+ { this.props.errorInfo.errorDescription } +

+

Please check below.

+ + Is your computer online? + Is the server alive? + Is the URL correct? + +
+ ); } }); From 1fad30aed7f906287c71b6acc20ff5a85197c985 Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sat, 5 Mar 2016 20:26:13 +0900 Subject: [PATCH 2/4] Fixup messages --- src/browser/index.jsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/browser/index.jsx b/src/browser/index.jsx index a9e4691f..1740b34e 100644 --- a/src/browser/index.jsx +++ b/src/browser/index.jsx @@ -312,6 +312,7 @@ var MattermostView = React.createClass({ }); // ErrorCode: https://code.google.com/p/chromium/codesearch#chromium/src/net/base/net_error_list.h +// FIXME: need better wording in English var ErrorView = React.createClass({ render: function() { return ( @@ -328,7 +329,7 @@ var ErrorView = React.createClass({

{ this.props.errorInfo.errorDescription }

-

Please check below.

+

Please check below. Then, reload this window. (Ctrl+R or Command+R)

Is your computer online? Is the server alive? From 1ccb7cebce4e7fb9c285dacc1348c894fa730aef Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sat, 5 Mar 2016 20:52:27 +0900 Subject: [PATCH 3/4] Add test for failed to load URL --- src/browser/index.jsx | 4 ++-- test/browser_test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/browser/index.jsx b/src/browser/index.jsx index 1740b34e..9c10648f 100644 --- a/src/browser/index.jsx +++ b/src/browser/index.jsx @@ -306,7 +306,7 @@ var MattermostView = React.createClass({ if (this.state.did_fail_load === null) { return (); } else { - return () + return () } } }); @@ -316,7 +316,7 @@ var MattermostView = React.createClass({ var ErrorView = React.createClass({ render: function() { return ( - +

Failed to load the URL

{ 'URL: ' } diff --git a/test/browser_test.js b/test/browser_test.js index a30ae701..33bb44fb 100644 --- a/test/browser_test.js +++ b/test/browser_test.js @@ -166,6 +166,21 @@ describe('electron-mattermost', function() { }) .end(); }); + + it('should show error when using incorrect URL', function() { + this.timeout(30000) + fs.writeFileSync(config_file_path, JSON.stringify({ + version: 1, + teams: [{ + name: 'error_1', + url: 'http://false' + }] + })); + return client + .init() + .waitForVisible('#mattermostView0-fail', 20000) + .end(); + }); }); describe('settings.html', function() { From f9387d251d9c4088abf3258f496933d8eb647cae Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sun, 6 Mar 2016 14:23:31 +0900 Subject: [PATCH 4/4] Notify the error --- src/browser/index.jsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/browser/index.jsx b/src/browser/index.jsx index 9c10648f..00c7bb83 100644 --- a/src/browser/index.jsx +++ b/src/browser/index.jsx @@ -221,6 +221,11 @@ var MattermostView = React.createClass({ webview.addEventListener('did-fail-load', function(e) { console.log(thisObj.props.name, 'webview did-fail-load', e); + // should use permanent way to indicate + var did_fail_load_notification = new Notification(`Failed to load "${thisObj.props.name}"`, { + body: `ErrorCode: ${e.errorCode}`, + icon: '../resources/appicon.png' + }); thisObj.setState({ did_fail_load: e });