diff --git a/src/vs/workbench/electron-main/lifecycle.ts b/src/vs/workbench/electron-main/lifecycle.ts index 4d0cbc3f5f6..b1963df8953 100644 --- a/src/vs/workbench/electron-main/lifecycle.ts +++ b/src/vs/workbench/electron-main/lifecycle.ts @@ -133,7 +133,7 @@ export class Lifecycle { c(true); // veto }); - vscodeWindow.win.webContents.send('vscode:beforeUnload', { okChannel: oneTimeOkEvent, cancelChannel: oneTimeCancelEvent }); + vscodeWindow.send('vscode:beforeUnload', { okChannel: oneTimeOkEvent, cancelChannel: oneTimeCancelEvent }); }); } diff --git a/src/vs/workbench/electron-main/menus.ts b/src/vs/workbench/electron-main/menus.ts index 0187db6b3ac..3a233e4eb2a 100644 --- a/src/vs/workbench/electron-main/menus.ts +++ b/src/vs/workbench/electron-main/menus.ts @@ -119,7 +119,7 @@ export class VSCodeMenu { // Resolve keybindings when workbench window is up if (this.actionIdKeybindingRequests.length) { - win.win.webContents.send('vscode:resolveKeybindings', JSON.stringify(this.actionIdKeybindingRequests)); + win.send('vscode:resolveKeybindings', JSON.stringify(this.actionIdKeybindingRequests)); } } diff --git a/src/vs/workbench/electron-main/window.ts b/src/vs/workbench/electron-main/window.ts index 066fba4d282..7bd14c3c996 100644 --- a/src/vs/workbench/electron-main/window.ts +++ b/src/vs/workbench/electron-main/window.ts @@ -294,9 +294,9 @@ export class VSCodeWindow { // Support navigation via mouse buttons 4/5 if (cmd === 'browser-backward') { - this._win.webContents.send('vscode:runAction', 'workbench.action.navigateBack'); + this.send('vscode:runAction', 'workbench.action.navigateBack'); } else if (cmd === 'browser-forward') { - this._win.webContents.send('vscode:runAction', 'workbench.action.navigateForward'); + this.send('vscode:runAction', 'workbench.action.navigateForward'); } }); @@ -532,6 +532,16 @@ export class VSCodeWindow { this.win.setMenuBarVisibility(isFullScreen); } + public sendWhenReady(channel: string, ...args: any[]): void { + this.ready().then(() => { + this.send(channel, ...args); + }); + } + + public send(channel: string, ...args: any[]): void { + this._win.webContents.send(channel, ...args); + } + public dispose(): void { if (this.showTimeoutHandle) { clearTimeout(this.showTimeoutHandle); diff --git a/src/vs/workbench/electron-main/windows.ts b/src/vs/workbench/electron-main/windows.ts index f928b91863f..308f5603a4c 100644 --- a/src/vs/workbench/electron-main/windows.ts +++ b/src/vs/workbench/electron-main/windows.ts @@ -390,13 +390,13 @@ export class WindowsManager { if (!openFilesInNewWindow && lastActiveWindow) { lastActiveWindow.restore(); lastActiveWindow.ready().then((readyWindow) => { - readyWindow.win.webContents.send('vscode:openFiles', { + readyWindow.send('vscode:openFiles', { filesToOpen: filesToOpen, filesToCreate: filesToCreate }); if (extensionsToInstall.length) { - readyWindow.win.webContents.send('vscode:installExtensions', { extensionsToInstall }); + readyWindow.send('vscode:installExtensions', { extensionsToInstall }); } }); } @@ -418,13 +418,13 @@ export class WindowsManager { if (windowsOnWorkspacePath.length > 0) { windowsOnWorkspacePath[0].restore(); // just focus one of them windowsOnWorkspacePath[0].ready().then((readyWindow) => { - readyWindow.win.webContents.send('vscode:openFiles', { + readyWindow.send('vscode:openFiles', { filesToOpen: filesToOpen, filesToCreate: filesToCreate }); if (extensionsToInstall.length) { - readyWindow.win.webContents.send('vscode:installExtensions', { extensionsToInstall }); + readyWindow.send('vscode:installExtensions', { extensionsToInstall }); } }); @@ -889,9 +889,7 @@ export class WindowsManager { const focusedWindow = this.getFocusedWindow() || this.getLastActiveWindow(); if (focusedWindow) { - focusedWindow.ready().then((readyWindow) => { - readyWindow.win.webContents.send(channel, ...args); - }); + focusedWindow.sendWhenReady(channel, ...args); } } @@ -901,9 +899,7 @@ export class WindowsManager { return; // do not send if we are instructed to ignore it } - w.ready().then((readyWindow) => { - readyWindow.win.webContents.send(channel, payload); - }); + w.sendWhenReady(channel, payload); }); }