diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 50000e930c8..6a893ef49d3 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -271,6 +271,7 @@ export class CodeApplication extends Disposable { //#region Bootstrap IPC Handlers ipcMain.on('vscode:fetchShellEnv', async event => { + const webContents = event.sender; const window = this.windowsMainService?.getWindowByWebContents(event.sender); let replied = false; @@ -282,7 +283,9 @@ export class CodeApplication extends Disposable { if (!replied) { replied = true; - window?.send('vscode:acceptShellEnv', env); + if (!webContents.isDestroyed()) { + webContents.send('vscode:acceptShellEnv', env); + } } } diff --git a/src/vs/code/electron-main/sharedProcess.ts b/src/vs/code/electron-main/sharedProcess.ts index cba5630273e..989da879644 100644 --- a/src/vs/code/electron-main/sharedProcess.ts +++ b/src/vs/code/electron-main/sharedProcess.ts @@ -14,6 +14,7 @@ import { browserCodeLoadingCacheStrategy } from 'vs/base/common/platform'; import { ISharedProcess, ISharedProcessConfiguration } from 'vs/platform/sharedProcess/node/sharedProcess'; import { Disposable } from 'vs/base/common/lifecycle'; import { connect as connectMessagePort } from 'vs/base/parts/ipc/electron-main/ipc.mp'; +import { assertIsDefined } from 'vs/base/common/types'; export class SharedProcess extends Disposable implements ISharedProcess { @@ -62,9 +63,7 @@ export class SharedProcess extends Disposable implements ISharedProcess { } // Signal exit to shared process when shutting down - if (!window.webContents.isDestroyed()) { - window.webContents.send('vscode:electron-main->shared-process=exit'); - } + window.webContents.send('vscode:electron-main->shared-process=exit'); // Shut the shared process down when we are quitting // @@ -208,13 +207,9 @@ export class SharedProcess extends Disposable implements ISharedProcess { // Wait for shared process being ready to accept connection await this.whenIpcReady; - // Assert healthy shared process window - if (!this.window || this.window.webContents.isDestroyed()) { - throw new Error('Cannot connect to shared process window because the window is closed or destroyed'); - } - // Connect and return message port - return connectMessagePort(this.window); + const window = assertIsDefined(this.window); + return connectMessagePort(window); } async toggle(): Promise { diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index 068bbf03a8e..357229c46a5 100644 --- a/src/vs/code/electron-main/window.ts +++ b/src/vs/code/electron-main/window.ts @@ -1254,11 +1254,6 @@ export class CodeWindow extends Disposable implements ICodeWindow { send(channel: string, ...args: any[]): void { if (this._win) { - if (this._win.isDestroyed()) { - this.logService.warn(`Sending IPC message to channel ${channel} for window that is destroyed`); - return; - } - this._win.webContents.send(channel, ...args); } }