Path: blob/main/src/vs/workbench/services/host/browser/host.ts
5242 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 { CancellationToken } from '../../../../base/common/cancellation.js';7import { Event } from '../../../../base/common/event.js';8import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';9import { FocusMode } from '../../../../platform/native/common/native.js';10import { IWindowOpenable, IOpenWindowOptions, IOpenEmptyWindowOptions, IPoint, IRectangle, IOpenedMainWindow, IOpenedAuxiliaryWindow } from '../../../../platform/window/common/window.js';1112export const IHostService = createDecorator<IHostService>('hostService');1314export interface IToastOptions {15readonly title: string;16readonly body?: string;1718readonly actions?: readonly string[];1920readonly silent?: boolean;21}2223export interface IToastResult {24readonly supported: boolean;2526readonly clicked: boolean;27readonly actionIndex?: number;28}2930/**31* A set of methods supported in both web and native environments.32*33* @see {@link INativeHostService} for methods that are specific to native34* environments.35*/36export interface IHostService {3738readonly _serviceBrand: undefined;3940//#region Focus4142/**43* Emitted when the focus of the window changes.44*45* Note: this considers the main window as well as auxiliary windows46* when they are in focus. As long as the main window or any of its47* auxiliary windows have focus, this event fires with `true`. It will48* fire with `false` when neither the main window nor any of its49* auxiliary windows have focus.50*/51readonly onDidChangeFocus: Event<boolean>;5253/**54* Find out if the window or any of its auxiliary windows have focus.55*/56readonly hasFocus: boolean;5758/**59* Find out if the window had the last focus.60*/61hadLastFocus(): Promise<boolean>;6263/**64* Attempt to bring the window to the foreground and focus it.65*66* @param options How to focus the window, defaults to {@link FocusMode.Transfer}67*/68focus(targetWindow: Window, options?: { mode?: FocusMode }): Promise<void>;6970//#endregion7172//#region Window7374/**75* Emitted when the active window changes between main window76* and auxiliary windows.77*/78readonly onDidChangeActiveWindow: Event<number>;7980/**81* Emitted when the window with the given identifier changes82* its fullscreen state.83*/84readonly onDidChangeFullScreen: Event<{ windowId: number; fullscreen: boolean }>;8586/**87* Opens an empty window. The optional parameter allows to define if88* a new window should open or the existing one change to an empty.89*/90openWindow(options?: IOpenEmptyWindowOptions): Promise<void>;9192/**93* Opens the provided array of openables in a window with the provided options.94*/95openWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>;9697/**98* Switch between fullscreen and normal window.99*/100toggleFullScreen(targetWindow: Window): Promise<void>;101102/**103* Bring a window to the front and restore it if needed.104*/105moveTop(targetWindow: Window): Promise<void>;106107/**108* Get the location of the mouse cursor and its display bounds or `undefined` if unavailable.109*/110getCursorScreenPoint(): Promise<{ readonly point: IPoint; readonly display: IRectangle } | undefined>;111112/**113* Get the list of opened windows, optionally including auxiliary windows.114*/115getWindows(options: { includeAuxiliaryWindows: true }): Promise<Array<IOpenedMainWindow | IOpenedAuxiliaryWindow>>;116getWindows(options: { includeAuxiliaryWindows: false }): Promise<Array<IOpenedMainWindow>>;117118//#endregion119120//#region Lifecycle121122/**123* Restart the entire application.124*/125restart(): Promise<void>;126127/**128* Reload the currently active main window.129*/130reload(options?: { disableExtensions?: boolean }): Promise<void>;131132/**133* Attempt to close the active main window.134*/135close(): Promise<void>;136137/**138* Execute an asynchronous `expectedShutdownTask`. While this task is139* in progress, attempts to quit the application will not be vetoed with a dialog.140*/141withExpectedShutdown<T>(expectedShutdownTask: () => Promise<T>): Promise<T>;142143//#endregion144145//#region Screenshots146147/**148* Captures a screenshot.149*/150getScreenshot(rect?: IRectangle): Promise<VSBuffer | undefined>;151152//#endregion153154//#region Native Handle155156/**157* Get the native handle of the window.158*/159getNativeWindowHandle(windowId: number): Promise<VSBuffer | undefined>;160161//#endregion162163//#region Toast Notifications164165/**166* Show an OS-level toast notification.167*/168showToast(options: IToastOptions, token: CancellationToken): Promise<IToastResult>;169170//#endregion171}172173174