@@ -14,7 +14,7 @@ import product from 'vs/platform/node/product';
1414import { IWindowsService , OpenContext , INativeOpenDialogOptions , IEnterWorkspaceResult , IMessageBoxResult , IDevToolsOptions } from 'vs/platform/windows/common/windows' ;
1515import { IEnvironmentService , ParsedArgs } from 'vs/platform/environment/common/environment' ;
1616import { shell , crashReporter , app , Menu , clipboard , BrowserWindow } from 'electron' ;
17- import { Event , fromNodeEventEmitter , mapEvent , filterEvent , anyEvent } from 'vs/base/common/event' ;
17+ import { Event , fromNodeEventEmitter , mapEvent , filterEvent , anyEvent , latch } from 'vs/base/common/event' ;
1818import { IURLService , IURLHandler } from 'vs/platform/url/common/url' ;
1919import { ILifecycleService } from 'vs/platform/lifecycle/electron-main/lifecycleMain' ;
2020import { IWindowsMainService , ISharedProcess } from 'vs/platform/windows/electron-main/windows' ;
@@ -32,6 +32,8 @@ export class WindowsService implements IWindowsService, IURLHandler, IDisposable
3232
3333 private disposables : IDisposable [ ] = [ ] ;
3434
35+ private _activeWindowId : number | undefined ;
36+
3537 readonly onWindowOpen : Event < number > = filterEvent ( fromNodeEventEmitter ( app , 'browser-window-created' , ( _ , w : Electron . BrowserWindow ) => w . id ) , id => ! ! this . windowsMainService . getWindowById ( id ) ) ;
3638 readonly onWindowFocus : Event < number > = anyEvent (
3739 mapEvent ( filterEvent ( mapEvent ( this . windowsMainService . onWindowsCountChanged , ( ) => this . windowsMainService . getLastActiveWindow ( ) ) , w => ! ! w ) , w => w . id ) ,
@@ -54,6 +56,10 @@ export class WindowsService implements IWindowsService, IURLHandler, IDisposable
5456 @ILogService private logService : ILogService
5557 ) {
5658 urlService . registerHandler ( this ) ;
59+
60+ // remember last active window id
61+ latch ( anyEvent ( this . onWindowOpen , this . onWindowFocus ) )
62+ ( id => this . _activeWindowId = id , null , this . disposables ) ;
5763 }
5864
5965 pickFileFolderAndOpen ( options : INativeOpenDialogOptions ) : TPromise < void > {
@@ -435,6 +441,10 @@ export class WindowsService implements IWindowsService, IURLHandler, IDisposable
435441 return TPromise . as ( null ) ;
436442 }
437443
444+ getActiveWindowId ( ) : TPromise < number | undefined > {
445+ return TPromise . as ( this . _activeWindowId ) ;
446+ }
447+
438448 openExternal ( url : string ) : TPromise < boolean > {
439449 this . logService . trace ( 'windowsService#openExternal' ) ;
440450 return TPromise . as ( shell . openExternal ( url ) ) ;
0 commit comments