Skip to content

Commit 5ecb032

Browse files
committed
Add initialiseWasm
1 parent 2ac099b commit 5ecb032

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
},
3737
"scripts": {
3838
"start": "vite",
39+
"build:wasm:dev": "(cd src/wasm-lib && wasm-pack build --dev --target web --out-dir pkg) && cp src/wasm-lib/pkg/wasm_lib_bg.wasm public",
40+
"build:wasm": "(cd src/wasm-lib && wasm-pack build --target web --out-dir pkg) && cp src/wasm-lib/pkg/wasm_lib_bg.wasm public",
3941
"build": "vite build",
4042
"test": "vitest",
4143
"e2e": "yarn build && yarn playwright test",

src/chrome/background.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
setStorageKittycadToken,
1919
} from './storage'
2020
import { getFileBlob, getFileDiff } from './diff'
21+
import init from '../wasm-lib/pkg/wasm_lib'
2122

2223
let github: Octokit | undefined
2324
let kittycad: Client | undefined
@@ -59,11 +60,24 @@ async function saveKittycadTokenAndReload(token: string): Promise<void> {
5960
await initKittycadApi()
6061
}
6162

62-
;(async () => {
63+
async function initialiseWasm() {
64+
try {
65+
const fullUrl = '/wasm_lib_bg.wasm'
66+
const input = await fetch(fullUrl)
67+
const buffer = await input.arrayBuffer()
68+
return await init(buffer)
69+
} catch (e) {
70+
console.log('Error initialising WASM', e)
71+
throw e
72+
}
73+
}
74+
75+
; (async () => {
6376
// Delay to allow for external storage sets before auth, like in e2e
6477
await new Promise(resolve => setTimeout(resolve, 1000))
6578
await initKittycadApi()
6679
await initGithubApi()
80+
await initialiseWasm()
6781
})()
6882

6983
const noClientError = new Error('API client is undefined')

0 commit comments

Comments
 (0)