From 49ac8858aa5530667c34d502f90f4f827d0e85c2 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Fri, 14 Jun 2019 15:24:42 -0700 Subject: [PATCH] fix: update ipcMain event and promisifiy dialog apis https://github.com/electron/electron/pull/17038 https://github.com/electron/electron/pull/17298 --- .../contextmenu/electron-main/contextmenu.ts | 6 +-- src/vs/code/electron-main/app.ts | 8 ++-- .../issue/electron-main/issueService.ts | 46 +++++++++++-------- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/vs/base/parts/contextmenu/electron-main/contextmenu.ts b/src/vs/base/parts/contextmenu/electron-main/contextmenu.ts index f375750dc2032..c30d26522af59 100644 --- a/src/vs/base/parts/contextmenu/electron-main/contextmenu.ts +++ b/src/vs/base/parts/contextmenu/electron-main/contextmenu.ts @@ -3,11 +3,11 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { Menu, MenuItem, BrowserWindow, Event, ipcMain } from 'electron'; +import { Menu, MenuItem, BrowserWindow, ipcMain } from 'electron'; import { ISerializableContextMenuItem, CONTEXT_MENU_CLOSE_CHANNEL, CONTEXT_MENU_CHANNEL, IPopupOptions } from 'vs/base/parts/contextmenu/common/contextmenu'; export function registerContextMenuListener(): void { - ipcMain.on(CONTEXT_MENU_CHANNEL, (event: Event, contextMenuId: number, items: ISerializableContextMenuItem[], onClickChannel: string, options?: IPopupOptions) => { + ipcMain.on(CONTEXT_MENU_CHANNEL, (event: Electron.IpcMainEvent, contextMenuId: number, items: ISerializableContextMenuItem[], onClickChannel: string, options?: IPopupOptions) => { const menu = createMenu(event, onClickChannel, items); menu.popup({ @@ -27,7 +27,7 @@ export function registerContextMenuListener(): void { }); } -function createMenu(event: Event, onClickChannel: string, items: ISerializableContextMenuItem[]): Menu { +function createMenu(event: Electron.IpcMainEvent, onClickChannel: string, items: ISerializableContextMenuItem[]): Menu { const menu = new Menu(); items.forEach(item => { diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index bf75167101e20..6fb21597b0164 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -226,7 +226,7 @@ export class CodeApplication extends Disposable { this.lifecycleService.kill(code); }); - ipc.on('vscode:fetchShellEnv', async (event: Event) => { + ipc.on('vscode:fetchShellEnv', async (event: Electron.IpcMainEvent) => { const webContents = event.sender; try { @@ -249,10 +249,10 @@ export class CodeApplication extends Disposable { } }); - ipc.on('vscode:toggleDevTools', (event: Event) => event.sender.toggleDevTools()); - ipc.on('vscode:openDevTools', (event: Event) => event.sender.openDevTools()); + ipc.on('vscode:toggleDevTools', (event: Electron.IpcMainEvent) => event.sender.toggleDevTools()); + ipc.on('vscode:openDevTools', (event: Electron.IpcMainEvent) => event.sender.openDevTools()); - ipc.on('vscode:reloadWindow', (event: Event) => event.sender.reload()); + ipc.on('vscode:reloadWindow', (event: Electron.IpcMainEvent) => event.sender.reload()); // After waking up from sleep (after window opened) (async () => { diff --git a/src/vs/platform/issue/electron-main/issueService.ts b/src/vs/platform/issue/electron-main/issueService.ts index b794f8ffc8ade..f353dc1108363 100644 --- a/src/vs/platform/issue/electron-main/issueService.ts +++ b/src/vs/platform/issue/electron-main/issueService.ts @@ -7,7 +7,7 @@ import { localize } from 'vs/nls'; import * as objects from 'vs/base/common/objects'; import { parseArgs } from 'vs/platform/environment/node/argv'; import { IIssueService, IssueReporterData, IssueReporterFeatures, ProcessExplorerData } from 'vs/platform/issue/common/issue'; -import { BrowserWindow, ipcMain, screen, Event, dialog } from 'electron'; +import { BrowserWindow, ipcMain, screen, dialog } from 'electron'; import { ILaunchService } from 'vs/platform/launch/electron-main/launchService'; import { PerformanceInfo, IDiagnosticsService } from 'vs/platform/diagnostics/electron-main/diagnosticsService'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; @@ -40,13 +40,13 @@ export class IssueService implements IIssueService { } private registerListeners(): void { - ipcMain.on('vscode:issueSystemInfoRequest', (event: Event) => { + ipcMain.on('vscode:issueSystemInfoRequest', (event: Electron.IpcMainEvent) => { this.diagnosticsService.getSystemInfo(this.launchService).then(msg => { event.sender.send('vscode:issueSystemInfoResponse', msg); }); }); - ipcMain.on('vscode:listProcesses', async (event: Event) => { + ipcMain.on('vscode:listProcesses', async (event: Electron.IpcMainEvent) => { const processes = []; try { @@ -75,7 +75,7 @@ export class IssueService implements IIssueService { event.sender.send('vscode:listProcessesResponse', processes); }); - ipcMain.on('vscode:issueReporterClipboard', (event: Event) => { + ipcMain.on('vscode:issueReporterClipboard', (event: Electron.IpcMainEvent) => { const messageOptions = { message: localize('issueReporterWriteToClipboard', "There is too much data to send to GitHub. Would you like to write the information to the clipboard so that it can be pasted?"), type: 'warning', @@ -86,13 +86,14 @@ export class IssueService implements IIssueService { }; if (this._issueWindow) { - dialog.showMessageBox(this._issueWindow, messageOptions, response => { - event.sender.send('vscode:issueReporterClipboardResponse', response === 0); - }); + dialog.showMessageBox(this._issueWindow, messageOptions) + .then(result => { + event.sender.send('vscode:issueReporterClipboardResponse', result.response === 0); + }); } }); - ipcMain.on('vscode:issuePerformanceInfoRequest', (event: Event) => { + ipcMain.on('vscode:issuePerformanceInfoRequest', (event: Electron.IpcMainEvent) => { this.getPerformanceInfo().then(msg => { event.sender.send('vscode:issuePerformanceInfoResponse', msg); }); @@ -109,14 +110,15 @@ export class IssueService implements IIssueService { }; if (this._issueWindow) { - dialog.showMessageBox(this._issueWindow, messageOptions, (response) => { - if (response === 0) { - if (this._issueWindow) { - this._issueWindow.destroy(); - this._issueWindow = null; + dialog.showMessageBox(this._issueWindow, messageOptions) + .then(result => { + if (result.response === 0) { + if (this._issueWindow) { + this._issueWindow.destroy(); + this._issueWindow = null; + } } - } - }); + }); } }); @@ -144,13 +146,13 @@ export class IssueService implements IIssueService { this.windowsService.openExternal(arg); }); - ipcMain.on('vscode:closeIssueReporter', (event: Event) => { + ipcMain.on('vscode:closeIssueReporter', (event: Electron.IpcMainEvent) => { if (this._issueWindow) { this._issueWindow.close(); } }); - ipcMain.on('windowsInfoRequest', (event: Event) => { + ipcMain.on('windowsInfoRequest', (event: Electron.IpcMainEvent) => { this.launchService.getMainProcessInfo().then(info => { event.sender.send('vscode:windowsInfoResponse', info.windows); }); @@ -174,7 +176,10 @@ export class IssueService implements IIssueService { x: position.x, y: position.y, title: localize('issueReporter', "Issue Reporter"), - backgroundColor: data.styles.backgroundColor || DEFAULT_BACKGROUND_COLOR + backgroundColor: data.styles.backgroundColor || DEFAULT_BACKGROUND_COLOR, + webPreferences: { + nodeIntegration: true + } }); this._issueWindow.setMenuBarVisibility(false); // workaround for now, until a menu is implemented @@ -220,7 +225,10 @@ export class IssueService implements IIssueService { x: position.x, y: position.y, backgroundColor: data.styles.backgroundColor, - title: localize('processExplorer', "Process Explorer") + title: localize('processExplorer', "Process Explorer"), + webPreferences: { + nodeIntegration: true + } }); this._processExplorerWindow.setMenuBarVisibility(false);