Skip to content

Commit 9eb9907

Browse files
author
Benjamin Pasero
committed
sandbox - further reduce electron dependencies
1 parent 246d259 commit 9eb9907

30 files changed

Lines changed: 335 additions & 36 deletions

File tree

build/gulpfile.vscode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ function packageTask(platform, arch, sourceFolderName, destinationFolderName, op
154154
const out = sourceFolderName;
155155

156156
const checksums = computeChecksums(out, [
157+
'vs/base/parts/sandbox/electron-browser/preload.js',
157158
'vs/workbench/workbench.desktop.main.js',
158159
'vs/workbench/workbench.desktop.main.css',
159160
'vs/workbench/services/extensions/node/extensionHostProcess.js',
160-
'vs/code/electron-browser/preload.js',
161161
'vs/code/electron-browser/workbench/workbench.html',
162162
'vs/code/electron-browser/workbench/workbench.js'
163163
]);

src/vs/base/parts/contextmenu/electron-sandbox/contextmenu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { ipcRenderer } from 'vs/base/electron-sandbox/globals';
6+
import { ipcRenderer } from 'vs/base/parts/sandbox/electron-sandbox/globals';
77
import { IContextMenuItem, ISerializableContextMenuItem, CONTEXT_MENU_CLOSE_CHANNEL, CONTEXT_MENU_CHANNEL, IPopupOptions, IContextMenuEvent } from 'vs/base/parts/contextmenu/common/contextmenu';
88

99
let contextMenuIdPool = 0;

src/vs/base/parts/ipc/electron-sandbox/ipc.electron-sandbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { IPCClient } from 'vs/base/parts/ipc/common/ipc';
88
import { Protocol } from 'vs/base/parts/ipc/common/ipc.electron';
99
import { IDisposable } from 'vs/base/common/lifecycle';
1010
import { VSBuffer } from 'vs/base/common/buffer';
11-
import { ipcRenderer } from 'vs/base/electron-sandbox/globals';
11+
import { ipcRenderer } from 'vs/base/parts/sandbox/electron-sandbox/globals';
1212

1313
export class Client extends IPCClient implements IDisposable {
1414

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
7+
// #######################################################################
8+
// ### ###
9+
// ### electron.d.ts types we need in a common layer for reuse ###
10+
// ### (copied from Electron 8.3.0) ###
11+
// ### ###
12+
// #######################################################################
13+
14+
15+
export interface MessageBoxOptions {
16+
/**
17+
* Can be `"none"`, `"info"`, `"error"`, `"question"` or `"warning"`. On Windows,
18+
* `"question"` displays the same icon as `"info"`, unless you set an icon using
19+
* the `"icon"` option. On macOS, both `"warning"` and `"error"` display the same
20+
* warning icon.
21+
*/
22+
type?: string;
23+
/**
24+
* Array of texts for buttons. On Windows, an empty array will result in one button
25+
* labeled "OK".
26+
*/
27+
buttons?: string[];
28+
/**
29+
* Index of the button in the buttons array which will be selected by default when
30+
* the message box opens.
31+
*/
32+
defaultId?: number;
33+
/**
34+
* Title of the message box, some platforms will not show it.
35+
*/
36+
title?: string;
37+
/**
38+
* Content of the message box.
39+
*/
40+
message: string;
41+
/**
42+
* Extra information of the message.
43+
*/
44+
detail?: string;
45+
/**
46+
* If provided, the message box will include a checkbox with the given label.
47+
*/
48+
checkboxLabel?: string;
49+
/**
50+
* Initial checked state of the checkbox. `false` by default.
51+
*/
52+
checkboxChecked?: boolean;
53+
// icon?: NativeImage;
54+
/**
55+
* The index of the button to be used to cancel the dialog, via the `Esc` key. By
56+
* default this is assigned to the first button with "cancel" or "no" as the label.
57+
* If no such labeled buttons exist and this option is not set, `0` will be used as
58+
* the return value.
59+
*/
60+
cancelId?: number;
61+
/**
62+
* On Windows Electron will try to figure out which one of the `buttons` are common
63+
* buttons (like "Cancel" or "Yes"), and show the others as command links in the
64+
* dialog. This can make the dialog appear in the style of modern Windows apps. If
65+
* you don't like this behavior, you can set `noLink` to `true`.
66+
*/
67+
noLink?: boolean;
68+
/**
69+
* Normalize the keyboard access keys across platforms. Default is `false`.
70+
* Enabling this assumes `&` is used in the button labels for the placement of the
71+
* keyboard shortcut access key and labels will be converted so they work correctly
72+
* on each platform, `&` characters are removed on macOS, converted to `_` on
73+
* Linux, and left untouched on Windows. For example, a button label of `Vie&w`
74+
* will be converted to `Vie_w` on Linux and `View` on macOS and can be selected
75+
* via `Alt-W` on Windows and Linux.
76+
*/
77+
normalizeAccessKeys?: boolean;
78+
}
79+
80+
export interface MessageBoxReturnValue {
81+
/**
82+
* The index of the clicked button.
83+
*/
84+
response: number;
85+
/**
86+
* The checked state of the checkbox if `checkboxLabel` was set. Otherwise `false`.
87+
*/
88+
checkboxChecked: boolean;
89+
}
90+
91+
export interface OpenDevToolsOptions {
92+
/**
93+
* Opens the devtools with specified dock state, can be `right`, `bottom`,
94+
* `undocked`, `detach`. Defaults to last used dock state. In `undocked` mode it's
95+
* possible to dock back. In `detach` mode it's not.
96+
*/
97+
mode: ('right' | 'bottom' | 'undocked' | 'detach');
98+
/**
99+
* Whether to bring the opened devtools window to the foreground. The default is
100+
* `true`.
101+
*/
102+
activate?: boolean;
103+
}
104+
105+
export interface SaveDialogOptions {
106+
title?: string;
107+
/**
108+
* Absolute directory path, absolute file path, or file name to use by default.
109+
*/
110+
defaultPath?: string;
111+
/**
112+
* Custom label for the confirmation button, when left empty the default label will
113+
* be used.
114+
*/
115+
buttonLabel?: string;
116+
filters?: FileFilter[];
117+
/**
118+
* Message to display above text fields.
119+
*
120+
* @platform darwin
121+
*/
122+
message?: string;
123+
/**
124+
* Custom label for the text displayed in front of the filename text field.
125+
*
126+
* @platform darwin
127+
*/
128+
nameFieldLabel?: string;
129+
/**
130+
* Show the tags input box, defaults to `true`.
131+
*
132+
* @platform darwin
133+
*/
134+
showsTagField?: boolean;
135+
properties?: Array<'showHiddenFiles' | 'createDirectory' | 'treatPackageAsDirectory' | 'showOverwriteConfirmation' | 'dontAddToRecent'>;
136+
/**
137+
* Create a security scoped bookmark when packaged for the Mac App Store. If this
138+
* option is enabled and the file doesn't already exist a blank file will be
139+
* created at the chosen path.
140+
*
141+
* @platform darwin,mas
142+
*/
143+
securityScopedBookmarks?: boolean;
144+
}
145+
146+
export interface OpenDialogOptions {
147+
title?: string;
148+
defaultPath?: string;
149+
/**
150+
* Custom label for the confirmation button, when left empty the default label will
151+
* be used.
152+
*/
153+
buttonLabel?: string;
154+
filters?: FileFilter[];
155+
/**
156+
* Contains which features the dialog should use. The following values are
157+
* supported:
158+
*/
159+
properties?: Array<'openFile' | 'openDirectory' | 'multiSelections' | 'showHiddenFiles' | 'createDirectory' | 'promptToCreate' | 'noResolveAliases' | 'treatPackageAsDirectory' | 'dontAddToRecent'>;
160+
/**
161+
* Message to display above input boxes.
162+
*
163+
* @platform darwin
164+
*/
165+
message?: string;
166+
/**
167+
* Create security scoped bookmarks when packaged for the Mac App Store.
168+
*
169+
* @platform darwin,mas
170+
*/
171+
securityScopedBookmarks?: boolean;
172+
}
173+
174+
export interface OpenDialogReturnValue {
175+
/**
176+
* whether or not the dialog was canceled.
177+
*/
178+
canceled: boolean;
179+
/**
180+
* An array of file paths chosen by the user. If the dialog is cancelled this will
181+
* be an empty array.
182+
*/
183+
filePaths: string[];
184+
/**
185+
* An array matching the `filePaths` array of base64 encoded strings which contains
186+
* security scoped bookmark data. `securityScopedBookmarks` must be enabled for
187+
* this to be populated. (For return values, see table here.)
188+
*
189+
* @platform darwin,mas
190+
*/
191+
bookmarks?: string[];
192+
}
193+
194+
export interface SaveDialogReturnValue {
195+
/**
196+
* whether or not the dialog was canceled.
197+
*/
198+
canceled: boolean;
199+
/**
200+
* If the dialog is canceled, this will be `undefined`.
201+
*/
202+
filePath?: string;
203+
/**
204+
* Base64 encoded string which contains the security scoped bookmark data for the
205+
* saved file. `securityScopedBookmarks` must be enabled for this to be present.
206+
* (For return values, see table here.)
207+
*
208+
* @platform darwin,mas
209+
*/
210+
bookmark?: string;
211+
}
212+
213+
export interface CrashReporterStartOptions {
214+
companyName: string;
215+
/**
216+
* URL that crash reports will be sent to as POST.
217+
*/
218+
submitURL: string;
219+
/**
220+
* Defaults to `app.name`.
221+
*/
222+
productName?: string;
223+
/**
224+
* Whether crash reports should be sent to the server. Default is `true`.
225+
*/
226+
uploadToServer?: boolean;
227+
/**
228+
* Default is `false`.
229+
*/
230+
ignoreSystemCrashHandler?: boolean;
231+
/**
232+
* An object you can define that will be sent along with the report. Only string
233+
* properties are sent correctly. Nested objects are not supported. When using
234+
* Windows, the property names and values must be fewer than 64 characters.
235+
*/
236+
extra?: Record<string, string>;
237+
/**
238+
* Directory to store the crash reports temporarily (only used when the crash
239+
* reporter is started via `process.crashReporter.start`).
240+
*/
241+
crashesDirectory?: string;
242+
}
243+
244+
export interface FileFilter {
245+
246+
// Docs: http://electronjs.org/docs/api/structures/file-filter
247+
248+
extensions: string[];
249+
name: string;
250+
}

src/vs/code/electron-browser/preload.js renamed to src/vs/base/parts/sandbox/electron-browser/preload.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
(function () {
88
'use strict';
99

10-
const { ipcRenderer, webFrame } = require('electron');
10+
const { ipcRenderer, webFrame, crashReporter } = require('electron');
1111

1212
// @ts-ignore
1313
window.vscode = {
@@ -16,7 +16,7 @@
1616
* A minimal set of methods exposed from ipcRenderer
1717
* to support communication to electron-main
1818
*
19-
* @type {typeof import('../../base/electron-sandbox/globals').ipcRenderer}
19+
* @type {typeof import('../electron-sandbox/globals').ipcRenderer}
2020
*/
2121
ipcRenderer: {
2222

@@ -64,7 +64,7 @@
6464
/**
6565
* Support for methods of webFrame type.
6666
*
67-
* @type {typeof import('../../base/electron-sandbox/globals').webFrame}
67+
* @type {typeof import('../electron-sandbox/globals').webFrame}
6868
*/
6969
webFrame: {
7070

@@ -82,6 +82,21 @@
8282
setZoomLevel(level) {
8383
webFrame.setZoomLevel(level);
8484
}
85+
},
86+
87+
/**
88+
* Support for methods of crashReporter type.
89+
*
90+
* @type {typeof import('../electron-sandbox/globals').crashReporter}
91+
*/
92+
crashReporter: {
93+
94+
/**
95+
* @param {Electron.CrashReporterStartOptions} options
96+
*/
97+
start(options) {
98+
crashReporter.start(options);
99+
}
85100
}
86101
};
87102

src/vs/base/electron-sandbox/globals.ts renamed to src/vs/base/parts/sandbox/electron-sandbox/globals.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { CrashReporterStartOptions } from 'vs/base/parts/sandbox/common/electronTypes';
7+
68
export const ipcRenderer = (window as any).vscode.ipcRenderer as {
79

810
/**
@@ -58,3 +60,34 @@ export const webFrame = (window as any).vscode.webFrame as {
5860
*/
5961
setZoomLevel(level: number): void;
6062
};
63+
64+
export const crashReporter = (window as any).vscode.crashReporter as {
65+
66+
/**
67+
* You are required to call this method before using any other `crashReporter` APIs
68+
* and in each process (main/renderer) from which you want to collect crash
69+
* reports. You can pass different options to `crashReporter.start` when calling
70+
* from different processes.
71+
*
72+
* **Note** Child processes created via the `child_process` module will not have
73+
* access to the Electron modules. Therefore, to collect crash reports from them,
74+
* use `process.crashReporter.start` instead. Pass the same options as above along
75+
* with an additional one called `crashesDirectory` that should point to a
76+
* directory to store the crash reports temporarily. You can test this out by
77+
* calling `process.crash()` to crash the child process.
78+
*
79+
* **Note:** If you need send additional/updated `extra` parameters after your
80+
* first call `start` you can call `addExtraParameter` on macOS or call `start`
81+
* again with the new/updated `extra` parameters on Linux and Windows.
82+
*
83+
* **Note:** On macOS and windows, Electron uses a new `crashpad` client for crash
84+
* collection and reporting. If you want to enable crash reporting, initializing
85+
* `crashpad` from the main process using `crashReporter.start` is required
86+
* regardless of which process you want to collect crashes from. Once initialized
87+
* this way, the crashpad handler collects crashes from all processes. You still
88+
* have to call `crashReporter.start` from the renderer or child process, otherwise
89+
* crashes from them will get reported without `companyName`, `productName` or any
90+
* of the `extra` information.
91+
*/
92+
start(options: CrashReporterStartOptions): void;
93+
};

0 commit comments

Comments
 (0)