...
This commit is contained in:
23
packages/ppc/platform/obsidian/deno.json
Normal file
23
packages/ppc/platform/obsidian/deno.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"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": "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
packages/ppc/platform/obsidian/deno.lock
generated
Normal file
1340
packages/ppc/platform/obsidian/deno.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
56
packages/ppc/platform/obsidian/esbuild.config.mjs
Normal file
56
packages/ppc/platform/obsidian/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();
|
||||
}
|
||||
8
packages/ppc/platform/obsidian/main.ts
Normal file
8
packages/ppc/platform/obsidian/main.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export function add(a: number, b: number): number {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// Learn more at https://docs.deno.com/runtime/manual/examples/module_metadata#concepts
|
||||
if (import.meta.main) {
|
||||
console.log("Add 2 + 3 =", add(2, 3));
|
||||
}
|
||||
6
packages/ppc/platform/obsidian/main_test.ts
Normal file
6
packages/ppc/platform/obsidian/main_test.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { assertEquals } from "@std/assert";
|
||||
import { add } from "./main.ts";
|
||||
|
||||
Deno.test(function addTest() {
|
||||
assertEquals(add(2, 3), 5);
|
||||
});
|
||||
10
packages/ppc/platform/obsidian/manifest.json
Normal file
10
packages/ppc/platform/obsidian/manifest.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"id": "ppc",
|
||||
"name": "PPC Obsidian Plugin",
|
||||
"version": "0.1.0",
|
||||
"minAppVersion": "1.5.0",
|
||||
"main": "main.js",
|
||||
"author": "ppc",
|
||||
"isDesktopOnly": true,
|
||||
"description": "Turns Obsidian into a full on PPC client"
|
||||
}
|
||||
23
packages/ppc/platform/obsidian/mod.rs
Normal file
23
packages/ppc/platform/obsidian/mod.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use mize::Mize;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
// 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 obsidian_mize_entrypoint() {
|
||||
console_log!("hiiiiiiiiiiiii from rust");
|
||||
let mize = Mize::new();
|
||||
console_log!("Obsidian Mize initialized");
|
||||
}
|
||||
40
packages/ppc/platform/obsidian/plugin.ts
Normal file
40
packages/ppc/platform/obsidian/plugin.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { Plugin, 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";
|
||||
import { task_obsidian_otask_parse } from "@ppc/marts";
|
||||
|
||||
export default class PPCObsidianPlugin extends Plugin {
|
||||
async onload() {
|
||||
// init mize from wasm
|
||||
const wasmModule = await import("./rust_dist/ppc.js");
|
||||
await wasmModule.default({ module_or_path: wasmBinary });
|
||||
wasmModule.initSync();
|
||||
wasmModule.obsidian_mize_entrypoint();
|
||||
|
||||
const mize = {};
|
||||
mize.get_part_native = (name) => this;
|
||||
|
||||
// c2vi part which patches canvas movement
|
||||
c2vi_obsidian_canvas_patch(mize);
|
||||
|
||||
task_obsidian_otask_parse(mize);
|
||||
|
||||
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",
|
||||
active: true,
|
||||
});
|
||||
this.app.workspace.revealLeaf(leaf);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
onunload() {
|
||||
this.app.workspace.detachLeavesOfType("ppc-app");
|
||||
}
|
||||
}
|
||||
35
packages/ppc/platform/os/main.rs
Normal file
35
packages/ppc/platform/os/main.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use clap::Command;
|
||||
use clap::crate_version;
|
||||
use mize::{Mize, MizeResult};
|
||||
|
||||
fn main() {
|
||||
let mut mize = Mize::new().expect("failed to create mize instance");
|
||||
|
||||
#[cfg(feature = "target-os")]
|
||||
os_main(&mut mize);
|
||||
|
||||
mize.run();
|
||||
}
|
||||
|
||||
#[cfg(feature = "target-os")]
|
||||
fn os_main(mize: &mut Mize) -> MizeResult<()> {
|
||||
marts::cli(mize)?;
|
||||
|
||||
let mut cli = mize.get_part_native::<marts::CliPart>("cli")?;
|
||||
|
||||
cli.with_cmd(|_, cmd| {
|
||||
Ok(cmd
|
||||
.version(crate_version!())
|
||||
.name("ppc")
|
||||
.author("ppc")
|
||||
.about("the ppc desktop program"))
|
||||
})?;
|
||||
|
||||
cli.subcommand(Command::new("test"), |_| {
|
||||
println!("test ppc...");
|
||||
Ok(())
|
||||
});
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user