fix: window-toggle actions focus when covered (Cmd+Ctrl+R/T, tray click)#114
fix: window-toggle actions focus when covered (Cmd+Ctrl+R/T, tray click)#114
Conversation
In Normal App mode, if the CodeV window was visible but covered
by another app (unfocused), pressing Cmd+Ctrl+R would hide it
instead of bringing it to the front. Required two presses to
reach top-most.
Now the three states are:
- Hidden/minimized → show + focus
- Visible but unfocused → app.focus({ steal: true }) + focus
- Visible AND focused → hide
Menu bar mode is unaffected: onBlur auto-hides the window, so
the visible-but-unfocused state can't occur there. The new
app.focus call is also gated to normal mode as a safeguard.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis PR updates the application to version 1.0.72 with a behavior fix for window toggle actions. In Normal mode, toggle actions now bring unfocused but visible windows to the front instead of immediately hiding them; focused windows continue to hide as before. Menu Bar mode behavior remains unchanged. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~28 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Apply the same three-state logic to: - Tray left-click (trayToggleEvtHandler default branch) - Cmd+Ctrl+T Terminal callback For Cmd+Ctrl+T, the visible-but-unfocused branch also sends 'switch-to-terminal' so the user lands on the Terminal tab after the window comes to front (matches the user intent of "I want to use the terminal"). Also adds the missing !window.isMinimized() check to both callbacks for consistency with quickSwitcherCallback. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main.ts (1)
1341-1357: Consider extracting the three-state toggle logic into a helper.The same visible/focused/unfocused branching pattern is duplicated in
trayToggleEvtHandler,quickSwitcherCallback, andterminalCallback. A small helper would reduce duplication and ensure consistent behavior across all toggle actions.♻️ Optional: Extract helper function
/** * Handles three-state window toggle: hidden→show, visible+unfocused→focus, visible+focused→hide. * Returns true if window was brought to front, false if hidden or not applicable. */ const bringToFrontOrHide = (window: BrowserWindow | null): 'shown' | 'hidden' | 'focused' | null => { if (!window) return null; if (window.isVisible() && !window.isMinimized()) { if (window.isFocused()) { hideSwitcherWindow(); return 'hidden'; } else { if (appMode === 'normal') { app.focus({ steal: true }); } window.show(); window.focus(); return 'focused'; } } return 'shown'; // caller should call showSwitcherWindow() };Then in each callback:
const result = bringToFrontOrHide(window); if (result === 'shown') { showSwitcherWindow(); } // For terminal: if (result === 'focused') window.webContents.send('switch-to-terminal');🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main.ts` around lines 1341 - 1357, Extract the duplicated three-state toggle logic (hidden → show, visible+unfocused → focus, visible+focused → hide) into a helper function (e.g., bringToFrontOrHide) and replace the repeated branches inside trayToggleEvtHandler, quickSwitcherCallback, and terminalCallback with calls to that helper; the helper should accept the BrowserWindow (or null), return a small discriminant ('shown' | 'focused' | 'hidden' | null), call hideSwitcherWindow() when hiding, call app.focus({steal:true}) + window.show() + window.focus() when bringing to front (respecting appMode), and return 'shown' when the caller still needs to call showSwitcherWindow(); update callers to call showSwitcherWindow() when helper returns 'shown' and send any context-specific messages (e.g., switch-to-terminal) when helper returns 'focused'.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/main.ts`:
- Around line 1341-1357: Extract the duplicated three-state toggle logic (hidden
→ show, visible+unfocused → focus, visible+focused → hide) into a helper
function (e.g., bringToFrontOrHide) and replace the repeated branches inside
trayToggleEvtHandler, quickSwitcherCallback, and terminalCallback with calls to
that helper; the helper should accept the BrowserWindow (or null), return a
small discriminant ('shown' | 'focused' | 'hidden' | null), call
hideSwitcherWindow() when hiding, call app.focus({steal:true}) + window.show() +
window.focus() when bringing to front (respecting appMode), and return 'shown'
when the caller still needs to call showSwitcherWindow(); update callers to call
showSwitcherWindow() when helper returns 'shown' and send any context-specific
messages (e.g., switch-to-terminal) when helper returns 'focused'.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1c6b72a6-28a9-4de1-9305-7c23762a1795
📒 Files selected for processing (3)
CHANGELOG.mdpackage.jsonsrc/main.ts
Summary
Fix window-toggle actions in Normal App mode when the CodeV window is visible but covered by another app.
Affected actions
Cmd+Ctrl+RquickSwitcherCallbacktrayToggleEvtHandlerCmd+Ctrl+TterminalCallbackThree-state logic
app.focus({ steal: true })+window.show()+window.focus()(new)For
Cmd+Ctrl+T, the visible-but-unfocused branch also sendsswitch-to-terminalso the user lands on the Terminal tab after the window comes to front (matches the user intent of "I want to use the terminal"). The visible-and-focused branch keeps the existing renderer-side toggle (check-terminal-and-hide).Also adds the missing
!window.isMinimized()check to bothtrayToggleEvtHandlerandterminalCallbackfor consistency withquickSwitcherCallback.Why menu bar mode is unaffected
In menu bar mode,
onBlurauto-hides the window the moment focus is lost (src/main.ts:267-271), so the "visible but unfocused" state can't occur. The newapp.focus({ steal: true })call is also gated toappMode === 'normal'as a safeguard — accessory apps shouldn't steal app-level focus.Test plan
Normal mode
Cmd+Ctrl+R: cover with another app → single press brings CodeV to frontCmd+Ctrl+R: on top + focused → hidesCmd+Ctrl+R: hidden → shows + focusesCmd+Ctrl+T: cover with another app → brings to front + lands on Terminal tabCmd+Ctrl+T: on top + focused + already on Terminal tab → hidesCmd+Ctrl+T: on top + focused + on other tab → switches to Terminal tabMenu bar mode
Cmd+Ctrl+R: behavior unchanged (visible → hide, hidden → show)Cmd+Ctrl+T: behavior unchanged🤖 On behalf of @grimmerk — generated with Claude Code
Summary by CodeRabbit