提交 2e94e43a 编写于 作者: B Benjamin Pasero

fix #89317

上级 405eeab2
...@@ -157,15 +157,6 @@ export class ElectronMainService implements IElectronMainService { ...@@ -157,15 +157,6 @@ export class ElectronMainService implements IElectronMainService {
} }
} }
async isWindowFocused(windowId: number | undefined): Promise<boolean> {
const window = this.windowById(windowId);
if (window) {
return window.win.isFocused();
}
return false;
}
async focusWindow(windowId: number | undefined, options?: { windowId?: number; }): Promise<void> { async focusWindow(windowId: number | undefined, options?: { windowId?: number; }): Promise<void> {
if (options && typeof options.windowId === 'number') { if (options && typeof options.windowId === 'number') {
windowId = options.windowId; windowId = options.windowId;
......
...@@ -43,7 +43,6 @@ export interface IElectronService { ...@@ -43,7 +43,6 @@ export interface IElectronService {
unmaximizeWindow(): Promise<void>; unmaximizeWindow(): Promise<void>;
minimizeWindow(): Promise<void>; minimizeWindow(): Promise<void>;
isWindowFocused(): Promise<boolean>;
focusWindow(options?: { windowId?: number }): Promise<void>; focusWindow(options?: { windowId?: number }): Promise<void>;
// Dialogs // Dialogs
......
...@@ -24,26 +24,17 @@ export class DesktopHostService extends Disposable implements IHostService { ...@@ -24,26 +24,17 @@ export class DesktopHostService extends Disposable implements IHostService {
@IElectronEnvironmentService private readonly electronEnvironmentService: IElectronEnvironmentService @IElectronEnvironmentService private readonly electronEnvironmentService: IElectronEnvironmentService
) { ) {
super(); super();
// Resolve initial window focus state
this._hasFocus = document.hasFocus();
electronService.isWindowFocused().then(focused => this._hasFocus = focused);
this.registerListeners();
}
private registerListeners(): void {
this._register(this.onDidChangeFocus(focus => this._hasFocus = focus));
} }
get onDidChangeFocus(): Event<boolean> { return this._onDidChangeFocus; } get onDidChangeFocus(): Event<boolean> { return this._onDidChangeFocus; }
private _onDidChangeFocus: Event<boolean> = Event.any( private _onDidChangeFocus: Event<boolean> = Event.any(
Event.map(Event.filter(this.electronService.onWindowFocus, id => id === this.electronEnvironmentService.windowId), _ => true), Event.map(Event.filter(this.electronService.onWindowFocus, id => id === this.electronEnvironmentService.windowId), () => this.hasFocus),
Event.map(Event.filter(this.electronService.onWindowBlur, id => id === this.electronEnvironmentService.windowId), _ => false) Event.map(Event.filter(this.electronService.onWindowBlur, id => id === this.electronEnvironmentService.windowId), () => this.hasFocus)
); );
private _hasFocus: boolean; get hasFocus(): boolean {
get hasFocus(): boolean { return this._hasFocus; } return document.hasFocus();
}
openWindow(options?: IOpenEmptyWindowOptions): Promise<void>; openWindow(options?: IOpenEmptyWindowOptions): Promise<void>;
openWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>; openWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>;
......
...@@ -1404,7 +1404,6 @@ export class TestElectronService implements IElectronService { ...@@ -1404,7 +1404,6 @@ export class TestElectronService implements IElectronService {
async maximizeWindow(): Promise<void> { } async maximizeWindow(): Promise<void> { }
async unmaximizeWindow(): Promise<void> { } async unmaximizeWindow(): Promise<void> { }
async minimizeWindow(): Promise<void> { } async minimizeWindow(): Promise<void> { }
async isWindowFocused(): Promise<boolean> { return true; }
async focusWindow(options?: { windowId?: number | undefined; } | undefined): Promise<void> { } async focusWindow(options?: { windowId?: number | undefined; } | undefined): Promise<void> { }
async showMessageBox(options: Electron.MessageBoxOptions): Promise<Electron.MessageBoxReturnValue> { throw new Error('Method not implemented.'); } async showMessageBox(options: Electron.MessageBoxOptions): Promise<Electron.MessageBoxReturnValue> { throw new Error('Method not implemented.'); }
async showSaveDialog(options: Electron.SaveDialogOptions): Promise<Electron.SaveDialogReturnValue> { throw new Error('Method not implemented.'); } async showSaveDialog(options: Electron.SaveDialogOptions): Promise<Electron.SaveDialogReturnValue> { throw new Error('Method not implemented.'); }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册