更新探测版插件:更详细的 context 结构探测

This commit is contained in:
ypshidifu
2026-09-22 20:55:42 +08:00
parent dc1a27e88e
commit fd1a475abc
2 changed files with 96 additions and 78 deletions
+47 -38
View File
@@ -5,60 +5,69 @@ export default Plugin.define({
setup(context) {
console.log("[oc-session-all] v2 Plugin loaded! Attempting command registration...")
// ── 尝试注册命令 ──────────────────────────────────────
// ── 探测 context 结构 ──────────────────────────────────────
const report = []
report.push("context keys: " + Object.keys(context).join(", "))
// 尝试 context.command.register
if (context.command && typeof context.command.register === "function") {
try {
const unregister = context.command.register(() => [
{
title: "Show All Sessions",
value: "sessions-all",
slash: { name: "sessions-all", aliases: ["sa"] },
description: "Display all session records in a dialog",
onSelect: async () => {
console.log("[oc-session-all] /sessions-all triggered")
context.ui.toast.show({
message: "Sessions-all command executed!",
variant: "success",
duration: 3000,
})
// 探测 context.command
if (context.command) {
const cmdKeys = Object.getOwnPropertyNames(context.command)
report.push("command props: " + cmdKeys.join(", "))
const cmdMethods = cmdKeys.filter(k => typeof context.command[k] === "function")
report.push("command methods: " + cmdMethods.join(", "))
// 尝试 command.register
if (typeof context.command.register === "function") {
try {
const unregister = context.command.register(() => [
{
title: "Show All Sessions",
value: "sessions-all",
slash: { name: "sessions-all", aliases: ["sa"] },
description: "Display all session records in a dialog",
onSelect: async () => {
console.log("[oc-session-all] /sessions-all triggered")
context.ui.toast.show({
message: "Sessions-all command executed!",
variant: "success",
duration: 3000,
})
},
},
},
])
report.push("command.register: SUCCESS, unregister: " + typeof unregister)
console.log("[oc-session-all] command.register succeeded")
} catch (e) {
report.push("command.register ERROR: " + e.message)
console.error("[oc-session-all] command.register failed:", e)
])
report.push("command.register: SUCCESS, unregister type: " + typeof unregister)
console.log("[oc-session-all] command.register succeeded")
} catch (e) {
report.push("command.register ERROR: " + e.message)
console.error("[oc-session-all] command.register failed:", e)
}
} else {
report.push("command.register: NOT A FUNCTION")
}
} else {
report.push("context.command: " + (context.command ? "exists but no register" : "undefined"))
report.push("context.command: undefined")
}
// 尝试 keymap 的其他方法
// 探测 context.keymap
if (context.keymap) {
const kmMethods = Object.getOwnPropertyNames(context.keymap)
.filter(k => typeof context.keymap[k] === "function")
const kmKeys = Object.getOwnPropertyNames(context.keymap)
report.push("keymap props: " + kmKeys.join(", "))
const kmMethods = kmKeys.filter(k => typeof context.keymap[k] === "function")
report.push("keymap methods: " + kmMethods.join(", "))
}
// 尝试常见的 Keymap 方法
const tryMethods = ["bind", "on", "register", "registerLayer", "layer"]
for (const m of tryMethods) {
if (typeof context.keymap[m] === "function") {
report.push("keymap." + m + " exists")
}
}
// 探测 context.ui
if (context.ui) {
const uiKeys = Object.keys(context.ui)
report.push("ui keys: " + uiKeys.join(", "))
}
const msg = report.join(" | ")
console.log("[oc-session-all] REGISTER PROBE: " + msg)
console.log("[oc-session-all] FULL PROBE: " + msg)
context.ui.toast.show({
message: "Register probe: " + msg,
message: "Full probe: " + msg,
variant: "info",
duration: 15000,
duration: 20000,
})
},
})
+47 -38
View File
@@ -5,60 +5,69 @@ export default Plugin.define({
setup(context) {
console.log("[oc-session-all] v2 Plugin loaded! Attempting command registration...")
// ── 尝试注册命令 ──────────────────────────────────────
// ── 探测 context 结构 ──────────────────────────────────────
const report = []
report.push("context keys: " + Object.keys(context).join(", "))
// 尝试 context.command.register
if (context.command && typeof context.command.register === "function") {
try {
const unregister = context.command.register(() => [
{
title: "Show All Sessions",
value: "sessions-all",
slash: { name: "sessions-all", aliases: ["sa"] },
description: "Display all session records in a dialog",
onSelect: async () => {
console.log("[oc-session-all] /sessions-all triggered")
context.ui.toast.show({
message: "Sessions-all command executed!",
variant: "success",
duration: 3000,
})
// 探测 context.command
if (context.command) {
const cmdKeys = Object.getOwnPropertyNames(context.command)
report.push("command props: " + cmdKeys.join(", "))
const cmdMethods = cmdKeys.filter(k => typeof context.command[k] === "function")
report.push("command methods: " + cmdMethods.join(", "))
// 尝试 command.register
if (typeof context.command.register === "function") {
try {
const unregister = context.command.register(() => [
{
title: "Show All Sessions",
value: "sessions-all",
slash: { name: "sessions-all", aliases: ["sa"] },
description: "Display all session records in a dialog",
onSelect: async () => {
console.log("[oc-session-all] /sessions-all triggered")
context.ui.toast.show({
message: "Sessions-all command executed!",
variant: "success",
duration: 3000,
})
},
},
},
])
report.push("command.register: SUCCESS, unregister: " + typeof unregister)
console.log("[oc-session-all] command.register succeeded")
} catch (e) {
report.push("command.register ERROR: " + e.message)
console.error("[oc-session-all] command.register failed:", e)
])
report.push("command.register: SUCCESS, unregister type: " + typeof unregister)
console.log("[oc-session-all] command.register succeeded")
} catch (e) {
report.push("command.register ERROR: " + e.message)
console.error("[oc-session-all] command.register failed:", e)
}
} else {
report.push("command.register: NOT A FUNCTION")
}
} else {
report.push("context.command: " + (context.command ? "exists but no register" : "undefined"))
report.push("context.command: undefined")
}
// 尝试 keymap 的其他方法
// 探测 context.keymap
if (context.keymap) {
const kmMethods = Object.getOwnPropertyNames(context.keymap)
.filter(k => typeof context.keymap[k] === "function")
const kmKeys = Object.getOwnPropertyNames(context.keymap)
report.push("keymap props: " + kmKeys.join(", "))
const kmMethods = kmKeys.filter(k => typeof context.keymap[k] === "function")
report.push("keymap methods: " + kmMethods.join(", "))
}
// 尝试常见的 Keymap 方法
const tryMethods = ["bind", "on", "register", "registerLayer", "layer"]
for (const m of tryMethods) {
if (typeof context.keymap[m] === "function") {
report.push("keymap." + m + " exists")
}
}
// 探测 context.ui
if (context.ui) {
const uiKeys = Object.keys(context.ui)
report.push("ui keys: " + uiKeys.join(", "))
}
const msg = report.join(" | ")
console.log("[oc-session-all] REGISTER PROBE: " + msg)
console.log("[oc-session-all] FULL PROBE: " + msg)
context.ui.toast.show({
message: "Register probe: " + msg,
message: "Full probe: " + msg,
variant: "info",
duration: 15000,
duration: 20000,
})
},
})