Skip to content

Commit

Permalink
fix: update ipcMain event and promisifiy dialog apis
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 committed Jun 14, 2019
1 parent 04df1d4 commit 49ac885
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
6 changes: 3 additions & 3 deletions src/vs/base/parts/contextmenu/electron-main/contextmenu.ts
Expand Up @@ -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({
Expand All @@ -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 => {
Expand Down
8 changes: 4 additions & 4 deletions src/vs/code/electron-main/app.ts
Expand Up @@ -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 {
Expand All @@ -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 () => {
Expand Down
46 changes: 27 additions & 19 deletions src/vs/platform/issue/electron-main/issueService.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
Expand All @@ -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);
});
Expand All @@ -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;
}
}
}
});
});
}
});

Expand Down Expand Up @@ -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);
});
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 49ac885

Please sign in to comment.