Skip to content

Commit 97a9b02

Browse files
author
Benjamin Pasero
committed
sandbox - add windowId to electron service
1 parent de1c06c commit 97a9b02

20 files changed

Lines changed: 67 additions & 36 deletions

File tree

src/vs/base/parts/ipc/common/ipc.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,12 @@ export interface IChannelSenderOptions extends IBaseChannelOptions {
10021002
* to each method call to the target.
10031003
*/
10041004
context?: unknown;
1005+
1006+
/**
1007+
* If provided, will not proxy any of the properties
1008+
* that are part of the Map but rather return that value.
1009+
*/
1010+
properties?: Map<string, unknown>;
10051011
}
10061012

10071013
export function createChannelSender<T>(channel: IChannel, options?: IChannelSenderOptions): T {
@@ -1011,6 +1017,11 @@ export function createChannelSender<T>(channel: IChannel, options?: IChannelSend
10111017
get(_target: T, propKey: PropertyKey) {
10121018
if (typeof propKey === 'string') {
10131019

1020+
// Check for predefined values
1021+
if (options?.properties?.has(propKey)) {
1022+
return options.properties.get(propKey);
1023+
}
1024+
10141025
// Event
10151026
if (propertyIsEvent(propKey)) {
10161027
return channel.listen(propKey);

src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ const eventPrefix = 'monacoworkbench';
9191
class MainProcessService implements IMainProcessService {
9292

9393
constructor(
94-
public readonly windowId: number,
9594
private server: Server,
9695
private mainRouter: StaticRouter
9796
) { }
@@ -126,7 +125,7 @@ async function main(server: Server, initData: ISharedProcessInitData, configurat
126125
disposables.add(logService);
127126
logService.info('main', JSON.stringify(configuration));
128127

129-
const mainProcessService = new MainProcessService(configuration.windowId, server, mainRouter);
128+
const mainProcessService = new MainProcessService(server, mainRouter);
130129
services.set(IMainProcessService, mainProcessService);
131130

132131
// Files

src/vs/platform/electron/common/electron.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ export interface IElectronService {
1616

1717
_serviceBrand: undefined;
1818

19+
// Properties
20+
readonly windowId: number;
21+
1922
// Events
2023
readonly onWindowOpen: Event<number>;
2124

src/vs/platform/electron/electron-main/electronMainService.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ export class ElectronMainService implements IElectronMainService {
4141
) {
4242
}
4343

44+
//#region Properties
45+
46+
get windowId(): never { throw new Error('Not implemented in electron-main'); }
47+
48+
//#endregion
49+
4450
//#region Events
4551

4652
readonly onWindowOpen: Event<number> = Event.filter(Event.fromNodeEventEmitter(app, 'browser-window-created', (_, window: BrowserWindow) => window.id), windowId => !!this.windowsMainService.getWindowById(windowId));

src/vs/platform/ipc/common/mainProcessService.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export interface IMainProcessService {
1212

1313
_serviceBrand: undefined;
1414

15-
readonly windowId: number;
16-
1715
getChannel(channelName: string): IChannel;
1816

1917
registerChannel(channelName: string, channel: IServerChannel<string>): void;

src/vs/platform/ipc/electron-sandbox/mainProcessService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class MainProcessService extends Disposable implements IMainProcessServic
1515
private mainProcessConnection: Client;
1616

1717
constructor(
18-
public readonly windowId: number
18+
windowId: number
1919
) {
2020
super();
2121

src/vs/workbench/contrib/splash/electron-browser/partsSplash.contribution.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
2626
import * as perf from 'vs/base/common/performance';
2727
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService';
2828
import { assertIsDefined } from 'vs/base/common/types';
29+
import { IElectronService } from 'vs/platform/electron/common/electron';
2930

3031
class PartsSplash {
3132

@@ -45,6 +46,7 @@ class PartsSplash {
4546
@ILifecycleService lifecycleService: ILifecycleService,
4647
@IEditorGroupsService editorGroupsService: IEditorGroupsService,
4748
@IConfigurationService configService: IConfigurationService,
49+
@IElectronService private readonly _electronService: IElectronService
4850
) {
4951
lifecycleService.when(LifecyclePhase.Restored).then(_ => {
5052
this._removePartsSplash();
@@ -112,7 +114,7 @@ class PartsSplash {
112114
// the color needs to be in hex
113115
const backgroundColor = this._themeService.getColorTheme().getColor(editorBackground) || themes.WORKBENCH_BACKGROUND(this._themeService.getColorTheme());
114116
const payload = JSON.stringify({ baseTheme, background: Color.Format.CSS.formatHex(backgroundColor) });
115-
ipcRenderer.send('vscode:changeColorTheme', this._envService.configuration.windowId, payload);
117+
ipcRenderer.send('vscode:changeColorTheme', this._electronService.windowId, payload);
116118
}
117119
}
118120

src/vs/workbench/electron-browser/actions/windowActions.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import { ICommandHandler } from 'vs/platform/commands/common/commands';
2020
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
2121
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2222
import { IElectronService } from 'vs/platform/electron/common/electron';
23-
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-browser/environmentService';
24-
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
2523
import { Codicon } from 'vs/base/common/codicons';
2624

2725
export class CloseCurrentWindowAction extends Action {
@@ -169,7 +167,6 @@ export abstract class BaseSwitchWindow extends Action {
169167
constructor(
170168
id: string,
171169
label: string,
172-
private readonly environmentService: INativeWorkbenchEnvironmentService,
173170
private readonly quickInputService: IQuickInputService,
174171
private readonly keybindingService: IKeybindingService,
175172
private readonly modelService: IModelService,
@@ -182,7 +179,7 @@ export abstract class BaseSwitchWindow extends Action {
182179
protected abstract isQuickNavigate(): boolean;
183180

184181
async run(): Promise<void> {
185-
const currentWindowId = this.environmentService.configuration.windowId;
182+
const currentWindowId = this.electronService.windowId;
186183

187184
const windows = await this.electronService.getWindows();
188185
const placeHolder = nls.localize('switchWindowPlaceHolder', "Select a window to switch to");
@@ -225,14 +222,13 @@ export class SwitchWindow extends BaseSwitchWindow {
225222
constructor(
226223
id: string,
227224
label: string,
228-
@IWorkbenchEnvironmentService environmentService: INativeWorkbenchEnvironmentService,
229225
@IQuickInputService quickInputService: IQuickInputService,
230226
@IKeybindingService keybindingService: IKeybindingService,
231227
@IModelService modelService: IModelService,
232228
@IModeService modeService: IModeService,
233229
@IElectronService electronService: IElectronService
234230
) {
235-
super(id, label, environmentService, quickInputService, keybindingService, modelService, modeService, electronService);
231+
super(id, label, quickInputService, keybindingService, modelService, modeService, electronService);
236232
}
237233

238234
protected isQuickNavigate(): boolean {
@@ -248,14 +244,13 @@ export class QuickSwitchWindow extends BaseSwitchWindow {
248244
constructor(
249245
id: string,
250246
label: string,
251-
@IWorkbenchEnvironmentService environmentService: INativeWorkbenchEnvironmentService,
252247
@IQuickInputService quickInputService: IQuickInputService,
253248
@IKeybindingService keybindingService: IKeybindingService,
254249
@IModelService modelService: IModelService,
255250
@IModeService modeService: IModeService,
256251
@IElectronService electronService: IElectronService
257252
) {
258-
super(id, label, environmentService, quickInputService, keybindingService, modelService, modeService, electronService);
253+
super(id, label, quickInputService, keybindingService, modelService, modeService, electronService);
259254
}
260255

261256
protected isQuickNavigate(): boolean {

src/vs/workbench/electron-browser/desktop.main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class DesktopMain extends Disposable {
199199
serviceCollection.set(IRemoteAgentService, remoteAgentService);
200200

201201
// Electron
202-
const electronService = new ElectronService(mainProcessService) as IElectronService;
202+
const electronService = new ElectronService(this.configuration.windowId, mainProcessService) as IElectronService;
203203
serviceCollection.set(IElectronService, electronService);
204204

205205
// Files

src/vs/workbench/electron-browser/window.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ export class NativeWindow extends Disposable {
285285

286286
// Detect minimize / maximize
287287
this._register(Event.any(
288-
Event.map(Event.filter(this.electronService.onWindowMaximize, id => id === this.environmentService.configuration.windowId), () => true),
289-
Event.map(Event.filter(this.electronService.onWindowUnmaximize, id => id === this.environmentService.configuration.windowId), () => false)
288+
Event.map(Event.filter(this.electronService.onWindowMaximize, id => id === this.electronService.windowId), () => true),
289+
Event.map(Event.filter(this.electronService.onWindowUnmaximize, id => id === this.electronService.windowId), () => false)
290290
)(e => this.onDidChangeMaximized(e)));
291291

292292
this.onDidChangeMaximized(this.environmentService.configuration.maximized ?? false);
@@ -400,7 +400,7 @@ export class NativeWindow extends Disposable {
400400
this.setupOpenHandlers();
401401

402402
// Emit event when vscode is ready
403-
this.lifecycleService.when(LifecyclePhase.Ready).then(() => ipcRenderer.send('vscode:workbenchReady', this.environmentService.configuration.windowId));
403+
this.lifecycleService.when(LifecyclePhase.Ready).then(() => ipcRenderer.send('vscode:workbenchReady', this.electronService.windowId));
404404

405405
// Integrity warning
406406
this.integrityService.isPure().then(res => this.titleService.updateProperties({ isPure: res.isPure }));
@@ -727,6 +727,7 @@ class NativeMenubarControl extends MenubarControl {
727727
@IAccessibilityService accessibilityService: IAccessibilityService,
728728
@IMenubarService private readonly menubarService: IMenubarService,
729729
@IHostService hostService: IHostService,
730+
@IElectronService private readonly electronService: IElectronService
730731
) {
731732
super(
732733
menuService,
@@ -775,7 +776,7 @@ class NativeMenubarControl extends MenubarControl {
775776
// Send menus to main process to be rendered by Electron
776777
const menubarData = { menus: {}, keybindings: {} };
777778
if (this.getMenubarMenus(menubarData)) {
778-
this.menubarService.updateMenubar(this.environmentService.configuration.windowId, menubarData);
779+
this.menubarService.updateMenubar(this.electronService.windowId, menubarData);
779780
}
780781
}
781782

0 commit comments

Comments
 (0)