Skip to content

Commit 8f96ce6

Browse files
author
Benjamin Pasero
committed
debt - reduce usage of electron remote module
1 parent 9a57f2e commit 8f96ce6

8 files changed

Lines changed: 51 additions & 39 deletions

File tree

src/vs/code/electron-browser/issue/issueReporter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
const path = require('path');
99
const fs = require('fs');
10-
const remote = require('electron').remote;
10+
const ipc = require('electron').ipcRenderer;
1111

1212
function assign(destination, source) {
1313
return Object.keys(source)
@@ -97,9 +97,9 @@ function main() {
9797
window.addEventListener('keydown', function (e) {
9898
const key = extractKey(e);
9999
if (key === TOGGLE_DEV_TOOLS_KB) {
100-
remote.getCurrentWebContents().toggleDevTools();
100+
ipc.send('vscode:toggleDevTools');
101101
} else if (key === RELOAD_KB) {
102-
remote.getCurrentWindow().reload();
102+
ipc.send('vscode:reloadWindow');
103103
}
104104
});
105105

src/vs/code/electron-browser/issue/issueReporterMain.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'use strict';
77

88
import 'vs/css!./media/issueReporter';
9-
import { shell, ipcRenderer, webFrame, remote, clipboard } from 'electron';
9+
import { shell, ipcRenderer, webFrame, clipboard } from 'electron';
1010
import { localize } from 'vs/nls';
1111
import { $ } from 'vs/base/browser/dom';
1212
import * as collections from 'vs/base/common/collections';
@@ -91,7 +91,7 @@ export class IssueReporter extends Disposable {
9191

9292
this.previewButton = new Button(document.getElementById('issue-reporter'));
9393

94-
ipcRenderer.on('issuePerformanceInfoResponse', (event, info) => {
94+
ipcRenderer.on('vscode:issuePerformanceInfoResponse', (event, info) => {
9595
this.logService.trace('issueReporter: Received performance data');
9696
this.issueReporterModel.update(info);
9797
this.receivedPerformanceInfo = true;
@@ -102,7 +102,7 @@ export class IssueReporter extends Disposable {
102102
this.updatePreviewButtonState();
103103
});
104104

105-
ipcRenderer.on('issueSystemInfoResponse', (event, info) => {
105+
ipcRenderer.on('vscode:issueSystemInfoResponse', (event, info) => {
106106
this.logService.trace('issueReporter: Received system data');
107107
this.issueReporterModel.update({ systemInfo: info });
108108
this.receivedSystemInfo = true;
@@ -111,9 +111,9 @@ export class IssueReporter extends Disposable {
111111
this.updatePreviewButtonState();
112112
});
113113

114-
ipcRenderer.send('issueSystemInfoRequest');
114+
ipcRenderer.send('vscode:issueSystemInfoRequest');
115115
if (configuration.data.issueType === IssueType.PerformanceIssue) {
116-
ipcRenderer.send('issuePerformanceInfoRequest');
116+
ipcRenderer.send('vscode:issuePerformanceInfoRequest');
117117
}
118118
this.logService.trace('issueReporter: Sent data requests');
119119

@@ -308,7 +308,7 @@ export class IssueReporter extends Disposable {
308308
const issueType = parseInt((<HTMLInputElement>event.target).value);
309309
this.issueReporterModel.update({ issueType: issueType });
310310
if (issueType === IssueType.PerformanceIssue && !this.receivedPerformanceInfo) {
311-
ipcRenderer.send('issuePerformanceInfoRequest');
311+
ipcRenderer.send('vscode:issuePerformanceInfoRequest');
312312
}
313313
this.updatePreviewButtonState();
314314
this.render();
@@ -384,14 +384,14 @@ export class IssueReporter extends Disposable {
384384
this.previewButton.onDidClick(() => this.createIssue());
385385

386386
this.addEventListener('disableExtensions', 'click', () => {
387-
ipcRenderer.send('workbenchCommand', 'workbench.action.reloadWindowWithExtensionsDisabled');
387+
ipcRenderer.send('vscode:workbenchCommand', 'workbench.action.reloadWindowWithExtensionsDisabled');
388388
});
389389

390390
this.addEventListener('disableExtensions', 'keydown', (e: KeyboardEvent) => {
391391
e.stopPropagation();
392392
if (e.keyCode === 13 || e.keyCode === 32) {
393-
ipcRenderer.send('workbenchCommand', 'workbench.extensions.action.disableAll');
394-
ipcRenderer.send('workbenchCommand', 'workbench.action.reloadWindow');
393+
ipcRenderer.send('vscode:workbenchCommand', 'workbench.extensions.action.disableAll');
394+
ipcRenderer.send('vscode:workbenchCommand', 'workbench.action.reloadWindow');
395395
}
396396
});
397397

@@ -400,7 +400,7 @@ export class IssueReporter extends Disposable {
400400
// Cmd/Ctrl+Enter previews issue and closes window
401401
if (cmdOrCtrlKey && e.keyCode === 13) {
402402
if (this.createIssue()) {
403-
remote.getCurrentWindow().close();
403+
ipcRenderer.send('vscode:closeIssueReporter');
404404
}
405405
}
406406

src/vs/code/electron-browser/processExplorer/processExplorer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
const path = require('path');
99
const fs = require('fs');
10-
const remote = require('electron').remote;
10+
const ipc = require('electron').ipcRenderer;
1111

1212
function assign(destination, source) {
1313
return Object.keys(source)
@@ -141,9 +141,9 @@ function main() {
141141
window.addEventListener('keydown', function (e) {
142142
const key = extractKey(e);
143143
if (key === TOGGLE_DEV_TOOLS_KB) {
144-
remote.getCurrentWebContents().toggleDevTools();
144+
ipc.send('vscode:toggleDevTools');
145145
} else if (key === RELOAD_KB) {
146-
remote.getCurrentWindow().reload();
146+
ipc.send('vscode:reloadWindow');
147147
}
148148
});
149149

src/vs/code/electron-browser/processExplorer/processExplorerMain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export function startup(data: ProcessExplorerData): void {
198198
applyZoom(data.zoomLevel);
199199

200200
// Map window process pids to titles, annotate process names with this when rendering to distinguish between them
201-
ipcRenderer.on('windowsInfoResponse', (event, windows) => {
201+
ipcRenderer.on('vscode:windowsInfoResponse', (event, windows) => {
202202
mapPidToWindowTitle = new Map<number, string>();
203203
windows.forEach(window => mapPidToWindowTitle.set(window.pid, window.title));
204204
});

src/vs/code/electron-browser/proxy/auth.html

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ <h1 id="title"></h1>
7979
</body>
8080

8181
<script>
82-
const electron = require('electron');
83-
const shell = electron.shell;
84-
const ipc = electron.ipcRenderer;
85-
const remote = electron.remote;
86-
const currentWindow = remote.getCurrentWindow();
8782

8883
function promptForCredentials(data) {
8984
return new Promise((c, e) => {

src/vs/code/electron-main/app.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
'use strict';
77

8-
import { app, ipcMain as ipc, systemPreferences, shell } from 'electron';
8+
import { app, ipcMain as ipc, systemPreferences, shell, Event } from 'electron';
99
import * as platform from 'vs/base/common/platform';
1010
import { WindowsManager } from 'vs/code/electron-main/windows';
1111
import { IWindowsService, OpenContext, ActiveWindowManager } from 'vs/platform/windows/common/windows';
@@ -194,15 +194,15 @@ export class CodeApplication {
194194
this.windowsMainService.openNewWindow(OpenContext.DESKTOP); //macOS native tab "+" button
195195
});
196196

197-
ipc.on('vscode:exit', (event: any, code: number) => {
197+
ipc.on('vscode:exit', (event: Event, code: number) => {
198198
this.logService.trace('IPC#vscode:exit', code);
199199

200200
this.dispose();
201201
this.lifecycleService.kill(code);
202202
});
203203

204-
ipc.on('vscode:fetchShellEnv', event => {
205-
const webContents = event.sender.webContents;
204+
ipc.on('vscode:fetchShellEnv', (event: Event) => {
205+
const webContents = event.sender;
206206
getShellEnvironment().then(shellEnv => {
207207
if (!webContents.isDestroyed()) {
208208
webContents.send('vscode:acceptShellEnv', shellEnv);
@@ -216,7 +216,7 @@ export class CodeApplication {
216216
});
217217
});
218218

219-
ipc.on('vscode:broadcast', (event: any, windowId: number, broadcast: { channel: string; payload: any; }) => {
219+
ipc.on('vscode:broadcast', (event: Event, windowId: number, broadcast: { channel: string; payload: any; }) => {
220220
if (this.windowsMainService && broadcast.channel && !isUndefinedOrNull(broadcast.payload)) {
221221
this.logService.trace('IPC#vscode:broadcast', broadcast.channel, broadcast.payload);
222222

@@ -232,6 +232,18 @@ export class CodeApplication {
232232
this.labelService.registerFormater(scheme, formater);
233233
});
234234

235+
ipc.on('vscode:toggleDevTools', (event: Event) => {
236+
event.sender.toggleDevTools();
237+
});
238+
239+
ipc.on('vscode:openDevTools', (event: Event) => {
240+
event.sender.openDevTools();
241+
});
242+
243+
ipc.on('vscode:reloadWindow', (event: Event) => {
244+
event.sender.reload();
245+
});
246+
235247
// Keyboard layout changes
236248
KeyboardLayoutMonitor.INSTANCE.onDidChangeKeyboardLayout(() => {
237249
if (this.windowsMainService) {

src/vs/platform/issue/electron-main/issueService.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { localize } from 'vs/nls';
1010
import * as objects from 'vs/base/common/objects';
1111
import { parseArgs } from 'vs/platform/environment/node/argv';
1212
import { IIssueService, IssueReporterData, IssueReporterFeatures, ProcessExplorerData } from 'vs/platform/issue/common/issue';
13-
import { BrowserWindow, ipcMain, screen } from 'electron';
13+
import { BrowserWindow, ipcMain, screen, Event } from 'electron';
1414
import { ILaunchService } from 'vs/code/electron-main/launch';
1515
import { getPerformanceInfo, PerformanceInfo, getSystemInfo, SystemInfo } from 'vs/code/electron-main/diagnostics';
1616
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
@@ -34,22 +34,28 @@ export class IssueService implements IIssueService {
3434
) { }
3535

3636
openReporter(data: IssueReporterData): TPromise<void> {
37-
ipcMain.on('issueSystemInfoRequest', event => {
37+
ipcMain.on('vscode:issueSystemInfoRequest', (event: Event) => {
3838
this.getSystemInformation().then(msg => {
39-
event.sender.send('issueSystemInfoResponse', msg);
39+
event.sender.send('vscode:issueSystemInfoResponse', msg);
4040
});
4141
});
4242

43-
ipcMain.on('issuePerformanceInfoRequest', event => {
43+
ipcMain.on('vscode:issuePerformanceInfoRequest', (event: Event) => {
4444
this.getPerformanceInfo().then(msg => {
45-
event.sender.send('issuePerformanceInfoResponse', msg);
45+
event.sender.send('vscode:issuePerformanceInfoResponse', msg);
4646
});
4747
});
4848

49-
ipcMain.on('workbenchCommand', (event, arg) => {
49+
ipcMain.on('vscode:workbenchCommand', (event, arg) => {
5050
this._issueParentWindow.webContents.send('vscode:runAction', { id: arg, from: 'issueReporter' });
5151
});
5252

53+
ipcMain.on('vscode:closeIssueReporter', (event: Event) => {
54+
if (this._issueWindow) {
55+
this._issueWindow.close();
56+
}
57+
});
58+
5359
this._issueParentWindow = BrowserWindow.getFocusedWindow();
5460
const position = this.getWindowPosition(this._issueParentWindow, 700, 800);
5561
if (!this._issueWindow) {
@@ -91,9 +97,9 @@ export class IssueService implements IIssueService {
9197
}
9298

9399
openProcessExplorer(data: ProcessExplorerData): TPromise<void> {
94-
ipcMain.on('windowsInfoRequest', event => {
100+
ipcMain.on('windowsInfoRequest', (event: Event) => {
95101
this.launchService.getMainProcessInfo().then(info => {
96-
event.sender.send('windowsInfoResponse', info.windows);
102+
event.sender.send('vscode:windowsInfoResponse', info.windows);
97103
});
98104
});
99105

src/vs/workbench/electron-browser/bootstrap/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ perf.mark('renderer/started');
1313
const path = require('path');
1414
const fs = require('fs');
1515
const electron = require('electron');
16-
const remote = electron.remote;
1716
const ipc = electron.ipcRenderer;
1817

1918
Error.stackTraceLimit = 100; // increase number of stack frames (from 10, https://github.com/v8/v8/wiki/Stack-Trace-API)
@@ -35,7 +34,7 @@ process.lazyEnv = new Promise(function (resolve) {
3534

3635
function onError(error, enableDeveloperTools) {
3736
if (enableDeveloperTools) {
38-
remote.getCurrentWebContents().openDevTools();
37+
ipc.send('vscode:openDevTools');
3938
}
4039

4140
console.error('[uncaught exception]: ' + error);
@@ -168,9 +167,9 @@ function registerListeners(enableDeveloperTools) {
168167
listener = function (e) {
169168
const key = extractKey(e);
170169
if (key === TOGGLE_DEV_TOOLS_KB) {
171-
remote.getCurrentWebContents().toggleDevTools();
170+
ipc.send('vscode:toggleDevTools');
172171
} else if (key === RELOAD_KB) {
173-
remote.getCurrentWindow().reload();
172+
ipc.send('vscode:reloadWindow');
174173
}
175174
};
176175
window.addEventListener('keydown', listener);

0 commit comments

Comments
 (0)