fix(overlay): tolerate minimal webContents in bridge send path

This commit is contained in:
2026-02-27 00:39:59 -08:00
parent edca554db1
commit 77c698e00b

View File

@@ -13,6 +13,11 @@ export function sendToVisibleOverlayRuntime<T extends string>(options: {
}): boolean { }): boolean {
if (!options.mainWindow || options.mainWindow.isDestroyed()) return false; if (!options.mainWindow || options.mainWindow.isDestroyed()) return false;
const wasVisible = options.visibleOverlayVisible; const wasVisible = options.visibleOverlayVisible;
const webContents = options.mainWindow.webContents as Electron.WebContents & {
isLoading?: () => boolean;
getURL?: () => string;
once?: (event: 'did-finish-load', listener: () => void) => void;
};
if (!options.visibleOverlayVisible) { if (!options.visibleOverlayVisible) {
options.setVisibleOverlayVisible(true); options.setVisibleOverlayVisible(true);
} }
@@ -21,22 +26,27 @@ export function sendToVisibleOverlayRuntime<T extends string>(options: {
} }
const sendNow = (): void => { const sendNow = (): void => {
if (options.payload === undefined) { if (options.payload === undefined) {
options.mainWindow!.webContents.send(options.channel); webContents.send(options.channel);
} else { } else {
options.mainWindow!.webContents.send(options.channel, options.payload); webContents.send(options.channel, options.payload);
} }
}; };
const currentURL = options.mainWindow.webContents.getURL(); const isLoading = typeof webContents.isLoading === 'function' ? webContents.isLoading() : false;
const currentURL = typeof webContents.getURL === 'function' ? webContents.getURL() : '';
const isReady = const isReady =
!options.mainWindow.webContents.isLoading() && !isLoading &&
currentURL !== '' && currentURL !== '' &&
currentURL !== 'about:blank'; currentURL !== 'about:blank';
if (!isReady) { if (!isReady) {
options.mainWindow.webContents.once('did-finish-load', () => { if (typeof webContents.once !== 'function') {
sendNow();
return true;
}
webContents.once('did-finish-load', () => {
if (!options.mainWindow || options.mainWindow.isDestroyed()) return; if (!options.mainWindow || options.mainWindow.isDestroyed()) return;
if (!options.mainWindow.webContents.isLoading()) { if (typeof webContents.isLoading !== 'function' || !webContents.isLoading()) {
sendNow(); sendNow();
} }
}); });