Path: blob/main/src/vs/workbench/services/host/browser/host.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { VSBuffer } from '../../../../base/common/buffer.js';6import { Event } from '../../../../base/common/event.js';7import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';8import { FocusMode } from '../../../../platform/native/common/native.js';9import { IWindowOpenable, IOpenWindowOptions, IOpenEmptyWindowOptions, IPoint, IRectangle } from '../../../../platform/window/common/window.js';1011export const IHostService = createDecorator<IHostService>('hostService');1213/**14* A set of methods supported in both web and native environments.15*16* @see {@link INativeHostService} for methods that are specific to native17* environments.18*/19export interface IHostService {2021readonly _serviceBrand: undefined;2223//#region Focus2425/**26* Emitted when the focus of the window changes.27*28* Note: this considers the main window as well as auxiliary windows29* when they are in focus. As long as the main window or any of its30* auxiliary windows have focus, this event fires with `true`. It will31* fire with `false` when neither the main window nor any of its32* auxiliary windows have focus.33*/34readonly onDidChangeFocus: Event<boolean>;3536/**37* Find out if the window or any of its auxiliary windows have focus.38*/39readonly hasFocus: boolean;4041/**42* Find out if the window had the last focus.43*/44hadLastFocus(): Promise<boolean>;4546/**47* Attempt to bring the window to the foreground and focus it.48*49* @param options How to focus the window, defaults to {@link FocusMode.Transfer}50*/51focus(targetWindow: Window, options?: { mode?: FocusMode }): Promise<void>;5253//#endregion5455//#region Window5657/**58* Emitted when the active window changes between main window59* and auxiliary windows.60*/61readonly onDidChangeActiveWindow: Event<number>;6263/**64* Emitted when the window with the given identifier changes65* its fullscreen state.66*/67readonly onDidChangeFullScreen: Event<{ windowId: number; fullscreen: boolean }>;6869/**70* Opens an empty window. The optional parameter allows to define if71* a new window should open or the existing one change to an empty.72*/73openWindow(options?: IOpenEmptyWindowOptions): Promise<void>;7475/**76* Opens the provided array of openables in a window with the provided options.77*/78openWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>;7980/**81* Switch between fullscreen and normal window.82*/83toggleFullScreen(targetWindow: Window): Promise<void>;8485/**86* Bring a window to the front and restore it if needed.87*/88moveTop(targetWindow: Window): Promise<void>;8990/**91* Get the location of the mouse cursor and its display bounds or `undefined` if unavailable.92*/93getCursorScreenPoint(): Promise<{ readonly point: IPoint; readonly display: IRectangle } | undefined>;9495//#endregion9697//#region Lifecycle9899/**100* Restart the entire application.101*/102restart(): Promise<void>;103104/**105* Reload the currently active main window.106*/107reload(options?: { disableExtensions?: boolean }): Promise<void>;108109/**110* Attempt to close the active main window.111*/112close(): Promise<void>;113114/**115* Execute an asynchronous `expectedShutdownTask`. While this task is116* in progress, attempts to quit the application will not be vetoed with a dialog.117*/118withExpectedShutdown<T>(expectedShutdownTask: () => Promise<T>): Promise<T>;119120//#endregion121122//#region Screenshots123124/**125* Captures a screenshot.126*/127getScreenshot(rect?: IRectangle): Promise<VSBuffer | undefined>;128129//#endregion130131//#region Native Handle132133/**134* Get the native handle of the window.135*/136getNativeWindowHandle(windowId: number): Promise<VSBuffer | undefined>;137138//#endregion139}140141142