Skip to content

Commit

Permalink
WindowEventChannel: Create it before registerting channel - Initial w…
Browse files Browse the repository at this point in the history
…indow events are bufferred
  • Loading branch information
sandy081 committed Sep 22, 2016
1 parent cb19176 commit 7baf009
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/vs/base/parts/ipc/node/ipc.net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ class RoutingChannelClient implements IRoutingChannelClient, IDisposable {
getChannel<T extends IChannel>(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;
Expand Down
2 changes: 1 addition & 1 deletion src/vs/code/common/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class ActiveWindowManager implements IDisposable {
this._activeWindowId = windowId;
}

public get activeWindowId(): string {
public get activeClientId(): string {
return `window:${ this._activeWindowId }`;
}

Expand Down
8 changes: 4 additions & 4 deletions src/vs/code/common/windowsIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<number>;
call(command: 'event:onWindowFocus'): TPromise<number>;
call(command: string, arg: any): any;
}

export class WindowsChannel implements IWindowsChannel {
export class WindowEventChannel implements IWindowEventChannel {

onNewWindowOpen: Event<number>;
onWindowFocus: Event<number>;
Expand All @@ -41,7 +41,7 @@ export class WindowEventChannelClient implements IWindowEventService {

_serviceBrand: any;

constructor(private channel: IWindowsChannel) { }
constructor(private channel: IWindowEventChannel) { }

private _onNewWindowOpen: Event<number> = eventFromCall<number>(this.channel, 'event:onNewWindowOpen');
get onNewWindowOpen(): Event<number> {
Expand Down
5 changes: 3 additions & 2 deletions src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<any>;
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) => {
Expand Down Expand Up @@ -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);
});
});

Expand Down
4 changes: 1 addition & 3 deletions src/vs/code/node/sharedProcessMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7baf009

Please sign in to comment.