feat: add global keyboard shortcuts for timer toggle and show app
Register CmdOrCtrl+Shift+T (toggle timer) and CmdOrCtrl+Shift+Z (show app) via tauri-plugin-global-shortcut. Shortcut keys are configurable in Settings Timer tab. Shortcuts re-register on change.
This commit is contained in:
33
src/App.vue
33
src/App.vue
@@ -4,9 +4,37 @@ import TitleBar from './components/TitleBar.vue'
|
||||
import NavRail from './components/NavRail.vue'
|
||||
import ToastNotification from './components/ToastNotification.vue'
|
||||
import { useSettingsStore } from './stores/settings'
|
||||
import { useTimerStore } from './stores/timer'
|
||||
|
||||
const settingsStore = useSettingsStore()
|
||||
|
||||
async function registerShortcuts() {
|
||||
try {
|
||||
const { unregisterAll, register } = await import('@tauri-apps/plugin-global-shortcut')
|
||||
await unregisterAll()
|
||||
const toggleKey = settingsStore.settings.shortcut_toggle_timer || 'CmdOrCtrl+Shift+T'
|
||||
const showKey = settingsStore.settings.shortcut_show_app || 'CmdOrCtrl+Shift+Z'
|
||||
|
||||
await register(toggleKey, () => {
|
||||
const timerStore = useTimerStore()
|
||||
if (timerStore.isStopped) {
|
||||
if (timerStore.selectedProjectId) timerStore.start()
|
||||
} else {
|
||||
timerStore.stop()
|
||||
}
|
||||
})
|
||||
|
||||
await register(showKey, async () => {
|
||||
const { getCurrentWindow } = await import('@tauri-apps/api/window')
|
||||
const win = getCurrentWindow()
|
||||
await win.show()
|
||||
await win.setFocus()
|
||||
})
|
||||
} catch (e) {
|
||||
console.error('Failed to register shortcuts:', e)
|
||||
}
|
||||
}
|
||||
|
||||
function applyTheme() {
|
||||
const el = document.documentElement
|
||||
const mode = settingsStore.settings.theme_mode || 'dark'
|
||||
@@ -29,6 +57,7 @@ onMounted(async () => {
|
||||
(app.style as any).zoom = `${zoom}%`
|
||||
}
|
||||
applyTheme()
|
||||
registerShortcuts()
|
||||
|
||||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
|
||||
if (settingsStore.settings.theme_mode === 'system') applyTheme()
|
||||
@@ -38,6 +67,10 @@ onMounted(async () => {
|
||||
watch(() => [settingsStore.settings.theme_mode, settingsStore.settings.accent_color], () => {
|
||||
applyTheme()
|
||||
})
|
||||
|
||||
watch(() => [settingsStore.settings.shortcut_toggle_timer, settingsStore.settings.shortcut_show_app], () => {
|
||||
registerShortcuts()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user