Skip to content

Commit 98bac76

Browse files
author
Benjamin Pasero
committed
debt - more cleanup of window services
1 parent c725364 commit 98bac76

14 files changed

Lines changed: 71 additions & 108 deletions

File tree

src/vs/workbench/services/window/electron-browser/windowService.ts renamed to src/vs/platform/broadcast/electron-browser/broadcastService.ts

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,33 @@
55

66
'use strict';
77

8-
import { ElectronWindow } from 'vs/workbench/electron-browser/window';
98
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
109
import Event, { Emitter } from 'vs/base/common/event';
1110

12-
import { ipcRenderer as ipc, remote } from 'electron';
11+
import { ipcRenderer as ipc } from 'electron';
1312

14-
const windowId = remote.getCurrentWindow().id;
15-
16-
export const IWindowIPCService = createDecorator<IWindowIPCService>('windowIPCService');
17-
18-
export interface IWindowServices {
19-
windowService?: IWindowIPCService;
20-
}
13+
export const IBroadcastService = createDecorator<IBroadcastService>('broadcastService');
2114

2215
export interface IBroadcast {
2316
channel: string;
2417
payload: any;
2518
}
2619

27-
export interface IWindowIPCService {
20+
export interface IBroadcastService {
2821
_serviceBrand: any;
2922

30-
getWindowId(): number;
31-
32-
getWindow(): ElectronWindow;
33-
34-
registerWindow(win: ElectronWindow): void;
35-
3623
broadcast(b: IBroadcast, target?: string): void;
3724

3825
onBroadcast: Event<IBroadcast>;
3926
}
4027

41-
/**
42-
* TODO@Joao: remove this service
43-
* @deprecated
44-
*/
45-
export class WindowIPCService implements IWindowIPCService {
28+
export class BroadcastService implements IBroadcastService {
4629
public _serviceBrand: any;
4730

48-
private win: ElectronWindow;
49-
private windowId: number;
5031
private _onBroadcast: Emitter<IBroadcast>;
5132

52-
constructor() {
33+
constructor(private windowId: number) {
5334
this._onBroadcast = new Emitter<IBroadcast>();
54-
this.windowId = windowId;
5535

5636
this.registerListeners();
5737
}
@@ -66,20 +46,8 @@ export class WindowIPCService implements IWindowIPCService {
6646
return this._onBroadcast.event;
6747
}
6848

69-
public getWindowId(): number {
70-
return this.windowId;
71-
}
72-
73-
public getWindow(): ElectronWindow {
74-
return this.win;
75-
}
76-
77-
public registerWindow(win: ElectronWindow): void {
78-
this.win = win;
79-
}
80-
8149
public broadcast(b: IBroadcast, target?: string): void {
82-
ipc.send('vscode:broadcast', this.getWindowId(), target, {
50+
ipc.send('vscode:broadcast', this.windowId, target, {
8351
channel: b.channel,
8452
payload: b.payload
8553
});

src/vs/platform/windows/common/windows.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ export interface IWindowService {
9595
maximizeWindow(): TPromise<void>;
9696
unmaximizeWindow(): TPromise<void>;
9797
onWindowTitleDoubleClick(): TPromise<void>;
98+
showMessageBox(options: Electron.ShowMessageBoxOptions): number;
99+
showSaveDialog(options: Electron.SaveDialogOptions, callback?: (fileName: string) => void): string;
98100
}
99101

100102
export type MenuBarVisibility = 'default' | 'visible' | 'toggle' | 'hidden';

src/vs/platform/windows/electron-browser/windowService.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import { TPromise } from 'vs/base/common/winjs.base';
99
import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows';
1010
import { ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
11+
import { remote } from 'electron';
1112

1213
export class WindowService implements IWindowService {
1314

@@ -98,4 +99,15 @@ export class WindowService implements IWindowService {
9899
return this.windowsService.setDocumentEdited(this.windowId, flag);
99100
}
100101

102+
showMessageBox(options: Electron.ShowMessageBoxOptions): number {
103+
return remote.dialog.showMessageBox(remote.getCurrentWindow(), options);
104+
}
105+
106+
showSaveDialog(options: Electron.SaveDialogOptions, callback?: (fileName: string) => void): string {
107+
if (callback) {
108+
return remote.dialog.showSaveDialog(remote.getCurrentWindow(), options, callback);
109+
}
110+
111+
return remote.dialog.showSaveDialog(remote.getCurrentWindow(), options); // https://github.com/electron/electron/issues/4936
112+
}
101113
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation
1111
import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry';
1212
import { IPartService } from 'vs/workbench/services/part/common/partService';
1313
import { CommonEditorRegistry } from 'vs/editor/common/editorCommonExtensions';
14-
import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService';
1514
import { NoEditorsVisibleContext, InZenModeContext } from 'vs/workbench/electron-browser/workbench';
16-
import { IWindowsService } from 'vs/platform/windows/common/windows';
15+
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
1716
import { IListService, ListFocusContext } from 'vs/platform/list/browser/listService';
1817
import { List } from 'vs/base/browser/ui/list/listWidget';
1918
import errors = require('vs/base/common/errors');
@@ -366,8 +365,8 @@ export function registerCommands(): void {
366365
when: NoEditorsVisibleContext,
367366
primary: KeyMod.CtrlCmd | KeyCode.KEY_W,
368367
handler: accessor => {
369-
const windowService = accessor.get(IWindowIPCService);
370-
windowService.getWindow().close();
368+
const windowService = accessor.get(IWindowService);
369+
windowService.closeWindow();
371370
}
372371
});
373372

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { ILifecycleService, ShutdownEvent } from 'vs/platform/lifecycle/common/l
1919
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
2020
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
2121
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
22-
import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService';
2322
import { ChildProcess, fork } from 'child_process';
2423
import { ipcRenderer as ipc } from 'electron';
2524
import product from 'vs/platform/node/product';
@@ -35,6 +34,7 @@ import { IInitData, IWorkspaceData } from 'vs/workbench/api/node/extHost.protoco
3534
import { MainProcessExtensionService } from 'vs/workbench/api/electron-browser/mainThreadExtensionService';
3635
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
3736
import { ICrashReporterService } from 'vs/workbench/services/crashReporter/common/crashReporterService';
37+
import { IBroadcastService } from "vs/platform/broadcast/electron-browser/broadcastService";
3838

3939
export const EXTENSION_LOG_BROADCAST_CHANNEL = 'vscode:extensionLog';
4040
export const EXTENSION_ATTACH_BROADCAST_CHANNEL = 'vscode:extensionAttach';
@@ -91,7 +91,7 @@ export class ExtensionHostProcessWorker {
9191
@IMessageService private messageService: IMessageService,
9292
@IWindowsService private windowsService: IWindowsService,
9393
@IWindowService private windowService: IWindowService,
94-
@IWindowIPCService private windowIpcService: IWindowIPCService,
94+
@IBroadcastService private broadcastService: IBroadcastService,
9595
@ILifecycleService lifecycleService: ILifecycleService,
9696
@IInstantiationService private instantiationService: IInstantiationService,
9797
@IEnvironmentService private environmentService: IEnvironmentService,
@@ -122,7 +122,7 @@ export class ExtensionHostProcessWorker {
122122
AMD_ENTRYPOINT: 'vs/workbench/node/extensionHostProcess',
123123
PIPE_LOGGING: 'true',
124124
VERBOSE_LOGGING: true,
125-
VSCODE_WINDOW_ID: String(this.windowIpcService.getWindowId()),
125+
VSCODE_WINDOW_ID: String(this.windowService.getCurrentWindowId()),
126126
VSCODE_IPC_HOOK_EXTHOST: hook,
127127
ELECTRON_NO_ASAR: '1'
128128
}),
@@ -185,7 +185,7 @@ export class ExtensionHostProcessWorker {
185185

186186
// Notify debugger that we are ready to attach to the process if we run a development extension
187187
if (this.isExtensionDevelopmentHost && port) {
188-
this.windowIpcService.broadcast({
188+
this.broadcastService.broadcast({
189189
channel: EXTENSION_ATTACH_BROADCAST_CHANNEL,
190190
payload: { port }
191191
}, this.environmentService.extensionDevelopmentPath /* target */);
@@ -327,7 +327,7 @@ export class ExtensionHostProcessWorker {
327327

328328
// Broadcast to other windows if we are in development mode
329329
else if (!this.environmentService.isBuilt || this.isExtensionDevelopmentHost) {
330-
this.windowIpcService.broadcast({
330+
this.broadcastService.broadcast({
331331
channel: EXTENSION_LOG_BROADCAST_CHANNEL,
332332
payload: logEntry
333333
}, this.environmentService.extensionDevelopmentPath /* target */);
@@ -370,7 +370,7 @@ export class ExtensionHostProcessWorker {
370370

371371
// Expected development extension termination: When the extension host goes down we also shutdown the window
372372
else if (!this.isExtensionDevelopmentTestFromCli) {
373-
this.windowIpcService.getWindow().close();
373+
this.windowService.closeWindow();
374374
}
375375

376376
// When CLI testing make sure to exit with proper exit code
@@ -394,7 +394,7 @@ export class ExtensionHostProcessWorker {
394394
// If the extension development host was started without debugger attached we need
395395
// to communicate this back to the main side to terminate the debug session
396396
if (this.isExtensionDevelopmentHost && !this.isExtensionDevelopmentTestFromCli && !this.isExtensionDevelopmentDebug) {
397-
this.windowIpcService.broadcast({
397+
this.broadcastService.broadcast({
398398
channel: EXTENSION_TERMINATE_BROADCAST_CHANNEL,
399399
payload: true
400400
}, this.environmentService.extensionDevelopmentPath /* target */);

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import { ElectronWindow } from 'vs/workbench/electron-browser/window';
3131
import { resolveWorkbenchCommonProperties, getOrCreateMachineId } from 'vs/platform/telemetry/node/workbenchCommonProperties';
3232
import { machineIdIpcChannel } from 'vs/platform/telemetry/node/commonProperties';
3333
import { WorkspaceStats } from 'vs/workbench/services/telemetry/common/workspaceStats';
34-
import { IWindowIPCService, WindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService';
3534
import { IWindowsService, IWindowService, IWindowConfiguration } from 'vs/platform/windows/common/windows';
3635
import { WindowsChannelClient } from 'vs/platform/windows/common/windowsIpc';
3736
import { WindowService } from 'vs/platform/windows/electron-browser/windowService';
@@ -100,6 +99,7 @@ import { registerThemingParticipant, ITheme, ICssStyleCollector } from 'vs/platf
10099
import { foreground, selectionBackground, focusBorder, scrollbarShadow, scrollbarSliderActiveBackground, scrollbarSliderBackground, scrollbarSliderHoverBackground, listHighlightForeground, inputPlaceholderForeground } from 'vs/platform/theme/common/colorRegistry';
101100
import { TextMateService } from 'vs/workbench/services/textMate/electron-browser/TMSyntax';
102101
import { ITextMateService } from 'vs/workbench/services/textMate/electron-browser/textMateService';
102+
import { IBroadcastService, BroadcastService } from "vs/platform/broadcast/electron-browser/broadcastService";
103103

104104
/**
105105
* Services that we require for the Shell
@@ -129,7 +129,7 @@ export class WorkbenchShell {
129129
private telemetryService: ITelemetryService;
130130
private extensionService: MainProcessExtensionService;
131131
private windowsService: IWindowsService;
132-
private windowIPCService: IWindowIPCService;
132+
private broadcastService: IBroadcastService;
133133
private timerService: ITimerService;
134134
private themeService: WorkbenchThemeService;
135135
private lifecycleService: LifecycleService;
@@ -190,8 +190,7 @@ export class WorkbenchShell {
190190
});
191191

192192
// Window
193-
const activeWindow = this.workbench.getInstantiationService().createInstance(ElectronWindow, currentWindow, this.container);
194-
this.windowIPCService.registerWindow(activeWindow);
193+
this.workbench.getInstantiationService().createInstance(ElectronWindow, currentWindow, this.container);
195194

196195
// Handle case where workbench is not starting up properly
197196
const timeoutHandle = setTimeout(() => {
@@ -256,9 +255,8 @@ export class WorkbenchShell {
256255

257256
const instantiationService: IInstantiationService = new InstantiationService(serviceCollection, true);
258257

259-
// TODO@joao remove this
260-
this.windowIPCService = instantiationService.createInstance<IWindowIPCService>(WindowIPCService);
261-
serviceCollection.set(IWindowIPCService, this.windowIPCService);
258+
this.broadcastService = new BroadcastService(currentWindow.id);
259+
serviceCollection.set(IBroadcastService, this.broadcastService);
262260

263261
const mainProcessClient = new ElectronIPCClient(String(`window${currentWindow.id}`));
264262
disposables.push(mainProcessClient);
@@ -267,10 +265,10 @@ export class WorkbenchShell {
267265
this.windowsService = new WindowsChannelClient(windowsChannel);
268266
serviceCollection.set(IWindowsService, this.windowsService);
269267

270-
serviceCollection.set(IWindowService, new SyncDescriptor(WindowService, this.windowIPCService.getWindowId()));
268+
serviceCollection.set(IWindowService, new SyncDescriptor(WindowService, currentWindow.id));
271269

272270
const sharedProcess = this.windowsService.whenSharedProcessReady()
273-
.then(() => connectNet(this.environmentService.sharedIPCHandle, `window:${this.windowIPCService.getWindowId()}`));
271+
.then(() => connectNet(this.environmentService.sharedIPCHandle, `window:${currentWindow.id}`));
274272

275273
sharedProcess
276274
.done(client => client.registerChannel('choice', instantiationService.createInstance(ChoiceChannel)));
@@ -385,7 +383,7 @@ export class WorkbenchShell {
385383
serviceCollection.set(IUpdateService, new SyncDescriptor(UpdateChannelClient, updateChannel));
386384

387385
const urlChannel = mainProcessClient.getChannel('url');
388-
serviceCollection.set(IURLService, new SyncDescriptor(URLChannelClient, urlChannel, this.windowIPCService.getWindowId()));
386+
serviceCollection.set(IURLService, new SyncDescriptor(URLChannelClient, urlChannel, currentWindow.id));
389387

390388
return [instantiationService, serviceCollection];
391389
}

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

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2929
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
3030
import { IWindowsService, IWindowService, IWindowSettings, IWindowConfiguration, IPath, IOpenFileRequest } from 'vs/platform/windows/common/windows';
3131
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
32-
import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService';
3332
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
3433
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
3534
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
@@ -43,11 +42,9 @@ import { IExtensionService } from 'vs/platform/extensions/common/extensions';
4342
import { KeyboardMapperFactory } from 'vs/workbench/services/keybinding/electron-browser/keybindingService';
4443
import { Themable, EDITOR_DRAG_AND_DROP_BACKGROUND } from 'vs/workbench/common/theme';
4544

46-
import { remote, ipcRenderer as ipc, webFrame } from 'electron';
45+
import { ipcRenderer as ipc, webFrame } from 'electron';
4746
import { activeContrastBorder } from 'vs/platform/theme/common/colorRegistry';
4847

49-
const dialog = remote.dialog;
50-
5148
const TextInputActions: IAction[] = [
5249
new Action('undo', nls.localize('undo', "Undo"), null, true, () => document.execCommand('undo') && TPromise.as(true)),
5350
new Action('redo', nls.localize('redo', "Redo"), null, true, () => document.execCommand('redo') && TPromise.as(true)),
@@ -69,7 +66,6 @@ export class ElectronWindow extends Themable {
6966
constructor(
7067
win: Electron.BrowserWindow,
7168
shellContainer: HTMLElement,
72-
@IWindowIPCService private windowIPCService: IWindowIPCService,
7369
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
7470
@IEditorGroupService private editorGroupService: IEditorGroupService,
7571
@IPartService private partService: IPartService,
@@ -143,7 +139,7 @@ export class ElectronWindow extends Themable {
143139
.on(DOM.EventType.DROP, (e: DragEvent) => {
144140
DOM.EventHelper.stop(e, true);
145141

146-
this.focus(); // make sure this window has focus so that the open call reaches the right window!
142+
this.windowService.focusWindow(); // make sure this window has focus so that the open call reaches the right window!
147143

148144
// Ask the user when opening a potential large number of folders
149145
let doOpen = true;
@@ -250,7 +246,7 @@ export class ElectronWindow extends Themable {
250246

251247
// Emit event when vscode has loaded
252248
this.partService.joinCreation().then(() => {
253-
ipc.send('vscode:workbenchLoaded', this.windowIPCService.getWindowId());
249+
ipc.send('vscode:workbenchLoaded', this.windowService.getCurrentWindowId());
254250
});
255251

256252
// Message support
@@ -463,24 +459,4 @@ export class ElectronWindow extends Themable {
463459
return stat(resource.fsPath).then(stats => stats.isDirectory() ? true : false, error => false);
464460
})).then(res => res.some(res => !!res));
465461
}
466-
467-
public close(): void {
468-
this.win.close();
469-
}
470-
471-
public showMessageBox(options: Electron.ShowMessageBoxOptions): number {
472-
return dialog.showMessageBox(this.win, options);
473-
}
474-
475-
public showSaveDialog(options: Electron.SaveDialogOptions, callback?: (fileName: string) => void): string {
476-
if (callback) {
477-
return dialog.showSaveDialog(this.win, options, callback);
478-
}
479-
480-
return dialog.showSaveDialog(this.win, options); // https://github.com/electron/electron/issues/4936
481-
}
482-
483-
public focus(): TPromise<void> {
484-
return this.windowService.focusWindow();
485-
}
486462
}

src/vs/workbench/parts/debug/electron-browser/debugService.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { IExtensionService } from 'vs/platform/extensions/common/extensions';
2525
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2626
import { FileChangesEvent, FileChangeType, IFileService } from 'vs/platform/files/common/files';
2727
import { IMessageService, CloseAction } from 'vs/platform/message/common/message';
28-
import { IWindowsService } from 'vs/platform/windows/common/windows';
28+
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
2929
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
3030
import { TelemetryService } from 'vs/platform/telemetry/common/telemetryService';
3131
import { TelemetryAppenderClient } from 'vs/platform/telemetry/common/telemetryIpc';
@@ -48,8 +48,8 @@ import { ITextFileService } from 'vs/workbench/services/textfile/common/textfile
4848
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
4949
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
5050
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
51-
import { IWindowIPCService, IBroadcast } from 'vs/workbench/services/window/electron-browser/windowService';
5251
import { ILogEntry, EXTENSION_LOG_BROADCAST_CHANNEL, EXTENSION_ATTACH_BROADCAST_CHANNEL, EXTENSION_TERMINATE_BROADCAST_CHANNEL } from 'vs/workbench/electron-browser/extensionHost';
52+
import { IBroadcastService, IBroadcast } from "vs/platform/broadcast/electron-browser/broadcastService";
5353

5454
const DEBUG_BREAKPOINTS_KEY = 'debug.breakpoint';
5555
const DEBUG_BREAKPOINTS_ACTIVATED_KEY = 'debug.breakpointactivated';
@@ -91,7 +91,8 @@ export class DebugService implements debug.IDebugService {
9191
@IMessageService private messageService: IMessageService,
9292
@IPartService private partService: IPartService,
9393
@IWindowsService private windowsService: IWindowsService,
94-
@IWindowIPCService private windowService: IWindowIPCService,
94+
@IWindowService private windowService: IWindowService,
95+
@IBroadcastService private broadcastService: IBroadcastService,
9596
@ITelemetryService private telemetryService: ITelemetryService,
9697
@IWorkspaceContextService private contextService: IWorkspaceContextService,
9798
@IContextKeyService contextKeyService: IContextKeyService,
@@ -144,7 +145,7 @@ export class DebugService implements debug.IDebugService {
144145
lifecycleService.onShutdown(this.store, this);
145146
lifecycleService.onShutdown(this.dispose, this);
146147

147-
this.toDispose.push(this.windowService.onBroadcast(this.onBroadcast, this));
148+
this.toDispose.push(this.broadcastService.onBroadcast(this.onBroadcast, this));
148149
this.toDispose.push(this.configurationService.onDidUpdateConfiguration((event) => {
149150
if (event.sourceConfig) {
150151
const names = this.configurationManager.getConfigurationNames();
@@ -276,7 +277,7 @@ export class DebugService implements debug.IDebugService {
276277

277278
this.focusStackFrameAndEvaluate(stackFrameToFocus).done(null, errors.onUnexpectedError);
278279
if (thread.stoppedDetails) {
279-
this.windowService.getWindow().focus();
280+
this.windowService.focusWindow();
280281
aria.alert(nls.localize('debuggingPaused', "Debugging paused, reason {0}, {1} {2}", thread.stoppedDetails.reason, stackFrameToFocus.source ? stackFrameToFocus.source.name : '', stackFrameToFocus.range.startLineNumber));
281282
}
282283

0 commit comments

Comments
 (0)