mirror of
https://github.com/usememos/memos.git
synced 2025-03-10 04:23:01 +08:00
fix: move initial wasm into app
This commit is contained in:
parent
79227021f5
commit
554f93eccc
3 changed files with 17 additions and 8 deletions
|
@ -18,12 +18,6 @@
|
|||
}
|
||||
</script>
|
||||
<script src="wasm_exec.js"></script>
|
||||
<script>
|
||||
const go = new Go();
|
||||
WebAssembly.instantiateStreaming(fetch("gomark.wasm"), go.importObject).then((result) => {
|
||||
go.run(result.instance);
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
|
|
@ -26,16 +26,20 @@ const App = () => {
|
|||
}, [systemStatus.host]);
|
||||
|
||||
useEffect(() => {
|
||||
const initialGoWASMExec = async () => {
|
||||
const go = new window.Go();
|
||||
const result = await WebAssembly.instantiateStreaming(fetch("/gomark.wasm"), go.importObject);
|
||||
go.run(result.instance);
|
||||
};
|
||||
const initialState = async () => {
|
||||
try {
|
||||
await userStore.fetchCurrentUser();
|
||||
} catch (error) {
|
||||
// Do nothing.
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
initialState();
|
||||
Promise.all([initialGoWASMExec(), initialState()]).then(() => setLoading(false));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
11
web/src/types/global.d.ts
vendored
11
web/src/types/global.d.ts
vendored
|
@ -1,7 +1,18 @@
|
|||
import { Node } from "./node";
|
||||
|
||||
declare class Go {
|
||||
argv: string[];
|
||||
env: { [envKey: string]: string };
|
||||
exit: (code: number) => void;
|
||||
importObject: WebAssembly.Imports;
|
||||
exited: boolean;
|
||||
mem: DataView;
|
||||
run(instance: WebAssembly.Instance): Promise<void>;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Go: typeof Go;
|
||||
parse: (content: string) => Node[];
|
||||
restore: (input: Node[]) => string;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue