Skip to content

refactor(main): dedupe window restore+focus into a shared focusWindow helper#230

Open
PaulHorn wants to merge 1 commit into
mainfrom
refactor/dedupe-window-focus
Open

refactor(main): dedupe window restore+focus into a shared focusWindow helper#230
PaulHorn wants to merge 1 commit into
mainfrom
refactor/dedupe-window-focus

Conversation

@PaulHorn
Copy link
Copy Markdown
Contributor

What

Extracts a small focusWindow(win) helper in src/main/singleInstance.ts and routes the three places that surface an existing window through it.

Why

The un-minimize-then-focus idiom —

if (win.isMinimized()) win.restore()
win.focus()

— was duplicated across three call sites:

  • singleInstance.focusRunningInstanceWindow (second-instance event)
  • deliverOpenPath in index.ts (open-path)
  • the notification-click handler in ipc/notifications.ts

PR #224 introduced the tested focusRunningInstanceWindow helper for the single-instance case but left the two pre-existing inline copies in place. This consolidates all three so there's a single place that decides how the app brings an existing window to the foreground.

How

  • New focusWindow(win: BrowserWindow) in singleInstance.ts.
  • focusRunningInstanceWindow now picks the first live window and delegates to focusWindow.
  • deliverOpenPath and the notification handler call focusWindow (each keeps its own surrounding guard — try/catch and !isDestroyed() respectively).

Notes

  • No behavior change. Pure de-duplication.
  • Each call site keeps its existing window selection logic (findMainWindow, the notification's owner window, first-live); only the shared restore+focus tail is unified.

Tests

  • Adds direct unit tests for focusWindow (focuses; restores-then-focuses when minimized).
  • tsc --noEmit clean · full vitest suite green (529 incl. 8 in singleInstance.test.ts).

… helper

The un-minimize-then-focus idiom was duplicated across three call sites:
singleInstance.focusRunningInstanceWindow, deliverOpenPath in index.ts, and
the notification-click handler. #224 introduced a tested helper for the
second-instance case but left the two pre-existing inline copies.

Extract focusWindow(win) in singleInstance.ts and route all three through it,
so there is a single place that decides how the app surfaces an existing
window. No behavior change; adds direct unit tests for the helper.
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