handle gateway connecting before page load

This commit is contained in:
hippoz 2023-01-03 23:25:57 +02:00
parent 67f1b481ac
commit fa6f65ce8a
Signed by: hippoz
GPG key ID: 56C4E02A85F2FBED

View file

@ -12,41 +12,63 @@ import { timeline } from './timeline';
timeline.start(); timeline.start();
let loaded = false;
let loadedListener = null;
document.addEventListener("DOMContentLoaded", () => {
loaded = true;
if (loadedListener) {
loadedListener();
loadedListener = null;
}
});
function handleGatewaySettlement() { function handleGatewaySettlement() {
timeline.addCheckpoint("Got gateway settlement"); timeline.addCheckpoint("Got gateway settlement");
const loadingElement = document.getElementById("pre--loading-screen"); const loadApplication = () => {
if (loadingElement) { timeline.addCheckpoint("Application load started");
loadingElement.parentElement.removeChild(loadingElement);
const loadingElement = document.getElementById("pre--loading-screen");
if (loadingElement) {
loadingElement.parentElement.removeChild(loadingElement);
}
const app = new Main({
target: document.body
});
window.__waffle.app = app;
timeline.addCheckpoint("Created application");
pluginStore.consumePluginLoaders();
const scripts = getItem("app:javascript");
scripts.forEach((script) => {
const func = new Function(script);
func();
});
const styles = getItem("app:stylesheets");
styles.forEach((styleText) => {
const style = document.createElement("style");
style.textContent = styleText;
document.head.appendChild(style);
});
timeline.addCheckpoint("Loaded custom user content");
gateway.unsubscribe(GatewayEventType.Ready, handleGatewaySettlement);
gateway.unsubscribe(GatewayEventType.Close, handleGatewaySettlement);
timeline.addCheckpoint("All initialization finished");
timeline.dump();
};
if (!loaded) {
timeline.addCheckpoint("Waiting for DOM content before loading application");
loadedListener = loadApplication;
} else {
loadApplication();
} }
const app = new Main({
target: document.body
});
window.__waffle.app = app;
timeline.addCheckpoint("Created application");
pluginStore.consumePluginLoaders();
const scripts = getItem("app:javascript");
scripts.forEach((script) => {
const func = new Function(script);
func();
});
const styles = getItem("app:stylesheets");
styles.forEach((styleText) => {
const style = document.createElement("style");
style.textContent = styleText;
document.head.appendChild(style);
});
timeline.addCheckpoint("Loaded custom user content");
gateway.unsubscribe(GatewayEventType.Ready, handleGatewaySettlement);
gateway.unsubscribe(GatewayEventType.Close, handleGatewaySettlement);
timeline.addCheckpoint("All initialization finished");
timeline.dump();
} }
function main() { function main() {