From f7fd1d94ebe0aecbcea003ecc2130dc46ee6a7b7 Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Wed, 2 Nov 2022 18:01:38 -0700 Subject: [PATCH] Move browser incompatibility check outside the JS bundle --- frontend/public/index.html | 36 ++++++++++++++++++++++++++++++++++++ frontend/src/main.ts | 34 ++++++---------------------------- 2 files changed, 42 insertions(+), 28 deletions(-) diff --git a/frontend/public/index.html b/frontend/public/index.html index 937a49f0..c261fee3 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -21,6 +21,42 @@
+ diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 5a0e6ab0..3add6d04 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -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. // 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. import "reflect-metadata"; import { createApp } from "vue"; -import { stripIndents } from "@/utility-functions/strip-indents"; import { initWasm } from "@/wasm-communication/editor"; import App from "@/App.vue"; -// Browser app entry point -(async (): Promise => { - // Confirm the browser is compatible before initializing the application - if (!checkBrowserCompatibility()) return; - +// This exported function is called in `index.html` after confirming that the browser supports all required JS standards +// eslint-disable-next-line @typescript-eslint/no-explicit-any +(window as any).graphiteAppInit = async (): Promise => { // Initialize the WASM module for the editor backend await initWasm(); // Initialize the Vue application createApp(App).mount("#app"); -})(); - -function checkBrowserCompatibility(): boolean { - if (!("BigUint64Array" in window)) { - const body = document.body; - const message = stripIndents` - -

This browser is too old

-

Please upgrade to a modern web browser such as the latest Firefox, Chrome, Edge, or Safari version 15 or newer.

-

(The BigInt64Array - JavaScript API must be supported by the browser for Graphite to function.)

- `; - body.innerHTML = message + body.innerHTML; - - return false; - } - - return true; -} +};