33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { Disposable } from 'vs/base/common/lifecycle' ;
6+ import { Disposable , DisposableStore } from 'vs/base/common/lifecycle' ;
77import { assign } from 'vs/base/common/objects' ;
88import { URI } from 'vs/base/common/uri' ;
99import { IWindowsService , OpenContext } from 'vs/platform/windows/common/windows' ;
@@ -23,6 +23,10 @@ export class LegacyWindowsMainService extends Disposable implements IWindowsServ
2323
2424 _serviceBrand : undefined ;
2525
26+ private readonly disposables = this . _register ( new DisposableStore ( ) ) ;
27+
28+ private _activeWindowId : number | undefined ;
29+
2630 readonly onWindowOpen : Event < number > = Event . filter ( Event . fromNodeEventEmitter ( app , 'browser-window-created' , ( _ , w : BrowserWindow ) => w . id ) , id => ! ! this . windowsMainService . getWindowById ( id ) ) ;
2731 readonly onWindowBlur : Event < number > = Event . filter ( Event . fromNodeEventEmitter ( app , 'browser-window-blur' , ( _ , w : BrowserWindow ) => w . id ) , id => ! ! this . windowsMainService . getWindowById ( id ) ) ;
2832 readonly onWindowMaximize : Event < number > = Event . filter ( Event . fromNodeEventEmitter ( app , 'browser-window-maximize' , ( _ , w : BrowserWindow ) => w . id ) , id => ! ! this . windowsMainService . getWindowById ( id ) ) ;
@@ -44,6 +48,10 @@ export class LegacyWindowsMainService extends Disposable implements IWindowsServ
4448 super ( ) ;
4549
4650 urlService . registerHandler ( this ) ;
51+
52+ // remember last active window id
53+ Event . latch ( Event . any ( this . onWindowOpen , this . onWindowFocus ) )
54+ ( id => this . _activeWindowId = id , null , this . disposables ) ;
4755 }
4856
4957 async addRecentlyOpened ( recents : IRecent [ ] ) : Promise < void > {
@@ -88,6 +96,10 @@ export class LegacyWindowsMainService extends Disposable implements IWindowsServ
8896 }
8997 }
9098
99+ async getActiveWindowId ( ) : Promise < number | undefined > {
100+ return this . _activeWindowId ;
101+ }
102+
91103 async handleURL ( uri : URI ) : Promise < boolean > {
92104
93105 // Catch file URLs
0 commit comments