Skip to content

Commit df7dbe4

Browse files
committed
lint: fix urlIpc layer breakage
microsoft#15293
1 parent 3e4cce7 commit df7dbe4

4 files changed

Lines changed: 31 additions & 8 deletions

File tree

src/vs/platform/url/common/urlIpc.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
99
import { IChannel, eventToCall, eventFromCall, Serializer, Deserializer } from 'vs/base/parts/ipc/common/ipc';
1010
import { IURLService } from './url';
1111
import Event, { filterEvent } from 'vs/base/common/event';
12-
import { IWindowsMainService } from 'vs/code/electron-main/windows';
12+
import { IWindowsService } from 'vs/platform/windows/common/windows';
1313
import URI from 'vs/base/common/uri';
1414

1515
const URISerializer: Serializer<URI, any> = uri => uri.toJSON();
@@ -22,10 +22,17 @@ export interface IURLChannel extends IChannel {
2222

2323
export class URLChannel implements IURLChannel {
2424

25+
private focusedWindowId: number;
26+
2527
constructor(
2628
private service: IURLService,
27-
@IWindowsMainService private windowsService: IWindowsMainService
28-
) { }
29+
@IWindowsService windowsService: IWindowsService
30+
) {
31+
windowsService.onWindowFocus(id => {
32+
console.log(id);
33+
this.focusedWindowId = id;
34+
});
35+
}
2936

3037
call(command: string, arg?: any): TPromise<any> {
3138
switch (command) {
@@ -42,8 +49,7 @@ export class URLChannel implements IURLChannel {
4249
* and fire it only to the focused window.
4350
*/
4451
private isWindowFocused(windowID: number): boolean {
45-
const window = this.windowsService.getFocusedWindow() || this.windowsService.getLastActiveWindow();
46-
return window ? window.id === windowID : false;
52+
return this.focusedWindowId === windowID;
4753
}
4854
}
4955

src/vs/platform/windows/common/windows.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77

88
import { TPromise } from 'vs/base/common/winjs.base';
99
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
10+
import Event from 'vs/base/common/event';
1011

1112
export const IWindowsService = createDecorator<IWindowsService>('windowsService');
1213

1314
export interface IWindowsService {
1415

1516
_serviceBrand: any;
1617

18+
onWindowFocus: Event<number>;
19+
1720
openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void>;
1821
openFilePicker(windowId: number, forceNewWindow?: boolean, path?: string): TPromise<void>;
1922
openFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void>;

src/vs/platform/windows/common/windowsIpc.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
'use strict';
77

88
import { TPromise } from 'vs/base/common/winjs.base';
9-
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
9+
import Event, { buffer } from 'vs/base/common/event';
10+
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
1011
import { IWindowsService } from './windows';
1112

1213
export interface IWindowsChannel extends IChannel {
14+
call(command: 'event:onWindowFocus'): TPromise<number>;
1315
call(command: 'openFileFolderPicker', arg: [number, boolean]): TPromise<void>;
1416
call(command: 'openFilePicker', arg: [number, boolean, string]): TPromise<void>;
1517
call(command: 'openFolderPicker', arg: [number, boolean]): TPromise<void>;
@@ -40,10 +42,15 @@ export interface IWindowsChannel extends IChannel {
4042

4143
export class WindowsChannel implements IWindowsChannel {
4244

43-
constructor(private service: IWindowsService) { }
45+
onWindowFocus: Event<number>;
46+
47+
constructor(private service: IWindowsService) {
48+
this.onWindowFocus = buffer(service.onWindowFocus, true);
49+
}
4450

4551
call(command: string, arg?: any): TPromise<any> {
4652
switch (command) {
53+
case 'event:onWindowFocus': return eventToCall(this.onWindowFocus);
4754
case 'openFileFolderPicker': return this.service.openFileFolderPicker(arg[0], arg[1]);
4855
case 'openFilePicker': return this.service.openFilePicker(arg[0], arg[1], arg[2]);
4956
case 'openFolderPicker': return this.service.openFolderPicker(arg[0], arg[1]);
@@ -80,6 +87,9 @@ export class WindowsChannelClient implements IWindowsService {
8087

8188
constructor(private channel: IWindowsChannel) { }
8289

90+
private _onWindowFocus: Event<number> = eventFromCall<number>(this.channel, 'event:onWindowFocus');
91+
get onWindowFocus(): Event<number> { return this._onWindowFocus; }
92+
8393
openFileFolderPicker(windowId: number, forceNewWindow?: boolean): TPromise<void> {
8494
return this.channel.call('openFileFolderPicker', [windowId, forceNewWindow]);
8595
}

src/vs/platform/windows/electron-main/windowsService.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import { TPromise } from 'vs/base/common/winjs.base';
99
import { IWindowsService } from 'vs/platform/windows/common/windows';
1010
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
11-
import { shell, crashReporter } from 'electron';
11+
import { shell, crashReporter, app } from 'electron';
12+
import Event from 'vs/base/common/event';
13+
import { fromEventEmitter } from 'vs/base/node/event';
1214

1315
// TODO@Joao: remove this dependency, move all implementation to this class
1416
import { IWindowsMainService } from 'vs/code/electron-main/windows';
@@ -17,6 +19,8 @@ export class WindowsService implements IWindowsService {
1719

1820
_serviceBrand: any;
1921

22+
onWindowFocus: Event<number> = fromEventEmitter(app, 'browser-window-focus', (_, w: Electron.BrowserWindow) => w.id);
23+
2024
constructor(
2125
@IWindowsMainService private windowsMainService: IWindowsMainService,
2226
@IEnvironmentService private environmentService: IEnvironmentService

0 commit comments

Comments
 (0)