mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -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 {
|
||||
if (!options.mainWindow || options.mainWindow.isDestroyed()) return false;
|
||||
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) {
|
||||
options.setVisibleOverlayVisible(true);
|
||||
}
|
||||
@@ -21,22 +26,27 @@ export function sendToVisibleOverlayRuntime<T extends string>(options: {
|
||||
}
|
||||
const sendNow = (): void => {
|
||||
if (options.payload === undefined) {
|
||||
options.mainWindow!.webContents.send(options.channel);
|
||||
webContents.send(options.channel);
|
||||
} 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 =
|
||||
!options.mainWindow.webContents.isLoading() &&
|
||||
!isLoading &&
|
||||
currentURL !== '' &&
|
||||
currentURL !== 'about:blank';
|
||||
|
||||
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.webContents.isLoading()) {
|
||||
if (typeof webContents.isLoading !== 'function' || !webContents.isLoading()) {
|
||||
sendNow();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user