fix(startup): preserve Electron WebContents receivers
This commit is contained in:
@@ -126,19 +126,19 @@ export function applyRemoteLoginSecurity(window: SecurityWindow, options: Remote
|
||||
|
||||
function applyCommonSecurity(window: SecurityWindow, externalHosts: readonly HttpsHostRule[]): void {
|
||||
const setWindowOpenHandler = window.webContents.setWindowOpenHandler as (handler: (details: { url: string }) => { action: "deny" }) => unknown;
|
||||
setWindowOpenHandler((details) => {
|
||||
setWindowOpenHandler.call(window.webContents, (details) => {
|
||||
void openAllowedExternalUrl(details.url, externalHosts);
|
||||
return { action: "deny" };
|
||||
});
|
||||
const setPermissionRequestHandler = window.webContents.session.setPermissionRequestHandler as (handler: (webContents: unknown, permission: string, callback: (allowed: boolean) => void) => void) => unknown;
|
||||
setPermissionRequestHandler((_webContents, _permission, callback) => {
|
||||
setPermissionRequestHandler.call(window.webContents.session, (_webContents, _permission, callback) => {
|
||||
callback(false);
|
||||
});
|
||||
}
|
||||
|
||||
function onNavigation(window: SecurityWindow, event: "will-navigate" | "will-redirect", listener: (event: NavigationEvent, url: string) => void): void {
|
||||
const on = window.webContents.on as (event: "will-navigate" | "will-redirect", listener: (event: NavigationEvent, url: string) => void) => unknown;
|
||||
on(event, listener);
|
||||
on.call(window.webContents, event, listener);
|
||||
}
|
||||
|
||||
function isExpectedRendererUrl(rawUrl: string, expectedUrl: string): boolean {
|
||||
|
||||
@@ -40,7 +40,9 @@ function isPackagedRendererUrl(senderUrl: string, appPath: string): boolean {
|
||||
}
|
||||
const senderPath = path.resolve(fileURLToPath(parsed));
|
||||
const rendererPath = path.resolve(appPath, "build", "renderer");
|
||||
return senderPath === rendererPath || senderPath.startsWith(rendererPath + path.sep);
|
||||
const actualPath = process.platform === "win32" ? senderPath.toLowerCase() : senderPath;
|
||||
const trustedRendererPath = process.platform === "win32" ? rendererPath.toLowerCase() : rendererPath;
|
||||
return actualPath === trustedRendererPath || actualPath.startsWith(trustedRendererPath + path.sep);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
+29
-19
@@ -148,8 +148,8 @@ function armScheduledStart(schedMs: number, opts: { startOnPast: boolean }): voi
|
||||
logger.info(`Geplanter Start gearmt: ${new Date(schedMs).toLocaleString()}`);
|
||||
}
|
||||
|
||||
function createWindow(): BrowserWindow {
|
||||
const window = new BrowserWindow({
|
||||
function createWindow(): BrowserWindow {
|
||||
const window = new BrowserWindow({
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
minWidth: 1120,
|
||||
@@ -160,6 +160,10 @@ function createWindow(): BrowserWindow {
|
||||
webPreferences: createMainWindowWebPreferences(path.join(__dirname, "../preload/preload.js"))
|
||||
});
|
||||
|
||||
window.webContents.on("did-fail-load", (_event, errorCode, errorDescription, validatedURL, isMainFrame) => {
|
||||
logger.error(`Renderer-Laden fehlgeschlagen: id=${window.id} code=${errorCode} mainFrame=${isMainFrame} url=${validatedURL} error=${errorDescription}`);
|
||||
});
|
||||
|
||||
applyMainWindowSecurity(window, {
|
||||
rendererUrl: getTrustedRendererUrl(),
|
||||
externalHosts: MAIN_WINDOW_EXTERNAL_HOSTS
|
||||
@@ -181,10 +185,14 @@ function createWindow(): BrowserWindow {
|
||||
window.setMenuBarVisibility(false);
|
||||
window.setAutoHideMenuBar(true);
|
||||
|
||||
if (isDevMode()) {
|
||||
void window.loadURL(DEV_SERVER_URL);
|
||||
} else {
|
||||
void window.loadFile(path.join(app.getAppPath(), "build", "renderer", "index.html"));
|
||||
if (isDevMode()) {
|
||||
void window.loadURL(DEV_SERVER_URL).catch((error) => {
|
||||
logger.error(`Renderer-Start fehlgeschlagen: ${String(error?.stack || error)}`);
|
||||
});
|
||||
} else {
|
||||
void window.loadFile(path.join(app.getAppPath(), "build", "renderer", "index.html")).catch((error) => {
|
||||
logger.error(`Renderer-Start fehlgeschlagen: ${String(error?.stack || error)}`);
|
||||
});
|
||||
}
|
||||
|
||||
return window;
|
||||
@@ -955,19 +963,21 @@ app.whenReady().then(() => {
|
||||
bindMainWindowLifecycle(mainWindow);
|
||||
}
|
||||
});
|
||||
}).catch((error) => {
|
||||
console.error("App startup failed:", error);
|
||||
app.quit();
|
||||
});
|
||||
|
||||
app.on("window-all-closed", () => {
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on("before-quit", () => {
|
||||
if (updateQuitTimer) { clearTimeout(updateQuitTimer); updateQuitTimer = null; }
|
||||
}).catch((error) => {
|
||||
logger.error(`App-Start fehlgeschlagen: ${String(error?.stack || error)}`);
|
||||
console.error("App startup failed:", error);
|
||||
app.quit();
|
||||
});
|
||||
|
||||
app.on("window-all-closed", () => {
|
||||
logger.warn("Alle Hauptfenster geschlossen");
|
||||
if (process.platform !== "darwin") {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on("before-quit", () => {
|
||||
if (updateQuitTimer) { clearTimeout(updateQuitTimer); updateQuitTimer = null; }
|
||||
stopClipboardWatcher();
|
||||
destroyTray();
|
||||
shutdownDaemon();
|
||||
|
||||
Reference in New Issue
Block a user