mirror of
https://github.com/Nystik-gh/ignis.git
synced 2026-06-17 04:35:53 +00:00
load bundled plugins via virtual-plugin loader
This commit is contained in:
@@ -232,6 +232,7 @@ export function initialize() {
|
||||
autoTrustDemoVaults(bootstrap.vaultList);
|
||||
applyTree(bootstrap.tree);
|
||||
applyCoreSyncGuard(bootstrap.plugins);
|
||||
window.__ignisVirtualPlugins = bootstrap.virtualPlugins || [];
|
||||
|
||||
// Race the indexer: batch-fetch text content into ContentCache so
|
||||
// Obsidian's startup indexing reads hit the cache instead of the network.
|
||||
|
||||
@@ -4,7 +4,10 @@ import { installCssOverrides } from "./css-overrides.js";
|
||||
import { initialize } from "./init.js";
|
||||
import { fsShim } from "./fs/index.js";
|
||||
import { registerUI } from "./ui-registry.js";
|
||||
import { extractObsidianModule } from "./virtual-plugin-loader.js";
|
||||
import {
|
||||
extractObsidianModule,
|
||||
loadVirtualPlugin,
|
||||
} from "./virtual-plugin-loader.js";
|
||||
|
||||
// __IGNIS_VERSION__ is replaced at build time from package.json.
|
||||
window.__ignis = { version: __IGNIS_VERSION__ };
|
||||
@@ -48,6 +51,15 @@ extractObsidianModule()
|
||||
const bridge = new IgnisBridgePlugin(window.app, BRIDGE_MANIFEST);
|
||||
await bridge.onload();
|
||||
console.log("[ignis] bridge loaded");
|
||||
|
||||
for (const vp of window.__ignisVirtualPlugins || []) {
|
||||
try {
|
||||
await loadVirtualPlugin(vp);
|
||||
console.log(`[ignis] virtual plugin loaded: ${vp.id}`);
|
||||
} catch (e) {
|
||||
console.error(`[ignis] virtual plugin load failed: ${vp.id}`, e);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((e) => console.error("[ignis] bridge load failed:", e));
|
||||
|
||||
|
||||
@@ -103,3 +103,42 @@ export async function extractObsidianModule() {
|
||||
console.log("[ignis] obsidian module captured");
|
||||
return captured;
|
||||
}
|
||||
|
||||
export async function loadVirtualPlugin(entry) {
|
||||
if (entry.cssUrl) {
|
||||
const link = document.createElement("link");
|
||||
link.rel = "stylesheet";
|
||||
link.href = entry.cssUrl;
|
||||
link.setAttribute("data-ignis-virtual-plugin", entry.id);
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
|
||||
const res = await fetch(entry.scriptUrl);
|
||||
|
||||
if (!res.ok) {
|
||||
throw new Error(
|
||||
`fetch ${entry.scriptUrl} -> ${res.status} ${res.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
const src =
|
||||
(await res.text()) + `\n//# sourceURL=ignis-virtual/${entry.id}.js`;
|
||||
|
||||
const module = { exports: {} };
|
||||
const localRequire = (name) =>
|
||||
name === "obsidian" ? window.__obsidian : window.require(name);
|
||||
|
||||
new Function("module", "exports", "require", src)(
|
||||
module,
|
||||
module.exports,
|
||||
localRequire,
|
||||
);
|
||||
|
||||
const PluginClass = module.exports.default || module.exports;
|
||||
const instance = new PluginClass(window.app, entry.manifest);
|
||||
|
||||
await instance.onload();
|
||||
|
||||
window.__ignis.plugins = window.__ignis.plugins || {};
|
||||
window.__ignis.plugins[entry.id] = { instance, manifest: entry.manifest };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user