From 7baf009e27c8a0ce11f4a33c75150becbbac5be1 Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Thu, 22 Sep 2016 11:02:55 +0200 Subject: [PATCH] WindowEventChannel: Create it before registerting channel - Initial window events are bufferred --- src/vs/base/parts/ipc/node/ipc.net.ts | 3 +++ src/vs/code/common/windows.ts | 2 +- src/vs/code/common/windowsIpc.ts | 8 ++++---- src/vs/code/electron-main/main.ts | 5 +++-- src/vs/code/node/sharedProcessMain.ts | 4 +--- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/vs/base/parts/ipc/node/ipc.net.ts b/src/vs/base/parts/ipc/node/ipc.net.ts index d1573af1828..694963fdb8f 100644 --- a/src/vs/base/parts/ipc/node/ipc.net.ts +++ b/src/vs/base/parts/ipc/node/ipc.net.ts @@ -114,6 +114,9 @@ class RoutingChannelClient implements IRoutingChannelClient, IDisposable { getChannel(channelName: string, router: IClientRouter): T { const call = (command: string, arg: any) => { const id = router.routeCall(command, arg); + if (!id) { + return TPromise.wrapError('Client id should be provided'); + } return this.getClient(id).then(client => client.getChannel(channelName).call(command, arg)); }; return { call } as T; diff --git a/src/vs/code/common/windows.ts b/src/vs/code/common/windows.ts index 28df548ebcc..7e268b1945c 100644 --- a/src/vs/code/common/windows.ts +++ b/src/vs/code/common/windows.ts @@ -30,7 +30,7 @@ export class ActiveWindowManager implements IDisposable { this._activeWindowId = windowId; } - public get activeWindowId(): string { + public get activeClientId(): string { return `window:${ this._activeWindowId }`; } diff --git a/src/vs/code/common/windowsIpc.ts b/src/vs/code/common/windowsIpc.ts index feec4bbd2be..4af2306e0c2 100644 --- a/src/vs/code/common/windowsIpc.ts +++ b/src/vs/code/common/windowsIpc.ts @@ -7,16 +7,16 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc'; -import { IWindowEventService } from './windows'; +import { IWindowEventService } from 'vs/code/common/windows'; import Event, { buffer } from 'vs/base/common/event'; -export interface IWindowsChannel extends IChannel { +export interface IWindowEventChannel extends IChannel { call(command: 'event:onNewWindowOpen'): TPromise; call(command: 'event:onWindowFocus'): TPromise; call(command: string, arg: any): any; } -export class WindowsChannel implements IWindowsChannel { +export class WindowEventChannel implements IWindowEventChannel { onNewWindowOpen: Event; onWindowFocus: Event; @@ -41,7 +41,7 @@ export class WindowEventChannelClient implements IWindowEventService { _serviceBrand: any; - constructor(private channel: IWindowsChannel) { } + constructor(private channel: IWindowEventChannel) { } private _onNewWindowOpen: Event = eventFromCall(this.channel, 'event:onNewWindowOpen'); get onNewWindowOpen(): Event { diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index c9a317dd98e..7315a2005c4 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -15,7 +15,7 @@ import { mkdirp } from 'vs/base/node/pfs'; import { IProcessEnvironment, IEnvService, EnvService } from 'vs/code/electron-main/env'; import { IWindowsService, WindowsManager, WindowEventService } from 'vs/code/electron-main/windows'; import { IWindowEventService } from 'vs/code/common/windows'; -import { WindowsChannel } from 'vs/code/common/windowsIpc'; +import { WindowEventChannel } from 'vs/code/common/windowsIpc'; import { ILifecycleService, LifecycleService } from 'vs/code/electron-main/lifecycle'; import { VSCodeMenu } from 'vs/code/electron-main/menus'; import { IUpdateService, UpdateManager } from 'vs/code/electron-main/update-manager'; @@ -74,6 +74,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce const lifecycleService = accessor.get(ILifecycleService); const updateService = accessor.get(IUpdateService); const configurationService = accessor.get(IConfigurationService) as ConfigurationService; + const windowEventChannel = new WindowEventChannel(windowEventService); // We handle uncaught exceptions here to prevent electron from opening a dialog to the user process.on('uncaughtException', (err: any) => { @@ -136,7 +137,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce sharedProcessDisposable = disposable; const sharedProcessConnect = connect(environmentService.sharedIPCHandle, 'main'); sharedProcessConnect.done(client => { - client.registerChannel('windowEvent', new WindowsChannel(windowEventService)); + client.registerChannel('windowEvent', windowEventChannel); }); }); diff --git a/src/vs/code/node/sharedProcessMain.ts b/src/vs/code/node/sharedProcessMain.ts index a3ceb02679e..6e873db4c39 100644 --- a/src/vs/code/node/sharedProcessMain.ts +++ b/src/vs/code/node/sharedProcessMain.ts @@ -75,9 +75,7 @@ function main(server: Server, initData: ISharedProcessInitData): void { const activeWindowManager = new ActiveWindowManager(windowEventService); services.set(IChoiceService, new ChoiceChannelClient(server.getChannel('choice', { - routeCall: (command: any, arg: any) => { - return activeWindowManager.activeWindowId; - } + routeCall: () => activeWindowManager.activeClientId }))); const instantiationService = new InstantiationService(services);