From 5ac890aad47722550e479f93514dcb4daf14dc2d Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 18 Feb 2026 10:46:18 +0200 Subject: [PATCH] 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. --- src/App.vue | 33 ++++++++ src/views/Settings.vue | 173 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 205 insertions(+), 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index 7ae72d6..84ed548 100644 --- a/src/App.vue +++ b/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() +})