omega restructuring + a bunch of changes i have made over the last weeks
This commit is contained in:
23
apps/obsidian-plugin/deno.json
Normal file
23
apps/obsidian-plugin/deno.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "@ppc/obsidian-plugin",
|
||||
"tasks": {
|
||||
"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": ""
|
||||
},
|
||||
"imports": {
|
||||
"@deno/esbuild-plugin": "jsr:@deno/esbuild-plugin@^1.2.1",
|
||||
"@flowershow/remark-wiki-link": "npm:@flowershow/remark-wiki-link@^3.4.0",
|
||||
"builtin-modules": "npm:builtin-modules@^5.0.0",
|
||||
"esbuild": "npm:esbuild@^0.27.3",
|
||||
"mdast": "npm:mdast@^3.0.0",
|
||||
"obsidian": "npm:obsidian@^1.12.2",
|
||||
"remark-frontmatter": "npm:remark-frontmatter@^5.0.0",
|
||||
"remark-gfm": "npm:remark-gfm@^4.0.1",
|
||||
"remark-parse": "npm:remark-parse@^11.0.0",
|
||||
"remark-stringify": "npm:remark-stringify@^11.0.0",
|
||||
"typescript": "npm:typescript@^5.9.3",
|
||||
"unified": "npm:unified@^11.0.5",
|
||||
"unist-util-visit": "npm:unist-util-visit@^5.1.0"
|
||||
}
|
||||
}
|
||||
1340
apps/obsidian-plugin/deno.lock
generated
Normal file
1340
apps/obsidian-plugin/deno.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
56
apps/obsidian-plugin/esbuild.config.mjs
Normal file
56
apps/obsidian-plugin/esbuild.config.mjs
Normal file
@@ -0,0 +1,56 @@
|
||||
import esbuild from "esbuild";
|
||||
import process from "node:process";
|
||||
import builtins from "builtin-modules";
|
||||
import { denoPlugin } from "@deno/esbuild-plugin";
|
||||
|
||||
const banner = `/*
|
||||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||||
*/
|
||||
`;
|
||||
|
||||
const prod = process.argv[2] === "production";
|
||||
|
||||
const context = await esbuild.context({
|
||||
banner: {
|
||||
js: banner,
|
||||
},
|
||||
entryPoints: ["plugin.ts"],
|
||||
bundle: true,
|
||||
external: [
|
||||
"obsidian",
|
||||
"electron",
|
||||
"@codemirror/autocomplete",
|
||||
"@codemirror/collab",
|
||||
"@codemirror/commands",
|
||||
"@codemirror/language",
|
||||
"@codemirror/lint",
|
||||
"@codemirror/search",
|
||||
"@codemirror/state",
|
||||
"@codemirror/view",
|
||||
"@lezer/common",
|
||||
"@lezer/highlight",
|
||||
"@lezer/lr",
|
||||
...builtins,
|
||||
],
|
||||
format: "cjs",
|
||||
target: "es2020",
|
||||
logLevel: "info",
|
||||
sourcemap: prod ? false : "inline",
|
||||
treeShaking: true,
|
||||
outfile: "dist/main.js",
|
||||
loader: {
|
||||
".wasm": "binary",
|
||||
".workerjs": "text",
|
||||
},
|
||||
define: {
|
||||
"import.meta.url": '"obsidian-plugin"',
|
||||
},
|
||||
plugins: [denoPlugin()],
|
||||
});
|
||||
|
||||
if (prod) {
|
||||
await context.rebuild();
|
||||
process.exit(0);
|
||||
} else {
|
||||
await context.watch();
|
||||
}
|
||||
10
apps/obsidian-plugin/manifest.json
Normal file
10
apps/obsidian-plugin/manifest.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"id": "mize",
|
||||
"name": "Mize",
|
||||
"version": "0.1.0",
|
||||
"minAppVersion": "1.5.0",
|
||||
"main": "main.js",
|
||||
"author": "c2vi",
|
||||
"isDesktopOnly": true,
|
||||
"description": "Turns Obsidian into a full Mize Explorer"
|
||||
}
|
||||
61
apps/obsidian-plugin/mod.rs
Normal file
61
apps/obsidian-plugin/mod.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use dioxus::prelude::*;
|
||||
use marts::ClientAuth;
|
||||
use mize::Mize;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use mize::{MizeResult, mize_part, MizePart, MizePartCreate, error::IntoMizeResultJsValue};
|
||||
use mize::platform::js::JsMize;
|
||||
|
||||
|
||||
// console_log macro
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
#[wasm_bindgen(js_namespace = console)]
|
||||
fn log(s: &str);
|
||||
}
|
||||
|
||||
macro_rules! console_log {
|
||||
// Note that this is using the `log` function imported above during
|
||||
// `bare_bones`
|
||||
($($t:tt)*) => ({ log(&format_args!($($t)*).to_string())})
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test_fn(mize: &mut JsMize) {
|
||||
let mize = mize.inner();
|
||||
console_log!("test fn...");
|
||||
|
||||
if let Err(e) = try_test_fn(mize) {
|
||||
console_log!("err: {:?}", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn try_test_fn(mize: &mut Mize) -> MizeResult<()> {
|
||||
//let auth = mize.get_part_native::<ClientAuth>("client_auth")?;
|
||||
//console_log!("secrets: {:?}", auth.secrets());
|
||||
|
||||
let parts = mize.parts.lock().unwrap();
|
||||
for part in parts.keys() {
|
||||
console_log!("part: {}", part)
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn part_obsidian_init(mize: &mut JsMize, plugin: JsValue, app: JsValue) {
|
||||
let mut mize = mize.inner();
|
||||
if let Err(e) = obsidian_mize_main(&mut mize, plugin, app) {
|
||||
console_log!("Failed to start the obsidian mize part: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn obsidian_mize_main(mize: &mut Mize, plugin: JsValue, app: JsValue) -> MizeResult<()> {
|
||||
|
||||
marts::part_obsidian(mize, plugin, app)?;
|
||||
marts::part_client_auth(mize)?;
|
||||
marts::spacetime(mize)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
173
apps/obsidian-plugin/plugin.ts
Normal file
173
apps/obsidian-plugin/plugin.ts
Normal file
@@ -0,0 +1,173 @@
|
||||
import { Plugin, ItemView, TFile, Modal } 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";
|
||||
import { task_obsidian_otask_parse } from "@ppc/marts";
|
||||
|
||||
class Mize {
|
||||
jsInstance: wasmNamespace.JsMize;
|
||||
jsInstancePtr: number;
|
||||
wasmModule: any;
|
||||
|
||||
constructor(wasmModule: any, jsInstance: wasmNamespace.JsMize) {
|
||||
this.jsInstance = jsInstance
|
||||
this.jsInstancePtr = jsInstance.__wbg_ptr;
|
||||
this.wasmModule = wasmModule
|
||||
}
|
||||
|
||||
test() {
|
||||
this.wasmModule.test_fn(this.jsInstance);
|
||||
}
|
||||
|
||||
get_part_native(name: string) {
|
||||
if (name == "obsidian") {
|
||||
return this.obsidianPlugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function mize_init() {
|
||||
|
||||
// init the wasm_bindgen module
|
||||
const wasmModule = await import("./rust_dist/ppc.js");
|
||||
await wasmModule.default({ module_or_path: wasmBinary });
|
||||
wasmModule.initSync();
|
||||
const jsInstance = await wasmModule.new_js_instance(JSON.stringify({
|
||||
auth: {
|
||||
client: {
|
||||
issuer: "https://auth.ppc.social",
|
||||
client_id: "363768685120258051",
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
jsInstance.init();
|
||||
console.log("jsInstance: ", jsInstance)
|
||||
|
||||
let mize = new Mize(wasmModule, jsInstance);
|
||||
|
||||
console.log("jsInstance: ", jsInstance)
|
||||
console.log("mize.jsInstance: ", mize.jsInstance)
|
||||
|
||||
// set global mize
|
||||
window.mize = mize;
|
||||
console.log("window.mize.jsInstance: ", window.mize.jsInstance)
|
||||
|
||||
return mize;
|
||||
}
|
||||
|
||||
export default class MizeObsidianPlugin extends Plugin {
|
||||
async onload() {
|
||||
|
||||
let mize = await mize_init();
|
||||
console.log("mize.jsInstance: ", mize.jsInstance)
|
||||
mize.wasmModule.part_obsidian_init(mize.jsInstance, this, this.app);
|
||||
console.log("mize.jsInstance: ", mize.jsInstance)
|
||||
mize.obsidianPlugin = this;
|
||||
console.log("mize.jsInstance: ", mize.jsInstance)
|
||||
|
||||
// c2vi part which patches canvas movement
|
||||
c2vi_obsidian_canvas_patch(mize);
|
||||
|
||||
task_obsidian_otask_parse(mize);
|
||||
|
||||
this.registerView("test-view", (leaf) => new TestView(leaf, this));
|
||||
|
||||
this.addCommand({
|
||||
id: "mize-test-view",
|
||||
name: "Mize TestView",
|
||||
callback: async () => {
|
||||
const leaf = this.app.workspace.getLeaf(true);
|
||||
await leaf.setViewState({
|
||||
type: "test-view",
|
||||
active: true,
|
||||
});
|
||||
this.app.workspace.revealLeaf(leaf);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onunload() {
|
||||
this.app.workspace.detachLeavesOfType("ppc-app-view");
|
||||
}
|
||||
|
||||
showDeviceCode(code: string, verificationUri: string) {
|
||||
const modal = new Modal(this.app);
|
||||
|
||||
modal.onOpen = () => {
|
||||
const { contentEl } = modal;
|
||||
|
||||
contentEl.createEl("h2", { text: "Device Login" });
|
||||
|
||||
// URL
|
||||
contentEl.createEl("p", {
|
||||
text: "Open this URL:"
|
||||
});
|
||||
|
||||
const urlContainer = contentEl.createDiv({
|
||||
cls: "device-login-row"
|
||||
});
|
||||
|
||||
const urlInput = urlContainer.createEl("input", {
|
||||
type: "text",
|
||||
value: verificationUri,
|
||||
});
|
||||
|
||||
urlInput.readOnly = true;
|
||||
urlInput.style.width = "100%";
|
||||
|
||||
urlContainer.createEl("button", {
|
||||
text: "Copy"
|
||||
}).onclick = async () => {
|
||||
await navigator.clipboard.writeText(verificationUri);
|
||||
new Notice("URL copied to clipboard");
|
||||
};
|
||||
|
||||
// Code
|
||||
contentEl.createEl("p", {
|
||||
text: "Enter this code:"
|
||||
});
|
||||
|
||||
const codeInput = contentEl.createEl("input", {
|
||||
type: "text",
|
||||
value: code,
|
||||
});
|
||||
|
||||
codeInput.readOnly = true;
|
||||
codeInput.style.width = "100%";
|
||||
codeInput.select();
|
||||
};
|
||||
|
||||
modal.open();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export class TestView 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.wasmModule.show_main_ui();
|
||||
}
|
||||
|
||||
override async onClose() {
|
||||
this.root.remove();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user