fix: re-enable modal input capture on active overlay window

This commit is contained in:
2026-02-27 21:31:04 -08:00
parent 8aa2a45c7c
commit 6da2caabf7
2 changed files with 50 additions and 1 deletions

View File

@@ -281,6 +281,41 @@ test('modal runtime notifies callers when modal input state becomes active/inact
assert.deepEqual(state, [true, false]);
});
test('notifyOverlayModalOpened enables input on visible main overlay window when no modal window exists', () => {
const mainWindow = createMockWindow();
mainWindow.visible = true;
mainWindow.ignoreMouseEvents = true;
const state: boolean[] = [];
const runtime = createOverlayModalRuntimeService(
{
getMainWindow: () => mainWindow as never,
getModalWindow: () => null,
createModalWindow: () => {
throw new Error('modal window should not be created when main overlay is visible');
},
getModalGeometry: () => ({ x: 0, y: 0, width: 400, height: 300 }),
setModalWindowBounds: () => {},
},
{
onModalStateChange: (active: boolean): void => {
state.push(active);
},
},
);
const sent = runtime.sendToActiveOverlayWindow('runtime-options:open', undefined, {
restoreOnModalClose: 'runtime-options',
});
runtime.notifyOverlayModalOpened('runtime-options');
assert.equal(sent, true);
assert.equal(state, [true]);
assert.equal(mainWindow.ignoreMouseEvents, false);
assert.equal(mainWindow.isFocused(), true);
assert.equal(mainWindow.webContentsFocused, true);
});
test('handleOverlayModalClosed resets modal state even when modal window does not exist', () => {
const state: boolean[] = [];
const runtime = createOverlayModalRuntimeService(

View File

@@ -65,6 +65,20 @@ export function createOverlayModalRuntimeService(
return null;
};
const getActiveOverlayWindowForModalInput = (): BrowserWindow | null => {
const modalWindow = deps.getModalWindow();
if (modalWindow && !modalWindow.isDestroyed()) {
return modalWindow;
}
const visibleMainWindow = deps.getMainWindow();
if (visibleMainWindow && !visibleMainWindow.isDestroyed()) {
return visibleMainWindow;
}
return null;
};
const isWindowReadyForIpc = (window: BrowserWindow): boolean => {
if (window.webContents.isLoading()) {
return false;
@@ -245,7 +259,7 @@ export function createOverlayModalRuntimeService(
const notifyOverlayModalOpened = (modal: OverlayHostedModal): void => {
if (!restoreVisibleOverlayOnModalClose.has(modal)) return;
notifyModalStateChange(true);
const targetWindow = deps.getModalWindow();
const targetWindow = getActiveOverlayWindowForModalInput();
clearPendingModalWindowReveal();
if (!targetWindow || targetWindow.isDestroyed()) {
return;