WindowEventChannel: Create it before registerting channel - Initial window events are bufferred

This commit is contained in:
Sandeep Somavarapu
2016-09-22 11:02:55 +02:00
parent cb19176a04
commit 7baf009e27
5 changed files with 12 additions and 10 deletions
+3
View File
@@ -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;
+1 -1
View File
@@ -30,7 +30,7 @@ export class ActiveWindowManager implements IDisposable {
this._activeWindowId = windowId;
}
public get activeWindowId(): string {
public get activeClientId(): string {
return `window:${ this._activeWindowId }`;
}
+4 -4
View File
@@ -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>;
@@ -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> {
+3 -2
View File
@@ -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<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) => {
@@ -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);
});
});
+1 -3
View File
@@ -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);