From 92fee7511f097415ff30029b253fe4a09125e047 Mon Sep 17 00:00:00 2001 From: ypshidifu Date: Tue, 22 Sep 2026 22:04:02 +0800 Subject: [PATCH] =?UTF-8?q?v4:=20=E7=9B=B4=E6=8E=A5=E8=B0=83=E7=94=A8=20ui?= =?UTF-8?q?.slot(component)=20=E6=B3=A8=E5=86=8C=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=9C=A8=E7=BB=84=E4=BB=B6=E6=B8=B2=E6=9F=93=E9=98=B6?= =?UTF-8?q?=E6=AE=B5=E8=B0=83=E7=94=A8=20keymap.layer=20=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tui-plugins/oc-session-all.js | 151 ++++++++++++++++------------------ 1 file changed, 71 insertions(+), 80 deletions(-) diff --git a/tui-plugins/oc-session-all.js b/tui-plugins/oc-session-all.js index 70104eb..a020949 100644 --- a/tui-plugins/oc-session-all.js +++ b/tui-plugins/oc-session-all.js @@ -30,106 +30,97 @@ function delay(ms) { export default Plugin.define({ id: "oc-session-all", async setup(context) { - log("[oc-session-all] v3 Plugin loaded! Trying to register command via ui.slot...") - - // 先写入测试日志,确保 fs 可用 - log("[oc-session-all] FS test: log file created successfully") + log("[oc-session-all] v4 Plugin loaded! Calling ui.slot(component) directly...") - // 延时 3 秒,避免 toast 被覆盖 - await delay(3000) + // 延时 5 秒,避免 toast 被覆盖(别人插件也会弹) + await delay(5000) - // ── 探测 context.ui.slot ────────────────────────────────────── const report = [] - - if (context.ui && context.ui.slot) { - report.push("ui.slot exists") - log("[oc-session-all] ui.slot type: " + typeof context.ui.slot) - - // 尝试列出 slot 的所有方法 - const slotMethods = Object.getOwnPropertyNames(context.ui.slot) - report.push("slot methods: " + slotMethods.join(", ")) - log("[oc-session-all] slot methods: " + slotMethods.join(", ")) - - // 尝试调用 slot 的各种方法 - for (const method of slotMethods) { - if (typeof context.ui.slot[method] === "function") { - log("[oc-session-all] slot." + method + " is a function") - } - } + + // ── 探测 ui.slot 函数本身的元信息 ────────────────────────────────────── + if (context.ui && typeof context.ui.slot === "function") { + report.push("ui.slot fn name=" + context.ui.slot.name + " arity=" + context.ui.slot.length) + log("[oc-session-all] ui.slot is a function, name=" + context.ui.slot.name + ", arity=" + context.ui.slot.length) } else { - report.push("ui.slot NOT found") + report.push("ui.slot NOT a function") + log("[oc-session-all] ui.slot is NOT a function, type=" + typeof (context.ui && context.ui.slot)) } - // ── 尝试通过 ui.slot 注册组件 ────────────────────────────────────── + // ── 直接调用 ui.slot(component) 注册组件 ────────────────────────────────────── + let slotReturn = "not called" try { - // 创建一个简单的组件,尝试在渲染时注册命令 - const testComponent = () => { - log("[oc-session-all] Test component rendered!") + // 组件在 SolidJS 渲染上下文内执行,此时 Keymap.Provider 应该可用 + const ProbeComponent = () => { + log("[oc-session-all] ProbeComponent RENDERED inside slot!") + // 在组件渲染阶段尝试 keymap.layer(此时应在 Provider 内) + try { + if (context.keymap && typeof context.keymap.layer === "function") { + const layerResult = context.keymap.layer({ + commands: [ + { + id: "sessions-all", + title: "Show all sessions", + group: "Session", + run: () => { + log("[oc-session-all] /sessions-all command RUN!") + }, + }, + ], + bindings: [ + { + key: "ctrl+o", + command: "sessions-all", + }, + ], + }) + log("[oc-session-all] keymap.layer() inside component: SUCCESS, result type=" + typeof layerResult) + report.push("layer-in-component: SUCCESS") + } else { + log("[oc-session-all] keymap.layer not available inside component") + report.push("layer-in-component: keymap.layer missing") + } + } catch (e) { + log("[oc-session-all] keymap.layer() inside component ERROR: " + e.message) + report.push("layer-in-component ERROR: " + e.message) + } + // 组件不渲染任何可见内容 return null } - - // 尝试不同的注册方法 - if (context.ui.slot && typeof context.ui.slot.register === "function") { - context.ui.slot.register(testComponent) - report.push("registered via slot.register()") - log("[oc-session-all] Registered component via slot.register()") - } else if (context.ui.slot && typeof context.ui.slot.add === "function") { - context.ui.slot.add(testComponent) - report.push("registered via slot.add()") - log("[oc-session-all] Registered component via slot.add()") - } else if (context.ui.slot && typeof context.ui.slot.append === "function") { - context.ui.slot.append(testComponent) - report.push("registered via slot.append()") - log("[oc-session-all] Registered component via slot.append()") - } else { - report.push("no known slot registration method") - log("[oc-session-all] No known slot registration method found") - } + + // 直接调用 slot 函数注册组件 + const ret = context.ui.slot(ProbeComponent) + slotReturn = typeof ret + report.push("ui.slot(component) returned type=" + typeof ret) + log("[oc-session-all] ui.slot(component) called, returned type=" + typeof ret + ", value=" + String(ret)) } catch (e) { - report.push("slot registration ERROR: " + e.message) - log("[oc-session-all] slot registration ERROR: " + e.message) + report.push("ui.slot(component) ERROR: " + e.message) + log("[oc-session-all] ui.slot(component) ERROR: " + e.message) } - // ── 尝试直接使用 keymap.layer(可能需要等待) ────────────────────────────────────── + // 等待组件渲染 + await delay(3000) + + // ── 验证命令是否注册成功 ────────────────────────────────────── try { - // 等待更长时间,让 Provider 可用 - await delay(2000) - - if (context.keymap && typeof context.keymap.layer === "function") { - log("[oc-session-all] Attempting keymap.layer call...") - try { - // 尝试注册一个测试命令 - const layer = context.keymap.layer({ - commands: [ - { - id: "sessions-all", - title: "Show all sessions", - group: "Session", - } - ], - bindings: [ - { - key: "ctrl+o", - command: "sessions-all", - } - ] - }) - report.push("keymap.layer() SUCCESS") - log("[oc-session-all] keymap.layer() SUCCESS") - } catch (e) { - report.push("keymap.layer() ERROR: " + e.message) - log("[oc-session-all] keymap.layer() ERROR: " + e.message) + if (context.keymap && typeof context.keymap.commands === "function") { + const cmds = context.keymap.commands() + const cmdStr = JSON.stringify(cmds) + log("[oc-session-all] commands() after slot: " + cmdStr.substring(0, 800)) + if (cmdStr.includes("sessions-all")) { + report.push("sessions-all REGISTERED!") + log("[oc-session-all] === sessions-all command REGISTERED SUCCESSFULLY ===") + } else { + report.push("sessions-all NOT in commands()") } } } catch (e) { - report.push("layer attempt ERROR: " + e.message) - log("[oc-session-all] layer attempt ERROR: " + e.message) + log("[oc-session-all] commands() check ERROR: " + e.message) } // 最终报告 const finalReport = report.join(" | ") log("[oc-session-all] SLOT PROBE: " + finalReport) - + // 延时后显示 toast await delay(2000) try { @@ -142,4 +133,4 @@ export default Plugin.define({ log("[oc-session-all] toast.show ERROR: " + e.message) } }, -}) \ No newline at end of file +})