mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
fix(overlay): tolerate minimal webContents in bridge send path
This commit is contained in:
@@ -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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user