wip: send openUrl only to the active window
This commit is contained in:
parent
2f4aa9dee1
commit
7803b68ca1
|
@ -319,12 +319,12 @@ export function eventToCall(event: Event<any>): TPromise<any> {
|
|||
);
|
||||
}
|
||||
|
||||
export function eventFromCall<T>(channel: IChannel, name: string): Event<T> {
|
||||
export function eventFromCall<T>(channel: IChannel, name: string, arg: any = null): Event<T> {
|
||||
let promise: Promise;
|
||||
|
||||
const emitter = new Emitter<any>({
|
||||
onFirstListenerAdd: () => {
|
||||
promise = channel.call(name, null).then(null, err => null, e => emitter.fire(e));
|
||||
promise = channel.call(name, arg).then(null, err => null, e => emitter.fire(e));
|
||||
},
|
||||
onLastListenerRemove: () => {
|
||||
promise.cancel();
|
||||
|
|
|
@ -110,7 +110,10 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
|
|||
|
||||
// Register Electron IPC services
|
||||
const urlService = instantiationService.createInstance(URLService);
|
||||
const urlChannel = new URLChannel(urlService);
|
||||
const urlChannel = new URLChannel(urlService, id => {
|
||||
const window = windowsService.getFocusedWindow() || windowsService.getLastActiveWindow();
|
||||
return window ? window.id === id : false;
|
||||
});
|
||||
electronIpcServer.registerChannel('url', urlChannel);
|
||||
|
||||
// Used by sub processes to communicate back to the main instance
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { IURLService } from './url';
|
||||
import Event from 'vs/base/common/event';
|
||||
import Event, { filterEvent } from 'vs/base/common/event';
|
||||
|
||||
export interface IURLChannel extends IChannel {
|
||||
call(command: 'event:onOpenURL'): TPromise<void>;
|
||||
|
@ -17,11 +17,11 @@ export interface IURLChannel extends IChannel {
|
|||
|
||||
export class URLChannel implements IURLChannel {
|
||||
|
||||
constructor(private service: IURLService) { }
|
||||
constructor(private service: IURLService, private eventScope: (id: number) => boolean) { }
|
||||
|
||||
call(command: string, arg: any): TPromise<any> {
|
||||
switch (command) {
|
||||
case 'event:onOpenURL': return eventToCall(this.service.onOpenURL);
|
||||
case 'event:onOpenURL': return eventToCall(filterEvent(this.service.onOpenURL, () => this.eventScope(arg as number)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ export class URLChannelClient implements IURLService {
|
|||
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor(private channel: IChannel) { }
|
||||
constructor(private channel: IChannel, private id: number) { }
|
||||
|
||||
private _onOpenURL = eventFromCall<string>(this.channel, 'event:onOpenURL');
|
||||
private _onOpenURL = eventFromCall<string>(this.channel, 'event:onOpenURL', this.id);
|
||||
get onOpenURL(): Event<string> { return this._onOpenURL; }
|
||||
}
|
|
@ -323,7 +323,7 @@ export class WorkbenchShell {
|
|||
serviceCollection.set(IExtensionManagementService, extensionManagementChannelClient);
|
||||
|
||||
const urlChannel = mainProcessClient.getChannel('url');
|
||||
const urlChannelClient = instantiationService.createInstance(URLChannelClient, urlChannel);
|
||||
const urlChannelClient = instantiationService.createInstance(URLChannelClient, urlChannel, this.windowService.getWindowId());
|
||||
serviceCollection.set(IURLService, urlChannelClient);
|
||||
|
||||
return [instantiationService, serviceCollection];
|
||||
|
|
Loading…
Reference in a new issue