Skip to content

Commit

Permalink
fix: wasm not loading in webkit
Browse files Browse the repository at this point in the history
  • Loading branch information
ZanzyTHEbar committed May 11, 2023
1 parent c44983f commit 0e74582
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "LICENSE"
repository = "https://github.com/xibyte/jsketcher"
default-run = "app"
edition = "2021"
rust-version = "1.64"
rust-version = "1.69"

[build-dependencies.tauri-build]
version = "1.3.0"
Expand Down
41 changes: 18 additions & 23 deletions web/app/cad/craft/e0/occtBundle.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import {GenericWASMEngine_V1} from "engine/impl/wasm/GenericWASMEngine_V1";
import {CraftEngine} from "./craftEngine";
import {createOCCService, OCCService} from "cad/craft/e0/occService";
import { GenericWASMEngine_V1 } from "engine/impl/wasm/GenericWASMEngine_V1";
import { CraftEngine } from "./craftEngine";
import { createOCCService, OCCService } from "cad/craft/e0/occService";

export interface OCCBundleContext {

craftEngine: CraftEngine; // to be removed

occService: OCCService;
}

export function activate(ctx) {

loadWasm(ctx);

const wasmEngine = new GenericWASMEngine_V1();
Expand All @@ -22,42 +20,39 @@ export function activate(ctx) {
ctx.occService = createOCCService(ctx);
}

function instantiateEngine(importObject, callback) {
const url = './lib-assets/jsketcher-occ-engine/occt.wasm';
//* work around until tauri v2
async function instantiateEngine(importObject, callback) {
const url = "./lib-assets/jsketcher-occ-engine/occt.wasm";

const response = await fetch(url);
const buffer = await response.arrayBuffer();

WebAssembly.instantiateStreaming(fetch(url), importObject).then(results => {
callback(results.instance);
});
const obj = await WebAssembly.instantiate(buffer, importObject);
callback(obj.instance);
}

function loadWasm(ctx) {
ctx.services.lifecycle.startAsyncInitializingJob('e0:loader');
ctx.services.lifecycle.startAsyncInitializingJob("e0:loader");

// @ts-ignore
window.Module = {
// locateFile: function(file) {
// return SERVER_PATH + file;
// },
onRuntimeInitialized: function() {
onRuntimeInitialized: function () {
Module._InitCommands();
ctx.services.lifecycle.finishAsyncInitializingJob('e0:loader');
ctx.services.lifecycle.finishAsyncInitializingJob("e0:loader");
},
instantiateWasm: function (importObject, fncReceiveInstance) {
instantiateEngine(importObject, fncReceiveInstance);
return {};
}
},
} as any;

const mainScript = document.createElement('script');
mainScript.setAttribute('src', './lib-assets/jsketcher-occ-engine/occt.js');
mainScript.setAttribute('async', 'async');
const mainScript = document.createElement("script");
mainScript.setAttribute("src", "./lib-assets/jsketcher-occ-engine/occt.js");
mainScript.setAttribute("async", "async");
document.head.appendChild(mainScript);
}

export const BundleName = "@OCCT";






0 comments on commit 0e74582

Please sign in to comment.