From edaad57418dc6074db74cd9cebd02bc44898bf66 Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:03:12 +0800 Subject: [PATCH] fix: relation section init bug --- src/modules/workspace/relation.ts | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/modules/workspace/relation.ts b/src/modules/workspace/relation.ts index f90bce8..786c17f 100644 --- a/src/modules/workspace/relation.ts +++ b/src/modules/workspace/relation.ts @@ -32,17 +32,6 @@ export function registerNoteRelation() { }, ], onInit({ body, refresh }) { - body - .querySelector("iframe")! - .contentWindow?.addEventListener("message", (ev) => { - if (ev.data.type === "openNote") { - addon.hooks.onOpenNote( - ev.data.id, - ev.data.isShift ? "window" : "tab", - ); - } - }); - const notifierKey = Zotero.Notifier.registerObserver( { notify: (event, type, ids, extraData) => { @@ -81,10 +70,20 @@ export function registerNoteRelation() { onAsyncRender: async ({ body, item }) => { if (!item?.isNote()) return; if (!body.querySelector("#bn-relation-graph")) { - const iframe = body.ownerDocument.createXULElement("iframe") as HTMLIFrameElement; + const iframe = body.ownerDocument.createXULElement( + "iframe", + ) as HTMLIFrameElement; iframe.src = `chrome://${config.addonRef}/content/relationGraph.html`; iframe.id = "bn-relation-graph"; body.appendChild(iframe); + iframe.contentWindow?.addEventListener("message", (ev) => { + if (ev.data.type === "openNote") { + addon.hooks.onOpenNote( + ev.data.id, + ev.data.isShift ? "window" : "tab", + ); + } + }); } await renderGraph(body, item); },