mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-08-11 16:58:03 +00:00
Move browser incompatibility check outside the JS bundle
This commit is contained in:
parent
5be59f7fce
commit
f7fd1d94eb
2 changed files with 42 additions and 28 deletions
|
@ -21,6 +21,42 @@
|
||||||
<noscript>JavaScript is required</noscript>
|
<noscript>JavaScript is required</noscript>
|
||||||
<!-- tabindex is used to allow the app to have focus while inside of it -->
|
<!-- tabindex is used to allow the app to have focus while inside of it -->
|
||||||
<div data-app id="app" tabindex="0"></div>
|
<div data-app id="app" tabindex="0"></div>
|
||||||
|
<script>
|
||||||
|
// Confirm the browser is compatible before initializing the application
|
||||||
|
|
||||||
|
// Display an error if the browser is incompatible with a required API
|
||||||
|
// This is run outside the JS code bundle in case unsupported features cause a syntax error when parsing the bundle, preventing the any bundle code from running
|
||||||
|
let error;
|
||||||
|
if (!("BigUint64Array" in window)) {
|
||||||
|
error = `
|
||||||
|
<style>
|
||||||
|
h2, p, a { text-align: center; color: white; }
|
||||||
|
#app { display: none; }
|
||||||
|
</style>
|
||||||
|
<h2>This browser is too old to run Graphite</h2>
|
||||||
|
<p>Please upgrade to a modern web browser such as the latest Firefox, Chrome, Edge, or Safari version 15 or newer.</p>
|
||||||
|
<p>(The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array#browser_compatibility" target="_blank"><code>BigInt64Array</code></a>
|
||||||
|
JavaScript API must be supported by the browser for Graphite to function.)</p>
|
||||||
|
`.trim();
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
document.body.innerHTML = error + document.body.innerHTML;
|
||||||
|
delete window.graphiteAppInit;
|
||||||
|
} else {
|
||||||
|
const retry = () => {
|
||||||
|
if (window.graphiteAppInit) {
|
||||||
|
const init = window.graphiteAppInit;
|
||||||
|
delete window.graphiteAppInit;
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setTimeout(retry, 0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
retry();
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,43 +1,21 @@
|
||||||
|
// This file is the browser's entry point for the JS bundle
|
||||||
|
|
||||||
// reflect-metadata allows for runtime reflection of types in JavaScript.
|
// reflect-metadata allows for runtime reflection of types in JavaScript.
|
||||||
// It is needed for class-transformer to work and is imported as a side effect.
|
// It is needed for class-transformer to work and is imported as a side effect.
|
||||||
// The library replaces the Reflect API on the window to support more features.
|
// The library replaces the Reflect API on the window to support more features.
|
||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import { createApp } from "vue";
|
import { createApp } from "vue";
|
||||||
|
|
||||||
import { stripIndents } from "@/utility-functions/strip-indents";
|
|
||||||
import { initWasm } from "@/wasm-communication/editor";
|
import { initWasm } from "@/wasm-communication/editor";
|
||||||
|
|
||||||
import App from "@/App.vue";
|
import App from "@/App.vue";
|
||||||
|
|
||||||
// Browser app entry point
|
// This exported function is called in `index.html` after confirming that the browser supports all required JS standards
|
||||||
(async (): Promise<void> => {
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
// Confirm the browser is compatible before initializing the application
|
(window as any).graphiteAppInit = async (): Promise<void> => {
|
||||||
if (!checkBrowserCompatibility()) return;
|
|
||||||
|
|
||||||
// Initialize the WASM module for the editor backend
|
// Initialize the WASM module for the editor backend
|
||||||
await initWasm();
|
await initWasm();
|
||||||
|
|
||||||
// Initialize the Vue application
|
// Initialize the Vue application
|
||||||
createApp(App).mount("#app");
|
createApp(App).mount("#app");
|
||||||
})();
|
};
|
||||||
|
|
||||||
function checkBrowserCompatibility(): boolean {
|
|
||||||
if (!("BigUint64Array" in window)) {
|
|
||||||
const body = document.body;
|
|
||||||
const message = stripIndents`
|
|
||||||
<style>
|
|
||||||
h2, p, a { text-align: center; color: white; }
|
|
||||||
#app { display: none; }
|
|
||||||
</style>
|
|
||||||
<h2>This browser is too old</h2>
|
|
||||||
<p>Please upgrade to a modern web browser such as the latest Firefox, Chrome, Edge, or Safari version 15 or newer.</p>
|
|
||||||
<p>(The <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt64Array#browser_compatibility" target="_blank"><code>BigInt64Array</code></a>
|
|
||||||
JavaScript API must be supported by the browser for Graphite to function.)</p>
|
|
||||||
`;
|
|
||||||
body.innerHTML = message + body.innerHTML;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue