expose Ignis API, implement shared ws client

This commit is contained in:
Nystik
2026-05-24 21:51:02 +02:00
parent 9eeff3c1b3
commit 28effab1ed
29 changed files with 824 additions and 745 deletions

View File

@@ -1,6 +1,8 @@
const api = require("./api");
async function renderLogViewer(containerEl, vaultId, wsListener) {
const CHANNEL = "plugin:headless-sync";
async function renderLogViewer(containerEl, vaultId) {
const details = containerEl.createEl("details", {
cls: "ignis-log-details",
});
@@ -32,19 +34,12 @@ async function renderLogViewer(containerEl, vaultId, wsListener) {
logBox.scrollTop = logBox.scrollHeight;
if (!wsListener) {
return () => {};
}
const channel = window.__ignis.ws.channel(CHANNEL);
let unsubLog = null;
details.addEventListener("toggle", () => {
if (details.open) {
wsListener.subscribeLogs(vaultId);
} else {
wsListener.unsubscribeLogs();
}
});
const onLog = (msg) => {
const payload = msg.payload || {};
const onLog = (payload) => {
if (payload.vaultId !== vaultId) {
return;
}
@@ -66,11 +61,22 @@ async function renderLogViewer(containerEl, vaultId, wsListener) {
}
};
wsListener.on("sync-log", onLog);
details.addEventListener("toggle", () => {
if (details.open) {
if (!unsubLog) {
unsubLog = channel.subscribe("sync-log", onLog);
}
} else if (unsubLog) {
unsubLog();
unsubLog = null;
}
});
return () => {
wsListener.off("sync-log", onLog);
wsListener.unsubscribeLogs();
if (unsubLog) {
unsubLog();
unsubLog = null;
}
};
}