2026-04-11 15:59:14 +08:00
|
|
|
import { onMounted, onUnmounted } from 'vue'
|
|
|
|
|
import { useRouter } from 'vue-router'
|
2026-04-16 08:38:18 +08:00
|
|
|
import { useChatStore } from '@/stores/hermes/chat'
|
2026-04-11 15:59:14 +08:00
|
|
|
|
|
|
|
|
export function useKeyboard() {
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
const chatStore = useChatStore()
|
|
|
|
|
|
|
|
|
|
function handleKeydown(e: KeyboardEvent) {
|
|
|
|
|
const mod = e.ctrlKey || e.metaKey
|
|
|
|
|
|
|
|
|
|
if (mod && e.key === 'n') {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
chatStore.newChat()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mod && e.key === 'j') {
|
|
|
|
|
e.preventDefault()
|
2026-04-16 08:38:18 +08:00
|
|
|
router.push({ name: 'hermes.jobs' })
|
2026-04-11 15:59:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.key === 'Escape') {
|
|
|
|
|
// Close any open modals — naive-ui handles this internally
|
|
|
|
|
const modal = document.querySelector('.n-modal-mask')
|
|
|
|
|
if (modal) {
|
|
|
|
|
const closeBtn = modal.querySelector('.n-base-close') as HTMLElement
|
|
|
|
|
closeBtn?.click()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
window.addEventListener('keydown', handleKeydown)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
window.removeEventListener('keydown', handleKeydown)
|
|
|
|
|
})
|
|
|
|
|
}
|