diff --git a/src/browser/index.jsx b/src/browser/index.jsx index 059da87a..00c7bb83 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,18 @@ 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); + // 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 + }); + }); + // Open link in browserWindow. for exmaple, attached files. webview.addEventListener('new-window', function(e) { var currentURL = url.parse(webview.getURL()); @@ -293,7 +308,40 @@ 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 +// FIXME: need better wording in English +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. Then, reload this window. (Ctrl+R or Command+R)

+ + Is your computer online? + Is the server alive? + Is the URL correct? + +
+ ); } }); 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() {