fix(desktop): 重构菜单并恢复 Shiki 高亮

This commit is contained in:
2026-09-07 23:35:43 +08:00
parent 078aabc667
commit cb123f4317
9 changed files with 315 additions and 100 deletions
@@ -17,6 +17,16 @@ export type CommandResult = { ok: true } | { ok: false; reason: 'unsupported' |
export type CommandHandler = (params: unknown) => CommandResult | Promise<CommandResult>
type Target = { available: () => boolean; handlers: Partial<Record<EditorCommandId, CommandHandler>> }
let active: Target | undefined
const capabilityListeners = new Set<() => void>()
export function subscribeEditorCommandCapabilities(listener: () => void) {
capabilityListeners.add(listener)
return () => capabilityListeners.delete(listener)
}
function notifyCapabilityListeners() {
capabilityListeners.forEach(listener => listener())
}
export function registerEditorCommands(target: Target) {
active = target
@@ -24,6 +34,7 @@ export function registerEditorCommands(target: Target) {
return () => { if (active === target) { active = undefined; updateNativeEditorMenu() } }
}
export function updateNativeEditorMenu() {
notifyCapabilityListeners()
if (isDesktop()) void hostInvoke('editor_capabilities', { importEnabled: !!active?.handlers['editor.import-note-properties'] && active.available() }).catch(() => undefined)
}
export function getEditorCommandCapabilities() {