dioxus hello world component in obsidian + some other stuff

This commit is contained in:
Sebastian Moser
2026-03-14 17:58:53 +01:00
parent f1f53e3857
commit 299f00c94f
25 changed files with 1617 additions and 136 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "@ppc/obsidian-plugin",
"tasks": {
"build_rust": "wasm-pack -vvvvv build -d src/platform/obsidian/rust_dist --target web --no-default-features --features target-obsidian",
"build_rust": "wasm-pack -vvvvv build -d platform/obsidian/rust_dist --target web --no-default-features --features target-obsidian",
"build": "deno run -A build_rust && mkdir -p dist && touch dist/.hotreload && cp manifest.json dist && deno -A esbuild.config.mjs production",
"dev": ""
},

View File

@@ -1,3 +1,4 @@
use dioxus::prelude::*;
use mize::Mize;
use wasm_bindgen::prelude::*;
@@ -17,7 +18,27 @@ macro_rules! console_log {
#[wasm_bindgen]
pub fn obsidian_mize_entrypoint() {
console_log!("hiiiiiiiiiiiii from rust");
let mize = Mize::new();
//crate::client_auth(mize)?;
console_log!("Obsidian Mize initialized");
}
#[wasm_bindgen]
pub fn show_main_ui() {
let document = web_sys::window()
.expect("global window not available")
.document()
.expect("no document in the global window obj");
let root = document.get_element_by_id("ppc-app-root").unwrap();
dioxus_web::launch::launch(
app,
Vec::new(),
vec![Box::new(dioxus_web::Config::new().rootelement(root))],
);
}
fn app() -> Element {
rsx! {
div { "Hello, from dioxus!" }
}
}

View File

@@ -1,4 +1,4 @@
import { Plugin, TFile } from "obsidian";
import { Plugin, ItemView, TFile } from "obsidian";
import wasmBinary from "./rust_dist/ppc_bg.wasm";
import * as wasmNamespace from "./rust_dist/ppc";
import { c2vi_obsidian_canvas_patch } from "@ppc/marts";
@@ -10,23 +10,29 @@ export default class PPCObsidianPlugin extends Plugin {
const wasmModule = await import("./rust_dist/ppc.js");
await wasmModule.default({ module_or_path: wasmBinary });
wasmModule.initSync();
wasmModule.obsidian_mize_entrypoint();
console.log("module: ", wasmModule);
const mize = {};
mize.get_part_native = (name) => this;
// mize filler.... till there is a more proper js lib implemented
this.mize = { parts: { obsidian: this }, misc_stuff: { wasmModule } };
window.mize = this.mize;
mize.get_part_native = (name) => mize.parts[name];
wasmModule.obsidian_mize_entrypoint();
// c2vi part which patches canvas movement
c2vi_obsidian_canvas_patch(mize);
task_obsidian_otask_parse(mize);
this.registerView("ppc-app-view", (leaf) => new PPCAppView(leaf, this));
this.addCommand({
id: "app",
name: "Open ppc app main page",
callback: async () => {
const leaf = this.app.workspace.getLeaf(true);
await leaf.setViewState({
type: "ppc-app",
type: "ppc-app-view",
active: true,
});
this.app.workspace.revealLeaf(leaf);
@@ -35,6 +41,33 @@ export default class PPCObsidianPlugin extends Plugin {
}
onunload() {
this.app.workspace.detachLeavesOfType("ppc-app");
this.app.workspace.detachLeavesOfType("ppc-app-view");
}
}
export class PPCAppView extends ItemView {
constructor(leaf: WorkspaceLeaf, plugin: PPCObsidianPlugin) {
super(leaf);
this.plugin = plugin;
}
getViewType(): string {
return "ppc-app-view";
}
getDisplayText(): string {
return "PPC App";
}
override async onOpen() {
this.root = document.createElement("div");
this.root.id = "ppc-app-root";
this.containerEl.children[1].appendChild(this.root);
this.plugin.mize.misc_stuff.wasmModule.show_main_ui();
}
override async onClose() {
this.root.remove();
}
}