From 2d5209da71a4960f07d31c4cb6f45f4fde0769e0 Mon Sep 17 00:00:00 2001 From: Samuel Date: Thu, 23 Jan 2025 17:02:02 +0100 Subject: [PATCH] feat: show error if wasm is not supported --- src/index.tsx | 21 ++++++++++++++++++--- src/lib/utils.ts | 12 ++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index 8033a8e..a379b4c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,13 +1,14 @@ /* @refresh reload */ import { MetaProvider } from "@solidjs/meta"; import { Router, useNavigate } from "@solidjs/router"; -import { render } from "solid-js/web"; +import { Portal, render } from "solid-js/web"; import App from "./App"; import { hasCashedData } from "./lib/db-cache"; import { createEffect, Show } from "solid-js"; import { dbLoaded } from "./db"; import { Callout, CalloutContent, CalloutTitle } from "./components/ui/callout"; import { A } from "./components/ui/A"; +import { isWasmSupported } from "./lib/utils"; const root = document.getElementById("root"); @@ -34,13 +35,27 @@ if (root) { } }); + const wasmSupport = isWasmSupported(); + return ( <> + + +
+ + Your browser does not support WebAssembly, which is required for this site to work with the + big amount of data a signal backup contains. +
+ Please try a different browser. +
+
+
+
- + There is currently no backup database loaded, but you can watch statistics that have been cached, meaning only chats you already opened or chats that were preloaded.
@@ -56,7 +71,7 @@ if (root) {
} > - + You are watching cached statistics Currently there is no backup database loaded. You can only watch statistics that have been diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 365058c..7c60284 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -4,3 +4,15 @@ import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } + +export function isWasmSupported(): boolean { + try { + if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") { + const module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00)); + if (module instanceof WebAssembly.Module) return new WebAssembly.Instance(module) instanceof WebAssembly.Instance; + } + // biome-ignore lint/suspicious/noEmptyBlockStatements: + } catch (_error) {} + + return false; +}