mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 06:38:23 +00:00
host - latch the change focus events
This commit is contained in:
parent
19c1c8ac0a
commit
9f07996c19
2 changed files with 10 additions and 12 deletions
|
@ -18,6 +18,7 @@ import { Disposable } from 'vs/base/common/lifecycle';
|
|||
import { URI } from 'vs/base/common/uri';
|
||||
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
|
||||
import { domEvent } from 'vs/base/browser/event';
|
||||
import { memoize } from 'vs/base/common/decorators';
|
||||
|
||||
/**
|
||||
* A workspace to open in the workbench can either be:
|
||||
|
@ -78,18 +79,15 @@ export class BrowserHostService extends Disposable implements IHostService {
|
|||
}
|
||||
}
|
||||
|
||||
private _onDidChangeFocus: Event<boolean> | undefined;
|
||||
@memoize
|
||||
get onDidChangeFocus(): Event<boolean> {
|
||||
if (!this._onDidChangeFocus) {
|
||||
const focusTracker = this._register(trackFocus(window));
|
||||
this._onDidChangeFocus = Event.any(
|
||||
Event.map(focusTracker.onDidFocus, () => this.hasFocus),
|
||||
Event.map(focusTracker.onDidBlur, () => this.hasFocus),
|
||||
Event.map(domEvent(window.document, 'visibilitychange'), () => this.hasFocus)
|
||||
);
|
||||
}
|
||||
const focusTracker = this._register(trackFocus(window));
|
||||
|
||||
return this._onDidChangeFocus;
|
||||
return Event.latch(Event.any(
|
||||
Event.map(focusTracker.onDidFocus, () => this.hasFocus),
|
||||
Event.map(focusTracker.onDidBlur, () => this.hasFocus),
|
||||
Event.map(domEvent(window.document, 'visibilitychange'), () => this.hasFocus)
|
||||
));
|
||||
}
|
||||
|
||||
get hasFocus(): boolean {
|
||||
|
|
|
@ -26,10 +26,10 @@ export class DesktopHostService extends Disposable implements IHostService {
|
|||
}
|
||||
|
||||
get onDidChangeFocus(): Event<boolean> { return this._onDidChangeFocus; }
|
||||
private _onDidChangeFocus: Event<boolean> = Event.any(
|
||||
private _onDidChangeFocus: Event<boolean> = Event.latch(Event.any(
|
||||
Event.map(Event.filter(this.electronService.onWindowFocus, id => id === this.environmentService.configuration.windowId), () => this.hasFocus),
|
||||
Event.map(Event.filter(this.electronService.onWindowBlur, id => id === this.environmentService.configuration.windowId), () => this.hasFocus)
|
||||
);
|
||||
));
|
||||
|
||||
get hasFocus(): boolean {
|
||||
return document.hasFocus();
|
||||
|
|
Loading…
Reference in a new issue