fix(desktop): 显示完整菜单栏并启用快捷键

This commit is contained in:
2026-09-07 19:55:38 +08:00
parent a189b89942
commit 1399b54780
9 changed files with 127 additions and 53 deletions
+15 -1
View File
@@ -9,8 +9,22 @@ import { isDesktop } from './desktop'
export async function installDesktopLifecycle() {
if (!isDesktop()) return
const activeEditor = useEditorStore()
// 保存属于窗口级命令;编辑区原生处理撤销/重做,避免重复派发。
window.addEventListener('keydown', event => {
if (event.defaultPrevented || event.isComposing || event.repeat || event.altKey || event.shiftKey) return
if (!(event.ctrlKey || event.metaKey) || event.key.toLowerCase() !== 's') return
const target = event.target as HTMLElement | null
if (target?.closest('input, textarea, select, dialog[open], [role="dialog"]')) return
if (!activeEditor.currentFilePath || ['saving', 'conflict', 'external_changed'].includes(activeEditor.saveStatus)) return
event.preventDefault()
void activeEditor.save()
})
watch(() => [activeEditor.currentFilePath, activeEditor.saveStatus, activeEditor.mode], updateNativeEditorMenu, { flush: 'post' })
await listen<string>('editor-command', event => { void executeEditorCommand(event.payload) })
await listen<string>('editor-command', event => {
const focused = document.activeElement as HTMLElement | null
if (focused?.closest('input, textarea, select, dialog[open], [role="dialog"]')) return
void executeEditorCommand(event.payload)
})
let closing = false
await listen('host-close-requested', async () => {
if (closing) return