From 6d59c24126149b63cc80776461e5385ed7d8d686 Mon Sep 17 00:00:00 2001 From: ypshidifu Date: Tue, 22 Sep 2026 21:50:57 +0800 Subject: [PATCH] =?UTF-8?q?v3:=20=E5=B0=9D=E8=AF=95=E9=80=9A=E8=BF=87ui.sl?= =?UTF-8?q?ot=E6=B3=A8=E5=86=8C=E7=BB=84=E4=BB=B6=E6=9D=A5=E8=8E=B7?= =?UTF-8?q?=E5=8F=96Keymap=20Provider=E4=B8=8A=E4=B8=8B=E6=96=87=EF=BC=8C?= =?UTF-8?q?=E6=8E=A2=E7=B4=A2=E5=9C=A8SolidJS=E6=B8=B2=E6=9F=93=E9=98=B6?= =?UTF-8?q?=E6=AE=B5=E6=B3=A8=E5=86=8C=E5=91=BD=E4=BB=A4=E7=9A=84=E5=8F=AF?= =?UTF-8?q?=E8=A1=8C=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tui-plugins/oc-session-all.js | 133 +++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 43 deletions(-) diff --git a/tui-plugins/oc-session-all.js b/tui-plugins/oc-session-all.js index c281517..70104eb 100644 --- a/tui-plugins/oc-session-all.js +++ b/tui-plugins/oc-session-all.js @@ -30,64 +30,111 @@ function delay(ms) { export default Plugin.define({ id: "oc-session-all", async setup(context) { - log("[oc-session-all] v2 Plugin loaded! Exploring keymap.commands and dispatch...") + 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") - // 延时 5 秒,避免 toast 被覆盖 - await delay(5000) + // 延时 3 秒,避免 toast 被覆盖 + await delay(3000) - // ── 探测 keymap.commands 和 dispatch ────────────────────────────────────── + // ── 探测 context.ui.slot ────────────────────────────────────── const report = [] - - if (context.keymap) { - // 尝试 keymap.commands() - if (typeof context.keymap.commands === "function") { - try { - const commandsResult = context.keymap.commands() - report.push("keymap.commands() returned: " + JSON.stringify(commandsResult).substring(0, 200)) - log("[oc-session-all] keymap.commands() result: " + JSON.stringify(commandsResult).substring(0, 500)) - } catch (e) { - report.push("keymap.commands() ERROR: " + e.message) - log("[oc-session-all] keymap.commands() ERROR: " + e.message) + + 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") } - } else { - report.push("keymap.commands is NOT a function") - } - - // 尝试 keymap.dispatch - if (typeof context.keymap.dispatch === "function") { - report.push("keymap.dispatch is a function") - - // 尝试触发一个已知的命令 - try { - context.keymap.dispatch("command.palette.show") - report.push("dispatch command.palette.show: SUCCESS") - log("[oc-session-all] dispatch command.palette.show: SUCCESS") - } catch (e) { - report.push("dispatch command.palette.show ERROR: " + e.message) - log("[oc-session-all] dispatch command.palette.show ERROR: " + e.message) - } - } else { - report.push("keymap.dispatch is NOT a function") - } - - // 尝试 keymap.layer 的不同调用方式 - if (typeof context.keymap.layer === "function") { - // 不调用 layer,只记录它存在 - report.push("keymap.layer exists but needs Provider context") } + } else { + report.push("ui.slot NOT found") } - const msg = report.join(" | ") - log("[oc-session-all] COMMANDS PROBE: " + msg) + // ── 尝试通过 ui.slot 注册组件 ────────────────────────────────────── + try { + // 创建一个简单的组件,尝试在渲染时注册命令 + const testComponent = () => { + log("[oc-session-all] Test component rendered!") + 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") + } + } catch (e) { + report.push("slot registration ERROR: " + e.message) + log("[oc-session-all] slot registration ERROR: " + e.message) + } + + // ── 尝试直接使用 keymap.layer(可能需要等待) ────────────────────────────────────── + 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) + } + } + } catch (e) { + report.push("layer attempt ERROR: " + e.message) + log("[oc-session-all] layer attempt ERROR: " + e.message) + } + + // 最终报告 + const finalReport = report.join(" | ") + log("[oc-session-all] SLOT PROBE: " + finalReport) // 延时后显示 toast await delay(2000) try { context.ui.toast.show({ - message: "Commands probe: " + msg, + message: "Slot probe: " + finalReport, variant: "info", duration: 25000, })