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:
Your Name
2026-02-18 10:46:18 +02:00
parent 8d0f6c6c7d
commit 5ac890aad4
2 changed files with 205 additions and 1 deletions

View File

@@ -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>