diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 4c9ca188f1b..ad751da60db 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -143,7 +143,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo // Spawn shared process const sharedProcess = new SharedProcess(environmentService, userEnv); - const sharedProcessClient = sharedProcess.onReady + const sharedProcessClient = sharedProcess.whenReady() .then(() => connect(environmentService.sharedIPCHandle, 'main')); // Create a new service collection, because the telemetry service diff --git a/src/vs/code/electron-main/sharedProcess.ts b/src/vs/code/electron-main/sharedProcess.ts index 4111cdc6526..b9088117aac 100644 --- a/src/vs/code/electron-main/sharedProcess.ts +++ b/src/vs/code/electron-main/sharedProcess.ts @@ -17,7 +17,7 @@ export class SharedProcess { private disposables: IDisposable[] = []; @memoize - get onReady(): TPromise { + private get _whenReady(): TPromise { this.window = new BrowserWindow({ show: false }); const config = assign({ appRoot: this.environmentService.appRoot, @@ -59,7 +59,7 @@ export class SharedProcess { args: this.environmentService.args }); - sender.once('handshake:im ready', () => c(null)); + ipcMain.once('handshake:im ready', () => c(null)); }); }); } @@ -69,6 +69,10 @@ export class SharedProcess { private userEnv: IProcessEnvironment ) { } + whenReady(): TPromise { + return this._whenReady; + } + toggle(): void { if (this.window.isVisible()) { this.hide(); diff --git a/src/vs/platform/windows/common/windows.ts b/src/vs/platform/windows/common/windows.ts index 58588327549..12e2783f1b0 100644 --- a/src/vs/platform/windows/common/windows.ts +++ b/src/vs/platform/windows/common/windows.ts @@ -40,6 +40,7 @@ export interface IWindowsService { relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise; // Shared process + whenSharedProcessReady(): TPromise; toggleSharedProcess(): TPromise; // Global methods diff --git a/src/vs/platform/windows/common/windowsIpc.ts b/src/vs/platform/windows/common/windowsIpc.ts index 2176e6672cf..a4aadc3cec3 100644 --- a/src/vs/platform/windows/common/windowsIpc.ts +++ b/src/vs/platform/windows/common/windowsIpc.ts @@ -37,6 +37,7 @@ export interface IWindowsChannel extends IChannel { call(command: 'getWindows'): TPromise<{ id: number; path: string; title: string; }[]>; call(command: 'getWindowCount'): TPromise; call(command: 'relaunch', arg: { addArgs?: string[], removeArgs?: string[] }): TPromise; + call(command: 'whenSharedProcessReady'): TPromise; call(command: 'toggleSharedProcess'): TPromise; call(command: 'log', arg: [string, string[]]): TPromise; call(command: 'closeExtensionHostWindow', arg: string): TPromise; @@ -83,6 +84,7 @@ export class WindowsChannel implements IWindowsChannel { case 'getWindows': return this.service.getWindows(); case 'getWindowCount': return this.service.getWindowCount(); case 'relaunch': return this.service.relaunch(arg[0]); + case 'whenSharedProcessReady': return this.service.whenSharedProcessReady(); case 'toggleSharedProcess': return this.service.toggleSharedProcess(); case 'quit': return this.service.quit(); case 'log': return this.service.log(arg[0], arg[1]); @@ -183,6 +185,10 @@ export class WindowsChannelClient implements IWindowsService { return this.channel.call('relaunch', [options]); } + whenSharedProcessReady(): TPromise { + return this.channel.call('whenSharedProcessReady'); + } + toggleSharedProcess(): TPromise { return this.channel.call('toggleSharedProcess'); } diff --git a/src/vs/platform/windows/electron-main/windowsService.ts b/src/vs/platform/windows/electron-main/windowsService.ts index 37d48abfe25..1aa25788815 100644 --- a/src/vs/platform/windows/electron-main/windowsService.ts +++ b/src/vs/platform/windows/electron-main/windowsService.ts @@ -21,6 +21,7 @@ import { OpenContext } from 'vs/code/common/windows'; import { IWindowsMainService } from 'vs/code/electron-main/windows'; export interface ISharedProcess { + whenReady(): TPromise; toggle(): void; } @@ -287,6 +288,10 @@ export class WindowsService implements IWindowsService, IDisposable { return TPromise.as(null); } + whenSharedProcessReady(): TPromise { + return this.sharedProcess.whenReady(); + } + toggleSharedProcess(): TPromise { this.sharedProcess.toggle(); return TPromise.as(null); diff --git a/src/vs/workbench/electron-browser/shell.ts b/src/vs/workbench/electron-browser/shell.ts index dee7e8c3174..6f7084d83ce 100644 --- a/src/vs/workbench/electron-browser/shell.ts +++ b/src/vs/workbench/electron-browser/shell.ts @@ -294,11 +294,11 @@ export class WorkbenchShell { serviceCollection.set(IWindowService, new SyncDescriptor(WindowService, this.windowIPCService.getWindowId())); - const sharedProcess = connectNet(this.environmentService.sharedIPCHandle, `window:${this.windowIPCService.getWindowId()}`); - sharedProcess.done(client => { - // Choice channel - client.registerChannel('choice', instantiationService.createInstance(ChoiceChannel)); - }, errors.onUnexpectedError); + const sharedProcess = this.windowsService.whenSharedProcessReady() + .then(() => connectNet(this.environmentService.sharedIPCHandle, `window:${this.windowIPCService.getWindowId()}`)); + + sharedProcess + .done(client => client.registerChannel('choice', instantiationService.createInstance(ChoiceChannel))); // Storage Sevice const disableWorkspaceStorage = this.environmentService.extensionTestsPath || (!this.contextService.hasWorkspace() && !this.environmentService.isExtensionDevelopment); // without workspace or in any extension test, we use inMemory storage unless we develop an extension where we want to preserve state diff --git a/src/vs/workbench/test/workbenchTestServices.ts b/src/vs/workbench/test/workbenchTestServices.ts index 224fb1f38a6..3035d7f7ec2 100644 --- a/src/vs/workbench/test/workbenchTestServices.ts +++ b/src/vs/workbench/test/workbenchTestServices.ts @@ -920,6 +920,9 @@ export class TestWindowsService implements IWindowsService { relaunch(options: { addArgs?: string[], removeArgs?: string[] }): TPromise { return TPromise.as(void 0); } + whenSharedProcessReady(): TPromise { + return TPromise.as(void 0); + } toggleSharedProcess(): TPromise { return TPromise.as(void 0); }