generated from trashhalo/obsidian-rust-plugin
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
967 additions
and
505 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ Cargo.lock | |
.vscode-test | ||
.vscode-launch.json | ||
.vscode-tasks.json | ||
copy_to_vault.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,58 @@ | ||
import {Plugin} from "obsidian"; | ||
import { Plugin } from "obsidian"; | ||
import rustPlugin from "../pkg/obisidian_note_linker_bg.wasm"; | ||
import * as wasm from "../pkg"; | ||
import MainModal from "./ts/MainModal"; | ||
import {init_panic_hook} from "../pkg/"; | ||
import { init_panic_hook } from "../pkg/"; | ||
import * as Comlink from "comlink"; | ||
|
||
// @ts-ignore | ||
import Wcw from 'web-worker:./ts/webWorkers/WasmWorker.ts'; | ||
import Wcw from "web-worker:./ts/webWorkers/WasmWorker.ts"; | ||
import { MatchingMode } from "./ts/components/containers/MainComponent"; | ||
|
||
export default class RustPlugin extends Plugin { | ||
async onload() { | ||
// init wasm | ||
const buffer = Uint8Array.from(atob(rustPlugin as unknown as string), c => c.charCodeAt(0)) | ||
await wasm.default(Promise.resolve(buffer)); | ||
init_panic_hook() | ||
async onload() { | ||
// init wasm | ||
const buffer = Uint8Array.from(atob(rustPlugin as unknown as string), (c) => | ||
c.charCodeAt(0) | ||
); | ||
await wasm.default(Promise.resolve(buffer)); | ||
init_panic_hook(); | ||
|
||
this.addRibbonIcon('link', 'Note Linker', async () => { | ||
// init the secondary wasm thread (for searching) | ||
const wcw = new Wcw(); | ||
const WasmComlinkWorker = Comlink.wrap<typeof Wcw>(wcw) | ||
let wasmWorkerInstance: Comlink.Remote<typeof WasmComlinkWorker>; | ||
this.addRibbonIcon("link", "Note Linker", () => this.openModal()); | ||
this.addCommand({ | ||
id: "open-note-linker", | ||
name: "Open", | ||
callback: this.openModal, | ||
}); | ||
this.addCommand({ | ||
id: "open-note-linker-vault", | ||
name: "Scan Vault", | ||
callback: () => this.openModal(MatchingMode.Vault), | ||
}); | ||
this.addCommand({ | ||
id: "open-note-linker-note", | ||
name: "Scan Note", | ||
callback: () => this.openModal(MatchingMode.Note), | ||
}); | ||
} | ||
|
||
wasmWorkerInstance = await new WasmComlinkWorker(); | ||
await wasmWorkerInstance.init(); | ||
openModal = async (_matchingModal?: MatchingMode) => { | ||
// init the secondary wasm thread (for searching) | ||
const wcw = new Wcw(); | ||
const WasmComlinkWorker = Comlink.wrap<typeof Wcw>(wcw); | ||
let wasmWorkerInstance: Comlink.Remote<typeof WasmComlinkWorker>; | ||
|
||
const linkMatchSelectionModal = new MainModal(app, wasmWorkerInstance, () => { | ||
wcw.terminate(); | ||
}); | ||
linkMatchSelectionModal.open(); | ||
}); | ||
} | ||
wasmWorkerInstance = await new WasmComlinkWorker(); | ||
await wasmWorkerInstance.init(); | ||
|
||
} | ||
const linkMatchSelectionModal = new MainModal( | ||
app, | ||
wasmWorkerInstance, | ||
() => { | ||
wcw.terminate(); | ||
}, | ||
_matchingModal | ||
); | ||
linkMatchSelectionModal.open(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.