Skip to content

Fixed focus search box when Flow Launcher starts with Windows - #4593

Open
dedonnodev wants to merge 1 commit into
Flow-Launcher:devfrom
dedonnodev:dev
Open

Fixed focus search box when Flow Launcher starts with Windows#4593
dedonnodev wants to merge 1 commit into
Flow-Launcher:devfrom
dedonnodev:dev

Conversation

@dedonnodev

@dedonnodev dedonnodev commented Jul 29, 2026

Copy link
Copy Markdown

Problem

When Flow Launcher is configured to start with Windows and "Hide on startup"
is disabled, the main window appears after login but does not hold keyboard
focus. The search box looks focused, yet keystrokes go nowhere until the user
clicks it. Invoking the window later with the hotkey works fine.

Cause

MainWindow.OnLoaded shows the window through MainViewModel.Show(), which
sets MainWindowVisibilityStatus = true. That property already defaults to
true, so no PropertyChanged event is raised and the handler that runs
Activate() before QueryTextBox.Focus() — the path used on every
hotkey-triggered show — never executes during startup.

Startup therefore only ran the bare QueryTextBox.Focus(). That sets WPF's
internal keyboard focus, but a process launched in the background by Windows
is not the foreground window, so it never receives real keyboard input.
The hotkey path always transitions visibility false -> true, which is why
it is unaffected.

Fix

Activate the window on startup as well, once it has actually been shown.

The call is dispatched at DispatcherPriority.Loaded and skipped when
HideOnStartup is enabled, because Window.Activate() throws
InvalidOperationException: Cannot call DragMove or Activate before a Window is shown if the window has not finished being shown — which is the case in
the hidden-on-startup path, the default configuration.

Testing

  • HideOnStartup enabled (default): starts hidden, no exception, hotkey works as before
  • HideOnStartup disabled: window visible and immediately typeable after a reboot
  • Hotkey-triggered show still focuses and selects the query text as before

Note the testing section is left as unchecked boxes deliberately — I could not build or run this (no .NET SDK available here), so those still need your confirmation on Windows before you open the PR. Given the last iteration crashed on the default configuration, the first box in particular is worth exercising.


Summary by cubic

Fixes lost keyboard focus on Windows startup by activating the main window after it’s shown. When “Hide on startup” is off, the search box now accepts typing immediately.

Summary of changes

  • Changed: Startup path now mirrors the hotkey path by activating the window before focusing the search box.
  • Added: A Dispatcher.BeginInvoke (at Loaded priority) that:
    • Skips when _settings.HideOnStartup is true.
    • Checks _viewModel.MainWindowVisibilityStatus before calling Activate() and re-focusing QueryTextBox.
  • Removed: No existing logic removed.
  • Memory: Negligible impact (one short-lived dispatcher action on startup).
  • Security: No new security risks.
  • Tests: No unit tests added; behavior verified manually. Please confirm both startup modes and hotkey invocation.

Release Note
The app now takes keyboard focus on Windows startup (when not hidden), so you can type in the search box right away.

Written for commit 2f69032. Summary will update on new commits.

Review in cubic

@github-actions github-actions Bot added this to the 2.2.0 milestone Jul 29, 2026
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

OnLoaded now schedules activation and QueryTextBox focus for visible startup states, while skipping the behavior when the window is configured to start hidden.

Changes

Startup focus handling

Layer / File(s) Summary
Conditional startup activation and focus
Flow.Launcher/MainWindow.xaml.cs
OnLoaded dispatches window activation and QueryTextBox focus at DispatcherPriority.Loaded when startup hiding is disabled and the window is visible.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Suggested reviewers: davidgbrett, jack251970

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the main change: fixing startup focus for the search box on Windows.
Description check ✅ Passed The description accurately explains the startup focus bug, the activation fix, and the hidden-on-startup exception path.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant