提交 8f61b620 编写于 作者: J Joao Moreno

remove `windowEvent`

上级 df7dbe46
......@@ -4,10 +4,8 @@
*--------------------------------------------------------------------------------------------*/
import Event from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IDisposable } from 'vs/base/common/lifecycle';
export const IWindowEventService = createDecorator<IWindowEventService>('windowEventService');
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IWindowsService } from 'vs/platform/windows/common/windows';
export interface IWindowEventService {
_serviceBrand: any;
......@@ -21,22 +19,20 @@ export class ActiveWindowManager implements IDisposable {
private disposables: IDisposable[] = [];
private _activeWindowId: number;
constructor( @IWindowEventService private windowService: IWindowEventService) {
this.disposables.push(this.windowService.onNewWindowOpen(windowId => this.setActiveWindow(windowId)));
this.disposables.push(this.windowService.onWindowFocus(windowId => this.setActiveWindow(windowId)));
constructor( @IWindowsService windowsService: IWindowsService) {
windowsService.onWindowOpen(this.setActiveWindow, this, this.disposables);
windowsService.onWindowFocus(this.setActiveWindow, this, this.disposables);
}
private setActiveWindow(windowId: number) {
this._activeWindowId = windowId;
}
public get activeClientId(): string {
get activeClientId(): string {
return `window:${this._activeWindowId}`;
}
public dispose() {
for (const disposable of this.disposables) {
disposable.dispose();
}
dispose() {
this.disposables = dispose(this.disposables);
}
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
import { IWindowEventService } from 'vs/code/common/windows';
import Event, { buffer } from 'vs/base/common/event';
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 WindowEventChannel implements IWindowEventChannel {
onNewWindowOpen: Event<number>;
onWindowFocus: Event<number>;
constructor(private service: IWindowEventService) {
this.onNewWindowOpen = buffer(service.onNewWindowOpen, true);
this.onWindowFocus = buffer(service.onWindowFocus, true);
}
call(command: string, args?: any): any {
switch (command) {
case 'event:onNewWindowOpen': return eventToCall(this.onNewWindowOpen);
case 'event:onWindowFocus': return eventToCall(this.onWindowFocus);
default: return TPromise.wrapError('invalid command');
}
}
}
export class WindowEventChannelClient implements IWindowEventService {
_serviceBrand: any;
constructor(private channel: IWindowEventChannel) { }
private _onNewWindowOpen: Event<number> = eventFromCall<number>(this.channel, 'event:onNewWindowOpen');
get onNewWindowOpen(): Event<number> { return this._onNewWindowOpen; }
private _onWindowFocus: Event<number> = eventFromCall<number>(this.channel, 'event:onWindowFocus');
get onWindowFocus(): Event<number> { return this._onWindowFocus; }
}
\ No newline at end of file
......@@ -15,7 +15,6 @@ import { IWindowsMainService, WindowsManager } from 'vs/code/electron-main/windo
import { IWindowsService } from 'vs/platform/windows/common/windows';
import { WindowsChannel } from 'vs/platform/windows/common/windowsIpc';
import { WindowsService } from 'vs/platform/windows/electron-main/windowsService';
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 } from 'vs/platform/update/common/update';
......@@ -167,6 +166,9 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
const instantiationService2 = instantiationService.createChild(services);
instantiationService2.invokeFunction(accessor => {
// TODO@Joao: unfold this
windowsMainService = accessor.get(IWindowsMainService);
// Register more Main IPC services
const launchService = accessor.get(ILaunchService);
const launchChannel = new LaunchChannel(launchService);
......@@ -184,12 +186,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: platfo
const windowsService = accessor.get(IWindowsService);
const windowsChannel = new WindowsChannel(windowsService);
electronIpcServer.registerChannel('windows', windowsChannel);
// TODO@Joao revisit this
// Register windowEvent
windowsMainService = accessor.get(IWindowsMainService);
const windowEventChannel = new WindowEventChannel(windowsMainService);
sharedProcess.done(client => client.registerChannel('windowEvent', windowEventChannel));
sharedProcess.done(client => client.registerChannel('windows', windowsChannel));
// Make sure we associate the program with the app user model id
// This will help Windows to associate the running program with
......
......@@ -24,7 +24,6 @@ import { ILifecycleService } from 'vs/code/electron-main/lifecycle';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ILogService } from 'vs/code/electron-main/log';
import { getPathLabel } from 'vs/base/common/labels';
import { IWindowEventService } from 'vs/code/common/windows';
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import CommonEvent, { Emitter, once } from 'vs/base/common/event';
......@@ -88,8 +87,6 @@ export interface IWindowsMainService {
// events
onWindowReady: CommonEvent<VSCodeWindow>;
onWindowClose: CommonEvent<number>;
onNewWindowOpen: CommonEvent<number>;
onWindowFocus: CommonEvent<number>;
onRecentPathsChange: CommonEvent<void>;
// methods
......@@ -119,7 +116,7 @@ export interface IWindowsMainService {
toggleMenuBar(windowId: number): void;
}
export class WindowsManager implements IWindowsMainService, IWindowEventService {
export class WindowsManager implements IWindowsMainService {
_serviceBrand: any;
......@@ -134,12 +131,6 @@ export class WindowsManager implements IWindowsMainService, IWindowEventService
private initialUserEnv: platform.IProcessEnvironment;
private windowsState: IWindowsState;
private _onFocus = new Emitter<number>();
onWindowFocus: CommonEvent<number> = this._onFocus.event;
private _onNewWindow = new Emitter<number>();
onNewWindowOpen: CommonEvent<number> = this._onNewWindow.event;
private _onRecentPathsChange = new Emitter<void>();
onRecentPathsChange: CommonEvent<void> = this._onRecentPathsChange.event;
......@@ -754,9 +745,7 @@ export class WindowsManager implements IWindowsMainService, IWindowEventService
vscodeWindow.win.on('unresponsive', () => this.onWindowError(vscodeWindow, WindowError.UNRESPONSIVE));
vscodeWindow.win.on('close', () => this.onBeforeWindowClose(vscodeWindow));
vscodeWindow.win.on('closed', () => this.onWindowClosed(vscodeWindow));
vscodeWindow.win.on('focus', () => this._onFocus.fire(vscodeWindow.id));
this._onNewWindow.fire(vscodeWindow.id);
// Lifecycle
this.lifecycleService.registerWindow(vscodeWindow);
}
......
......@@ -32,8 +32,9 @@ import { AppInsightsAppender } from 'vs/platform/telemetry/node/appInsightsAppen
import { ISharedProcessInitData } from './sharedProcess';
import { IChoiceService } from 'vs/platform/message/common/message';
import { ChoiceChannelClient } from 'vs/platform/message/common/messageIpc';
import { WindowEventChannelClient } from 'vs/code/common/windowsIpc';
import { IWindowEventService, ActiveWindowManager } from 'vs/code/common/windows';
import { IWindowsService } from 'vs/platform/windows/common/windows';
import { WindowsChannelClient } from 'vs/platform/windows/common/windowsIpc';
import { ActiveWindowManager } from 'vs/code/common/windows';
function quit(err?: Error) {
if (err) {
......@@ -66,11 +67,11 @@ function main(server: Server, initData: ISharedProcessInitData): void {
services.set(IConfigurationService, new SyncDescriptor(ConfigurationService));
services.set(IRequestService, new SyncDescriptor(RequestService));
const windowEventChannel = server.getChannel('windowEvent', { route: () => 'main' });
const windowEventService: IWindowEventService = new WindowEventChannelClient(windowEventChannel);
services.set(IWindowEventService, windowEventService);
const windowsChannel = server.getChannel('windows', { route: () => 'main' });
const windowsService = new WindowsChannelClient(windowsChannel);
services.set(IWindowsService, windowsService);
const activeWindowManager = new ActiveWindowManager(windowEventService);
const activeWindowManager = new ActiveWindowManager(windowsService);
const choiceChannel = server.getChannel('choice', { route: () => activeWindowManager.activeClientId });
services.set(IChoiceService, new ChoiceChannelClient(choiceChannel));
......
......@@ -15,6 +15,7 @@ export interface IWindowsService {
_serviceBrand: any;
onWindowOpen: Event<number>;
onWindowFocus: Event<number>;
openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void>;
......
......@@ -11,6 +11,7 @@ import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/i
import { IWindowsService } from './windows';
export interface IWindowsChannel extends IChannel {
call(command: 'event:onWindowOpen'): TPromise<number>;
call(command: 'event:onWindowFocus'): TPromise<number>;
call(command: 'openFileFolderPicker', arg: [number, boolean]): TPromise<void>;
call(command: 'openFilePicker', arg: [number, boolean, string]): TPromise<void>;
......@@ -42,14 +43,17 @@ export interface IWindowsChannel extends IChannel {
export class WindowsChannel implements IWindowsChannel {
onWindowFocus: Event<number>;
private onWindowOpen: Event<number>;
private onWindowFocus: Event<number>;
constructor(private service: IWindowsService) {
this.onWindowOpen = buffer(service.onWindowOpen, true);
this.onWindowFocus = buffer(service.onWindowFocus, true);
}
call(command: string, arg?: any): TPromise<any> {
switch (command) {
case 'event:onWindowOpen': return eventToCall(this.onWindowOpen);
case 'event:onWindowFocus': return eventToCall(this.onWindowFocus);
case 'openFileFolderPicker': return this.service.openFileFolderPicker(arg[0], arg[1]);
case 'openFilePicker': return this.service.openFilePicker(arg[0], arg[1], arg[2]);
......@@ -87,6 +91,9 @@ export class WindowsChannelClient implements IWindowsService {
constructor(private channel: IWindowsChannel) { }
private _onWindowOpen: Event<number> = eventFromCall<number>(this.channel, 'event:onWindowOpen');
get onWindowOpen(): Event<number> { return this._onWindowOpen; }
private _onWindowFocus: Event<number> = eventFromCall<number>(this.channel, 'event:onWindowFocus');
get onWindowFocus(): Event<number> { return this._onWindowFocus; }
......
......@@ -19,6 +19,7 @@ export class WindowsService implements IWindowsService {
_serviceBrand: any;
onWindowOpen: Event<number> = fromEventEmitter(app, 'browser-window-created', (_, w: Electron.BrowserWindow) => w.id);
onWindowFocus: Event<number> = fromEventEmitter(app, 'browser-window-focus', (_, w: Electron.BrowserWindow) => w.id);
constructor(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册