fix: address code review feedback for PR #232

- Drop isVisible() filter from getWindow() fallback so flashFrame()
  works on minimized windows, which is its primary use case
- Add isDestroyed() guard to setTimeout resize callback to prevent
  errors if the window is closed within the 50ms delay

Co-Authored-By: Claude <claude@anthropic.com>
This commit is contained in:
aaddrick
2026-02-16 11:30:26 -05:00
parent b544a7bb6c
commit 75841f0813
2 changed files with 10 additions and 6 deletions

View File

@@ -4,17 +4,19 @@ const KeyboardKey = { Backspace: 43, Tab: 280, Enter: 261, Shift: 272, Control:
Object.freeze(KeyboardKey);
// Helper: get the focused BrowserWindow (lazy-loaded to avoid circular deps)
// Filters destroyed/invisible windows from fallback to avoid errors like
// flashFrame() on a destroyed window or getIsMaximized() on a popup
// Filters destroyed windows from fallback to avoid errors like
// flashFrame() on a destroyed window or getIsMaximized() on a popup.
// Note: isVisible() is intentionally NOT checked — flashFrame() must work
// on minimized (non-visible) windows, which is its primary use case.
function getWindow() {
try {
const { BrowserWindow } = require('electron');
const focused = BrowserWindow.getFocusedWindow();
if (focused) return focused;
const visible = BrowserWindow.getAllWindows().find(
(w) => !w.isDestroyed() && w.isVisible()
const win = BrowserWindow.getAllWindows().find(
(w) => !w.isDestroyed()
);
return visible || null;
return win || null;
} catch (e) {
console.warn('[Claude Native Stub] getWindow() failed:', e);
return null;

View File

@@ -96,7 +96,9 @@ Module.prototype.require = function(id) {
// Only applies to main windows; popups don't need resize jiggle
const [w, h] = this.getSize();
this.setSize(w + 1, h + 1);
setTimeout(() => this.setSize(w, h), 50);
setTimeout(() => {
if (!this.isDestroyed()) this.setSize(w, h);
}, 50);
}
});