Skip to content

Commit 9f07996

Browse files
author
Benjamin Pasero
committed
host - latch the change focus events
1 parent 19c1c8a commit 9f07996

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

src/vs/workbench/services/host/browser/browserHostService.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
1818
import { URI } from 'vs/base/common/uri';
1919
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
2020
import { domEvent } from 'vs/base/browser/event';
21+
import { memoize } from 'vs/base/common/decorators';
2122

2223
/**
2324
* A workspace to open in the workbench can either be:
@@ -78,18 +79,15 @@ export class BrowserHostService extends Disposable implements IHostService {
7879
}
7980
}
8081

81-
private _onDidChangeFocus: Event<boolean> | undefined;
82+
@memoize
8283
get onDidChangeFocus(): Event<boolean> {
83-
if (!this._onDidChangeFocus) {
84-
const focusTracker = this._register(trackFocus(window));
85-
this._onDidChangeFocus = Event.any(
86-
Event.map(focusTracker.onDidFocus, () => this.hasFocus),
87-
Event.map(focusTracker.onDidBlur, () => this.hasFocus),
88-
Event.map(domEvent(window.document, 'visibilitychange'), () => this.hasFocus)
89-
);
90-
}
84+
const focusTracker = this._register(trackFocus(window));
9185

92-
return this._onDidChangeFocus;
86+
return Event.latch(Event.any(
87+
Event.map(focusTracker.onDidFocus, () => this.hasFocus),
88+
Event.map(focusTracker.onDidBlur, () => this.hasFocus),
89+
Event.map(domEvent(window.document, 'visibilitychange'), () => this.hasFocus)
90+
));
9391
}
9492

9593
get hasFocus(): boolean {

src/vs/workbench/services/host/electron-browser/desktopHostService.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export class DesktopHostService extends Disposable implements IHostService {
2626
}
2727

2828
get onDidChangeFocus(): Event<boolean> { return this._onDidChangeFocus; }
29-
private _onDidChangeFocus: Event<boolean> = Event.any(
29+
private _onDidChangeFocus: Event<boolean> = Event.latch(Event.any(
3030
Event.map(Event.filter(this.electronService.onWindowFocus, id => id === this.environmentService.configuration.windowId), () => this.hasFocus),
3131
Event.map(Event.filter(this.electronService.onWindowBlur, id => id === this.environmentService.configuration.windowId), () => this.hasFocus)
32-
);
32+
));
3333

3434
get hasFocus(): boolean {
3535
return document.hasFocus();

0 commit comments

Comments
 (0)