Skip to content

Commit a446a5e

Browse files
authored
Merge pull request RocketChat#372 from RocketChat/feature/reload
Show reload screen when server fails to load
2 parents 22aa692 + 8cd2805 commit a446a5e

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

src/public/images/error.png

10.7 KB
Loading

src/public/loading-error.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!doctype html>
2+
<html style="height: 100%;">
3+
<head>
4+
<title></title>
5+
<meta charset="utf-8" />
6+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
7+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
8+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
9+
<link rel="stylesheet" type="text/css" href="../stylesheets/main.css">
10+
</head>
11+
<body style="height: 100%;">
12+
<section style="text-align: center;background-color: #022439;height:100%;">
13+
<img src="./images/error.png" />
14+
<div class="load-fail" id="load-fail">
15+
<h2 style="color:white">Server Failed to Load</h2>
16+
<div class="loading-animation" id="loading" style="display:none;">
17+
<div class="bounce1"></div>
18+
<div class="bounce2"></div>
19+
<div class="bounce3"></div>
20+
</div>
21+
<button class="button primary" id="reload">Reload</button>
22+
</div>
23+
</section>
24+
</body>
25+
</html>

src/public/preload.js

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ window.onload = function () {
4545
}
4646

4747
$(document).on('click', 'a', checkExternalUrl);
48+
49+
$('#reload').click(function () {
50+
ipcRenderer.sendToHost('reload-server');
51+
$(this).hide();
52+
$(this).parent().find('.loading-animation').show();
53+
});
4854
};
4955

5056
// Prevent redirect to url when dragging in

src/scripts/start.js

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export var start = function () {
158158
});
159159

160160
$('.add-server').on('click', function () {
161+
webview.loaded();
161162
servers.clearActive();
162163
});
163164

src/scripts/webview.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EventEmitter } from 'events';
22
import servers from './servers';
33
import sidebar from './sidebar';
4-
import { shell, desktopCapturer, ipcRenderer } from 'electron';
4+
import { desktopCapturer, ipcRenderer } from 'electron';
55

66
class WebView extends EventEmitter {
77
constructor () {
@@ -44,12 +44,15 @@ class WebView extends EventEmitter {
4444
}
4545

4646
loaded () {
47-
var loading = document.querySelector('#loading');
48-
var form = document.querySelector('#login-card');
49-
var footer = document.querySelector('footer');
50-
loading.style.display = 'none';
51-
form.style.display = 'block';
52-
footer.style.display = 'block';
47+
document.querySelector('#loading').style.display = 'none';
48+
document.querySelector('#login-card').style.display = 'block';
49+
document.querySelector('footer').style.display = 'block';
50+
}
51+
52+
loading () {
53+
document.querySelector('#loading').style.display = 'block';
54+
document.querySelector('#login-card').style.display = 'none';
55+
document.querySelector('footer').style.display = 'none';
5356
}
5457

5558
add (host) {
@@ -98,12 +101,21 @@ class WebView extends EventEmitter {
98101
ipcRenderer.send('screenshare', sources);
99102
});
100103
break;
104+
case 'reload-server':
105+
const active = this.getActive();
106+
const server = active.getAttribute('server');
107+
this.loading();
108+
active.loadURL(server);
109+
break;
101110
}
102111
});
103112

104113
webviewObj.addEventListener('dom-ready', () => {
105114
this.emit('dom-ready', host.url);
106-
this.loaded(host);
115+
});
116+
117+
webviewObj.addEventListener('did-fail-load', () => {
118+
webviewObj.loadURL('file://' + __dirname + '/loading-error.html');
107119
});
108120

109121
this.webviewParentElement.appendChild(webviewObj);

0 commit comments

Comments
 (0)