diff --git a/src/vs/code/common/windowsIpc.ts b/src/vs/code/common/windowsIpc.ts index 709249d2366..2620656dc23 100644 --- a/src/vs/code/common/windowsIpc.ts +++ b/src/vs/code/common/windowsIpc.ts @@ -28,12 +28,10 @@ export class WindowEventChannel implements IWindowEventChannel { call(command: string, args?: any): any { switch (command) { - case 'event:onNewWindowOpen': - return eventToCall(this.onNewWindowOpen); - case 'event:onWindowFocus': - return eventToCall(this.onWindowFocus); + case 'event:onNewWindowOpen': return eventToCall(this.onNewWindowOpen); + case 'event:onWindowFocus': return eventToCall(this.onWindowFocus); + default: return TPromise.wrapError('invalid command'); } - return TPromise.wrapError('invalid command'); } } @@ -44,12 +42,8 @@ export class WindowEventChannelClient implements IWindowEventService { constructor(private channel: IWindowEventChannel) { } private _onNewWindowOpen: Event = eventFromCall(this.channel, 'event:onNewWindowOpen'); - get onNewWindowOpen(): Event { - return this._onNewWindowOpen; - } + get onNewWindowOpen(): Event { return this._onNewWindowOpen; } private _onWindowFocus: Event = eventFromCall(this.channel, 'event:onWindowFocus'); - get onWindowFocus(): Event { - return this._onWindowFocus; - } + get onWindowFocus(): Event { return this._onWindowFocus; } } \ No newline at end of file diff --git a/src/vs/code/electron-main/main.ts b/src/vs/code/electron-main/main.ts index 6ae217638a1..4227e9ae220 100644 --- a/src/vs/code/electron-main/main.ts +++ b/src/vs/code/electron-main/main.ts @@ -12,8 +12,7 @@ import * as platform from 'vs/base/common/platform'; import { parseMainProcessArgv, ParsedArgs } from 'vs/platform/environment/node/argv'; import { mkdirp } from 'vs/base/node/pfs'; import { validatePaths } from 'vs/code/electron-main/paths'; -import { IWindowsService, WindowsManager, WindowEventService } from 'vs/code/electron-main/windows'; -import { IWindowEventService } from 'vs/code/common/windows'; +import { IWindowsService, WindowsManager } from 'vs/code/electron-main/windows'; import { WindowEventChannel } from 'vs/code/common/windowsIpc'; import { ILifecycleService, LifecycleService } from 'vs/code/electron-main/lifecycle'; import { VSCodeMenu } from 'vs/code/electron-main/menus'; @@ -74,11 +73,10 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo const logService = accessor.get(ILogService); const environmentService = accessor.get(IEnvironmentService); const windowsService = accessor.get(IWindowsService); - const windowEventService = accessor.get(IWindowEventService); const lifecycleService = accessor.get(ILifecycleService); const updateService = accessor.get(IUpdateService); const configurationService = accessor.get(IConfigurationService) as ConfigurationService; - const windowEventChannel = new WindowEventChannel(windowEventService); + const windowEventChannel = new WindowEventChannel(windowsService); // We handle uncaught exceptions here to prevent electron from opening a dialog to the user process.on('uncaughtException', (err: any) => { @@ -140,12 +138,12 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo }; let sharedProcessDisposable; + spawnSharedProcess(initData, options).done(disposable => { sharedProcessDisposable = disposable; - const sharedProcessConnect = connect(environmentService.sharedIPCHandle, 'main'); - sharedProcessConnect.done(client => { - client.registerChannel('windowEvent', windowEventChannel); - }); + + connect(environmentService.sharedIPCHandle, 'main') + .done(client => client.registerChannel('windowEvent', windowEventChannel)); }); // Make sure we associate the program with the app user model id @@ -448,7 +446,6 @@ function start(): void { services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, args, process.execPath)); services.set(ILogService, new SyncDescriptor(MainLogService)); services.set(IWindowsService, new SyncDescriptor(WindowsManager)); - services.set(IWindowEventService, new SyncDescriptor(WindowEventService)); services.set(ILifecycleService, new SyncDescriptor(LifecycleService)); services.set(IStorageService, new SyncDescriptor(StorageService)); services.set(IConfigurationService, new SyncDescriptor(ConfigurationService)); diff --git a/src/vs/code/electron-main/windows.ts b/src/vs/code/electron-main/windows.ts index 16da9162265..c0592e36f1f 100644 --- a/src/vs/code/electron-main/windows.ts +++ b/src/vs/code/electron-main/windows.ts @@ -123,22 +123,7 @@ export interface IWindowsService { clearRecentPathsList(): void; } -export class WindowEventService implements IWindowEventService { - - _serviceBrand: any; - - constructor( @IWindowsService private windowsService: IWindowsService) { } - - public get onWindowFocus(): CommonEvent { - return this.windowsService.onWindowFocus; - } - - public get onNewWindowOpen(): CommonEvent { - return this.windowsService.onNewWindowOpen; - } -} - -export class WindowsManager implements IWindowsService { +export class WindowsManager implements IWindowsService, IWindowEventService { _serviceBrand: any; diff --git a/src/vs/code/node/sharedProcessMain.ts b/src/vs/code/node/sharedProcessMain.ts index 86313446bfd..b21e99fbcab 100644 --- a/src/vs/code/node/sharedProcessMain.ts +++ b/src/vs/code/node/sharedProcessMain.ts @@ -66,17 +66,14 @@ function main(server: Server, initData: ISharedProcessInitData): void { services.set(IConfigurationService, new SyncDescriptor(ConfigurationService)); services.set(IRequestService, new SyncDescriptor(RequestService)); - const windowEventService: IWindowEventService = new WindowEventChannelClient(server.getChannel('windowEvent', { - routeCall: (command: any, arg: any) => { - return 'main'; - } - })); + const windowEventChannel = server.getChannel('windowEvent', { routeCall: () => 'main' }); + const windowEventService: IWindowEventService = new WindowEventChannelClient(windowEventChannel); services.set(IWindowEventService, windowEventService); const activeWindowManager = new ActiveWindowManager(windowEventService); - services.set(IChoiceService, new ChoiceChannelClient(server.getChannel('choice', { - routeCall: () => activeWindowManager.activeClientId - }))); + + const choiceChannel = server.getChannel('choice', { routeCall: () => activeWindowManager.activeClientId }); + services.set(IChoiceService, new ChoiceChannelClient(choiceChannel)); const instantiationService = new InstantiationService(services);