fix(frontend): wait for window focus before focusing quick entry input

The v-focus directive fires when the input mounts, but in the Electron
quick entry window the page loads before the window is shown. This
means focus() is called on a hidden window and has no effect.

Now check document.hasFocus() and if the window isn't focused yet,
defer the focus call to when the window receives focus.
This commit is contained in:
kolaente
2026-03-03 23:44:03 +01:00
parent 86141e13be
commit d909b50989

View File

@@ -186,7 +186,21 @@ watchEffect(() => {
watchEffect(() => {
if (active.value && isQuickAddMode) {
selectedCmd.value = commands.value.newTask
nextTick(() => searchInput.value?.focus())
// The Electron window may not be visible yet when Vue mounts
// (it's shown after did-finish-load). Try focusing now, and if
// the window doesn't have focus yet, wait for it.
nextTick(() => {
if (document.hasFocus()) {
searchInput.value?.focus()
} else {
const focusOnWindowReady = () => {
searchInput.value?.focus()
window.removeEventListener('focus', focusOnWindowReady)
}
window.addEventListener('focus', focusOnWindowReady)
}
})
}
})