2019-11-05 19:29:51 +00:00
|
|
|
/* eslint strict: 0 */
|
2016-10-09 19:14:02 +00:00
|
|
|
"use strict";
|
|
|
|
|
2016-06-07 17:56:49 +00:00
|
|
|
/*
|
|
|
|
* This is a separate file for two reasons:
|
|
|
|
* 1. CSP policy does not allow inline javascript
|
|
|
|
* 2. It has to be a small javascript executed before all other scripts,
|
|
|
|
* so that the timeout can be triggered while slow JS is loading
|
|
|
|
*/
|
|
|
|
|
2017-12-16 23:14:58 +00:00
|
|
|
(function() {
|
2019-11-05 19:29:51 +00:00
|
|
|
const msg = document.getElementById("loading-page-message");
|
|
|
|
msg.textContent = "Loading the app…";
|
2018-07-13 07:43:31 +00:00
|
|
|
|
2019-11-05 19:29:51 +00:00
|
|
|
document
|
|
|
|
.getElementById("loading-reload")
|
|
|
|
.addEventListener("click", () => location.reload(true));
|
2018-07-13 07:37:39 +00:00
|
|
|
|
2019-11-05 19:29:51 +00:00
|
|
|
const displayReload = () => {
|
|
|
|
const loadingReload = document.getElementById("loading-reload");
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-12-16 23:14:58 +00:00
|
|
|
if (loadingReload) {
|
2017-10-28 20:50:57 +00:00
|
|
|
loadingReload.style.visibility = "visible";
|
2017-12-16 23:14:58 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-05 19:29:51 +00:00
|
|
|
const loadingSlowTimeout = setTimeout(() => {
|
|
|
|
const loadingSlow = document.getElementById("loading-slow");
|
|
|
|
loadingSlow.style.visibility = "visible";
|
|
|
|
displayReload();
|
2017-12-16 23:14:58 +00:00
|
|
|
}, 5000);
|
|
|
|
|
2019-11-05 19:29:51 +00:00
|
|
|
const errorHandler = (e) => {
|
|
|
|
msg.textContent = "An error has occurred that prevented the client from loading correctly.";
|
2017-12-16 23:14:58 +00:00
|
|
|
|
2019-11-05 19:29:51 +00:00
|
|
|
const summary = document.createElement("summary");
|
2017-12-16 23:14:58 +00:00
|
|
|
summary.textContent = "More details";
|
|
|
|
|
2019-11-05 19:29:51 +00:00
|
|
|
const data = document.createElement("pre");
|
2017-12-16 23:14:58 +00:00
|
|
|
data.textContent = e.message; // e is an ErrorEvent
|
|
|
|
|
2019-11-05 19:29:51 +00:00
|
|
|
const info = document.createElement("p");
|
2017-12-16 23:14:58 +00:00
|
|
|
info.textContent = "Open the developer tools of your browser for more information.";
|
|
|
|
|
2019-11-05 19:29:51 +00:00
|
|
|
const details = document.createElement("details");
|
2017-12-16 23:14:58 +00:00
|
|
|
details.appendChild(summary);
|
|
|
|
details.appendChild(data);
|
|
|
|
details.appendChild(info);
|
2019-11-05 19:29:51 +00:00
|
|
|
msg.parentNode.insertBefore(details, msg.nextSibling);
|
2017-12-16 23:14:58 +00:00
|
|
|
|
|
|
|
window.clearTimeout(loadingSlowTimeout);
|
2017-12-16 21:19:51 +00:00
|
|
|
displayReload();
|
2017-12-16 23:14:58 +00:00
|
|
|
};
|
2017-05-09 13:12:12 +00:00
|
|
|
|
2019-11-05 19:29:51 +00:00
|
|
|
window.addEventListener("error", errorHandler);
|
|
|
|
|
|
|
|
window.g_TheLoungeRemoveLoading = () => {
|
|
|
|
delete window.g_TheLoungeRemoveLoading;
|
|
|
|
window.clearTimeout(loadingSlowTimeout);
|
|
|
|
window.removeEventListener("error", errorHandler);
|
|
|
|
document.getElementById("loading").remove();
|
|
|
|
};
|
2018-06-05 12:29:43 +00:00
|
|
|
|
|
|
|
// Trigger early service worker registration
|
|
|
|
if ("serviceWorker" in navigator) {
|
|
|
|
navigator.serviceWorker.register("service-worker.js");
|
2019-07-23 12:31:26 +00:00
|
|
|
|
|
|
|
// Handler for messages coming from the service worker
|
2019-11-05 19:29:51 +00:00
|
|
|
const messageHandler = (event) => {
|
2019-07-23 12:31:26 +00:00
|
|
|
if (event.data.type === "fetch-error") {
|
2019-11-05 19:29:51 +00:00
|
|
|
errorHandler({
|
2019-07-23 12:31:26 +00:00
|
|
|
message: `Service worker failed to fetch an url: ${event.data.message}`,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display only one fetch error
|
|
|
|
navigator.serviceWorker.removeEventListener("message", messageHandler);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
navigator.serviceWorker.addEventListener("message", messageHandler);
|
2018-06-05 12:29:43 +00:00
|
|
|
}
|
2017-12-16 23:14:58 +00:00
|
|
|
})();
|