fix(desktop): 显示完整菜单栏并启用快捷键
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user