From 2dac869dd9300b067cec77bc05414fe491fc2073 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Thu, 20 Jul 2017 18:20:57 +0200 Subject: [PATCH] api: WindowState --- src/vs/vscode.proposed.d.ts | 17 ++++++++++++--- src/vs/workbench/api/node/extHost.api.impl.ts | 8 +++---- src/vs/workbench/api/node/extHostWindow.ts | 21 ++++++++++++------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index f522a239c7b..6c3414040ab 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -168,19 +168,30 @@ declare module 'vscode' { export function deleteSecret(service: string, account: string): Thenable; } - export namespace window { + /** + * Represents the state of a window. + */ + export interface WindowState { /** * Whether the current window is focused. + */ + readonly focused: boolean; + } + + export namespace window { + + /** + * Represents the current window's state. * * @readonly */ - export let isFocused: boolean; + export let state: WindowState; /** * An [event](#Event) which fires when the focus state of the current window * changes. The value of the event represents whether the window is focused. */ - export const onDidChangeWindowFocus: Event; + export const onDidChangeWindowState: Event; } } diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index b49272536ed..dc5d9eaf89a 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -310,11 +310,11 @@ export function createApiFactory( onDidCloseTerminal(listener, thisArg?, disposables?) { return extHostTerminalService.onDidCloseTerminal(listener, thisArg, disposables); }, - get isFocused() { - return extHostWindow.isFocused; + get state() { + return extHostWindow.state; }, - onDidChangeWindowFocus: proposedApiFunction(extension, (listener, thisArg?, disposables?) => { - return extHostWindow.onDidChangeWindowFocus(listener, thisArg, disposables); + onDidChangeWindowState: proposedApiFunction(extension, (listener, thisArg?, disposables?) => { + return extHostWindow.onDidChangeWindowState(listener, thisArg, disposables); }), showInformationMessage(message, first, ...rest) { return extHostMessageService.showMessage(Severity.Info, message, first, rest); diff --git a/src/vs/workbench/api/node/extHostWindow.ts b/src/vs/workbench/api/node/extHostWindow.ts index 0d0dc69cbf6..cf8e0be930a 100644 --- a/src/vs/workbench/api/node/extHostWindow.ts +++ b/src/vs/workbench/api/node/extHostWindow.ts @@ -7,28 +7,33 @@ import Event, { Emitter } from 'vs/base/common/event'; import { IThreadService } from 'vs/workbench/services/thread/common/threadService'; import { ExtHostWindowShape, MainContext, MainThreadWindowShape } from './extHost.protocol'; +import { WindowState } from 'vscode'; export class ExtHostWindow implements ExtHostWindowShape { + private static InitialState: WindowState = { + focused: true + }; + private _proxy: MainThreadWindowShape; - private _onDidChangeWindowFocus = new Emitter(); - readonly onDidChangeWindowFocus: Event = this._onDidChangeWindowFocus.event; + private _onDidChangeWindowState = new Emitter(); + readonly onDidChangeWindowState: Event = this._onDidChangeWindowState.event; - private _isFocused = true; - get isFocused(): boolean { return this._isFocused; } + private _state = ExtHostWindow.InitialState; + get state(): WindowState { return this._state; } constructor(threadService: IThreadService) { this._proxy = threadService.get(MainContext.MainThreadWindow); this._proxy.$getWindowVisibility().then(isFocused => this.$onDidChangeWindowFocus(isFocused)); } - $onDidChangeWindowFocus(isFocused: boolean): void { - if (isFocused === this._isFocused) { + $onDidChangeWindowFocus(focused: boolean): void { + if (focused === this._state.focused) { return; } - this._isFocused = isFocused; - this._onDidChangeWindowFocus.fire(isFocused); + this._state = { ...this._state, focused }; + this._onDidChangeWindowState.fire(this._state); } } \ No newline at end of file -- GitLab