implement ui-registry for dynamic UI handler registration

This commit is contained in:
Nystik 2026-05-19 01:39:29 +02:00
parent 64073968d4
commit 4da91d017b
9 changed files with 54 additions and 10 deletions

View file

@ -41,8 +41,8 @@
<div id="ignis-status-label">Loading Obsidian...</div> <div id="ignis-status-label">Loading Obsidian...</div>
</div> </div>
<!-- Ignis shims: must run before any Obsidian code. --> <!-- Ignis shims: must run before any Obsidian code. -->
<script type="text/javascript" src="__IGNIS_UI_SRC__"></script>
<script type="text/javascript" src="__SHIM_LOADER_SRC__"></script> <script type="text/javascript" src="__SHIM_LOADER_SRC__"></script>
<script type="text/javascript" src="__IGNIS_UI_SRC__"></script>
<!-- Obsidian scripts injected dynamically to avoid touching their files. --> <!-- Obsidian scripts injected dynamically to avoid touching their files. -->
<script> <script>
(function () { (function () {

View file

@ -1,4 +1,4 @@
import { showVaultManager } from "../../ui/bootstrap.js"; import { showVaultManager } from "../ui-registry.js";
import { vaultService } from "../../services/vault-service.js"; import { vaultService } from "../../services/vault-service.js";
const listeners = new Map(); const listeners = new Map();

View file

@ -2,7 +2,7 @@ import {
showMessageDialog, showMessageDialog,
showConfirmDialog, showConfirmDialog,
showPromptDialog, showPromptDialog,
} from "../../../ui/bootstrap.js"; } from "../../ui-registry.js";
import { inputCacheSet, inputCacheDelete } from "../../fs/input-cache.js"; import { inputCacheSet, inputCacheDelete } from "../../fs/input-cache.js";
const IMPORTS_DIR = ".obsidian/imports"; const IMPORTS_DIR = ".obsidian/imports";

View file

@ -3,7 +3,7 @@ import {
registerPopupWindow, registerPopupWindow,
unregisterPopupWindow, unregisterPopupWindow,
} from "./electron/remote/window.js"; } from "./electron/remote/window.js";
import { showVaultManager } from "../ui/bootstrap.js"; import { showVaultManager } from "./ui-registry.js";
function installProcess() { function installProcess() {
window.process = processShim; window.process = processShim;

View file

@ -1,7 +1,7 @@
import { fsShim } from "./fs/index.js"; import { fsShim } from "./fs/index.js";
import { installRequestUrlShim } from "./request-url.js"; import { installRequestUrlShim } from "./request-url.js";
import { vaultService } from "../services/vault-service.js"; import { vaultService } from "../services/vault-service.js";
import { showPluginInstallDialog } from "../ui/bootstrap.js"; import { showPluginInstallDialog } from "./ui-registry.js";
import { registerReadTransform } from "./fs/transforms.js"; import { registerReadTransform } from "./fs/transforms.js";
import { import {
resolveWorkspaceName, resolveWorkspaceName,

View file

@ -3,9 +3,11 @@ import { installGlobals } from "./globals.js";
import { installCssOverrides } from "./css-overrides.js"; import { installCssOverrides } from "./css-overrides.js";
import { initialize } from "./init.js"; import { initialize } from "./init.js";
import { fsShim } from "./fs/index.js"; import { fsShim } from "./fs/index.js";
import { registerUI } from "./ui-registry.js";
// __IGNIS_VERSION__ is replaced at build time from package.json. // __IGNIS_VERSION__ is replaced at build time from package.json.
window.__ignis = { version: __IGNIS_VERSION__ }; window.__ignis = { version: __IGNIS_VERSION__ };
window.__ignis_registerUI = registerUI;
installGlobals(); // process, Buffer, window overrides (before require so Buffer is available) installGlobals(); // process, Buffer, window overrides (before require so Buffer is available)
installRequire(); // shim registry, window.require installRequire(); // shim registry, window.require

26
src/shims/ui-registry.js Normal file
View file

@ -0,0 +1,26 @@
// Use a runtime registry to avoid bloating bundles with imported component code.
let handlers = {};
export function registerUI(impls) {
handlers = { ...handlers, ...impls };
}
function proxy(name) {
return (...args) => {
const fn = handlers[name];
if (typeof fn !== "function") {
console.warn(`[ignis] UI handler '${name}' not registered`);
return undefined;
}
return fn(...args);
};
}
export const showVaultManager = proxy("showVaultManager");
export const showMessageDialog = proxy("showMessageDialog");
export const showConfirmDialog = proxy("showConfirmDialog");
export const showPluginInstallDialog = proxy("showPluginInstallDialog");
export const showPromptDialog = proxy("showPromptDialog");

24
src/ui/bootstrap.js vendored
View file

@ -1,6 +1,6 @@
import { vaultService } from "../services/vault-service.js"; import { vaultService } from "../services/vault-service.js";
export function showVaultManager() { function showVaultManager() {
if (document.querySelector(".vault-manager-overlay")) return; if (document.querySelector(".vault-manager-overlay")) return;
new window.IgnisUI.VaultManager({ new window.IgnisUI.VaultManager({
@ -9,7 +9,7 @@ export function showVaultManager() {
}); });
} }
export function showMessageDialog(title, message) { function showMessageDialog(title, message) {
return new Promise((resolve) => { return new Promise((resolve) => {
const dialog = new window.IgnisUI.MessageDialog({ const dialog = new window.IgnisUI.MessageDialog({
target: document.body, target: document.body,
@ -23,7 +23,7 @@ export function showMessageDialog(title, message) {
}); });
} }
export function showConfirmDialog( function showConfirmDialog(
title, title,
message, message,
description, description,
@ -47,7 +47,7 @@ export function showConfirmDialog(
}); });
} }
export function showPluginInstallDialog(vaultId) { function showPluginInstallDialog(vaultId) {
return new Promise((resolve) => { return new Promise((resolve) => {
const dialog = new window.IgnisUI.PluginInstallDialog({ const dialog = new window.IgnisUI.PluginInstallDialog({
target: document.body, target: document.body,
@ -83,7 +83,7 @@ export function showPluginInstallDialog(vaultId) {
}); });
} }
export function showPromptDialog( function showPromptDialog(
title, title,
label, label,
placeholder = "", placeholder = "",
@ -107,3 +107,17 @@ export function showPromptDialog(
}); });
}); });
} }
if (typeof window !== "undefined" && window.__ignis_registerUI) {
window.__ignis_registerUI({
showVaultManager,
showMessageDialog,
showConfirmDialog,
showPluginInstallDialog,
showPromptDialog,
});
} else if (typeof window !== "undefined") {
console.warn(
"[ignis] __ignis_registerUI not available; UI handlers not registered",
);
}

View file

@ -1,3 +1,5 @@
import "./bootstrap.js";
export { default as VaultManager } from "./views/VaultManager.svelte"; export { default as VaultManager } from "./views/VaultManager.svelte";
export { default as MessageDialog } from "./components/layout/MessageDialog.svelte"; export { default as MessageDialog } from "./components/layout/MessageDialog.svelte";
export { default as ConfirmDialog } from "./components/layout/ConfirmDialog.svelte"; export { default as ConfirmDialog } from "./components/layout/ConfirmDialog.svelte";