Improve terminal renderer recovery

This commit is contained in:
Mohamed Boudra
2026-04-24 13:05:58 +07:00
parent c92e4e46d2
commit d152b4f055
3 changed files with 88 additions and 23 deletions
+2
View File
@@ -21,6 +21,7 @@ import {
getMainWindowChromeOptions,
getWindowBackgroundColor,
resolveSystemWindowTheme,
setupDarwinPaintRefresh,
setupWindowResizeEvents,
setupDefaultContextMenu,
setupDragDropPrevention,
@@ -189,6 +190,7 @@ async function createMainWindow(): Promise<void> {
app.dock?.setBadge(devWorktreeName);
}
setupDarwinPaintRefresh(mainWindow);
setupWindowResizeEvents(mainWindow);
setupDefaultContextMenu(mainWindow);
setupDragDropPrevention(mainWindow);
@@ -219,6 +219,59 @@ export function setupWindowResizeEvents(win: BrowserWindow): void {
});
}
function refreshChromiumSurface(win: BrowserWindow): void {
if (win.isDestroyed()) {
return;
}
win.webContents.invalidate();
if (win.isMaximized() || win.isFullScreen()) {
return;
}
const [width, height] = win.getSize();
win.setSize(width + 1, height);
setTimeout(() => {
if (!win.isDestroyed()) {
win.setSize(width, height);
}
}, 32);
}
export function setupDarwinPaintRefresh(win: BrowserWindow): void {
if (process.platform !== "darwin") {
return;
}
win.webContents.setBackgroundThrottling(false);
const requestSurfaceRefresh = () => {
if (!win.isDestroyed()) {
win.webContents.invalidate();
}
};
const handleChildProcessGone = (
_event: Electron.Event,
details: { type?: string; reason?: string },
) => {
if (details.type !== "GPU") {
return;
}
console.warn("[window] GPU process gone:", details.reason);
refreshChromiumSurface(win);
};
win.on("restore", requestSurfaceRefresh);
win.on("show", requestSurfaceRefresh);
app.on("child-process-gone", handleChildProcessGone);
win.once("closed", () => {
win.off("restore", requestSurfaceRefresh);
win.off("show", requestSurfaceRefresh);
app.off("child-process-gone", handleChildProcessGone);
});
}
export function setupDefaultContextMenu(win: BrowserWindow): void {
win.webContents.on("context-menu", (_event, params) => {
const menu = Menu.buildFromTemplate([