提交 6987cb0e 编写于 作者: J Joao Moreno

API: window.isFocused, window.onDidChangeWindowFocus

fixes #18263
上级 7f503e89
......@@ -167,4 +167,20 @@ declare module 'vscode' {
*/
export function deleteSecret(service: string, account: string): Thenable<boolean>;
}
export namespace window {
/**
* Whether the current window is focused.
*
* @readonly
*/
export let isFocused: boolean;
/**
* 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<boolean>;
}
}
......@@ -37,6 +37,7 @@ import { MainThreadFileSystemEventService } from './mainThreadFileSystemEventSer
import { MainThreadTask } from './mainThreadTask';
import { MainThreadSCM } from './mainThreadSCM';
import { MainThreadCredentials } from './mainThreadCredentials';
import { MainThreadWindow } from './mainThreadWindow';
// --- other interested parties
import { MainThreadDocumentsAndEditors } from './mainThreadDocumentsAndEditors';
......@@ -92,6 +93,7 @@ export class ExtHostContribution implements IWorkbenchContribution {
col.define(MainContext.MainThreadSCM).set(create(MainThreadSCM));
col.define(MainContext.MainThreadTask).set(create(MainThreadTask));
col.define(MainContext.MainThreadCredentials).set(create(MainThreadCredentials));
col.define(MainContext.MainThreadWindow).set(create(MainThreadWindow));
if (this.extensionService instanceof MainProcessExtensionService) {
col.define(MainContext.MainProcessExtensionService).set(<MainProcessExtensionService>this.extensionService);
}
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { TPromise } from 'vs/base/common/winjs.base';
import { IWindowService } from 'vs/platform/windows/common/windows';
import { MainThreadWindowShape, ExtHostWindowShape, ExtHostContext } from '../node/extHost.protocol';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
export class MainThreadWindow extends MainThreadWindowShape {
private readonly proxy: ExtHostWindowShape;
private disposables: IDisposable[] = [];
constructor(
@IThreadService threadService: IThreadService,
@IWindowService private windowService: IWindowService
) {
super();
this.proxy = threadService.get(ExtHostContext.ExtHostWindow);
windowService.onDidChangeFocus(this.proxy.$onDidChangeWindowFocus, this.proxy, this.disposables);
}
$getWindowVisibility(): TPromise<boolean> {
return this.windowService.isFocused();
}
dispose(): void {
this.disposables = dispose(this.disposables);
}
}
......@@ -36,6 +36,7 @@ import { ExtHostApiCommands } from 'vs/workbench/api/node/extHostApiCommands';
import { ExtHostTask } from 'vs/workbench/api/node/extHostTask';
import { ExtHostDebugService } from 'vs/workbench/api/node/extHostDebugService';
import { ExtHostCredentials } from 'vs/workbench/api/node/extHostCredentials';
import { ExtHostWindow } from 'vs/workbench/api/node/extHostWindow';
import * as extHostTypes from 'vs/workbench/api/node/extHostTypes';
import URI from 'vs/base/common/uri';
import Severity from 'vs/base/common/severity';
......@@ -96,6 +97,7 @@ export function createApiFactory(
const extHostSCM = col.define(ExtHostContext.ExtHostSCM).set<ExtHostSCM>(new ExtHostSCM(threadService, extHostCommands));
const extHostTask = col.define(ExtHostContext.ExtHostTask).set<ExtHostTask>(new ExtHostTask(threadService));
const extHostCredentials = col.define(ExtHostContext.ExtHostCredentials).set<ExtHostCredentials>(new ExtHostCredentials(threadService));
const extHostWindow = col.define(ExtHostContext.ExtHostWindow).set<ExtHostWindow>(new ExtHostWindow(threadService));
col.define(ExtHostContext.ExtHostExtensionService).set(extensionService);
col.finish(false, threadService);
......@@ -308,6 +310,12 @@ export function createApiFactory(
onDidCloseTerminal(listener, thisArg?, disposables?) {
return extHostTerminalService.onDidCloseTerminal(listener, thisArg, disposables);
},
get isFocused() {
return extHostWindow.isFocused;
},
onDidChangeWindowFocus: proposedApiFunction(extension, (listener, thisArg?, disposables?) => {
return extHostWindow.onDidChangeWindowFocus(listener, thisArg, disposables);
}),
showInformationMessage(message, first, ...rest) {
return extHostMessageService.showMessage(Severity.Info, message, first, rest);
},
......
......@@ -356,6 +356,10 @@ export abstract class MainThreadCredentialsShape {
$deleteSecret(service: string, account: string): Thenable<boolean> { throw ni(); }
}
export abstract class MainThreadWindowShape {
$getWindowVisibility(): TPromise<boolean> { throw ni(); }
}
// -- extension host
export abstract class ExtHostCommandsShape {
......@@ -515,6 +519,10 @@ export abstract class ExtHostDebugServiceShape {
export abstract class ExtHostCredentialsShape {
}
export abstract class ExtHostWindowShape {
$onDidChangeWindowFocus(value: boolean): void { throw ni(); }
}
// --- proxy identifiers
export const MainContext = {
......@@ -541,6 +549,7 @@ export const MainContext = {
MainThreadSCM: createMainId<MainThreadSCMShape>('MainThreadSCM', MainThreadSCMShape),
MainThreadTask: createMainId<MainThreadTaskShape>('MainThreadTask', MainThreadTaskShape),
MainThreadCredentials: createMainId<MainThreadCredentialsShape>('MainThreadCredentials', MainThreadCredentialsShape),
MainThreadWindow: createMainId<MainThreadWindowShape>('MainThreadWindow', MainThreadWindowShape),
};
export const ExtHostContext = {
......@@ -563,4 +572,5 @@ export const ExtHostContext = {
ExtHostTask: createExtId<ExtHostTaskShape>('ExtHostTask', ExtHostTaskShape),
ExtHostWorkspace: createExtId<ExtHostWorkspaceShape>('ExtHostWorkspace', ExtHostWorkspaceShape),
ExtHostCredentials: createExtId<ExtHostCredentialsShape>('ExtHostCredentials', ExtHostCredentialsShape),
ExtHostWindow: createExtId<ExtHostWindowShape>('ExtHostWindow', ExtHostWindowShape),
};
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import Event, { Emitter } from 'vs/base/common/event';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { ExtHostWindowShape, MainContext, MainThreadWindowShape } from './extHost.protocol';
export class ExtHostWindow implements ExtHostWindowShape {
private _proxy: MainThreadWindowShape;
private _onDidChangeWindowFocus = new Emitter<boolean>();
get onDidChangeWindowFocus(): Event<boolean> { return this._onDidChangeWindowFocus.event; }
private _isFocused = false;
get isFocused(): boolean { return this._isFocused; }
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) {
return;
}
this._isFocused = isFocused;
this._onDidChangeWindowFocus.fire(isFocused);
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册