Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/host/browser/host.ts
5242 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { VSBuffer } from '../../../../base/common/buffer.js';
7
import { CancellationToken } from '../../../../base/common/cancellation.js';
8
import { Event } from '../../../../base/common/event.js';
9
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
10
import { FocusMode } from '../../../../platform/native/common/native.js';
11
import { IWindowOpenable, IOpenWindowOptions, IOpenEmptyWindowOptions, IPoint, IRectangle, IOpenedMainWindow, IOpenedAuxiliaryWindow } from '../../../../platform/window/common/window.js';
12
13
export const IHostService = createDecorator<IHostService>('hostService');
14
15
export interface IToastOptions {
16
readonly title: string;
17
readonly body?: string;
18
19
readonly actions?: readonly string[];
20
21
readonly silent?: boolean;
22
}
23
24
export interface IToastResult {
25
readonly supported: boolean;
26
27
readonly clicked: boolean;
28
readonly actionIndex?: number;
29
}
30
31
/**
32
* A set of methods supported in both web and native environments.
33
*
34
* @see {@link INativeHostService} for methods that are specific to native
35
* environments.
36
*/
37
export interface IHostService {
38
39
readonly _serviceBrand: undefined;
40
41
//#region Focus
42
43
/**
44
* Emitted when the focus of the window changes.
45
*
46
* Note: this considers the main window as well as auxiliary windows
47
* when they are in focus. As long as the main window or any of its
48
* auxiliary windows have focus, this event fires with `true`. It will
49
* fire with `false` when neither the main window nor any of its
50
* auxiliary windows have focus.
51
*/
52
readonly onDidChangeFocus: Event<boolean>;
53
54
/**
55
* Find out if the window or any of its auxiliary windows have focus.
56
*/
57
readonly hasFocus: boolean;
58
59
/**
60
* Find out if the window had the last focus.
61
*/
62
hadLastFocus(): Promise<boolean>;
63
64
/**
65
* Attempt to bring the window to the foreground and focus it.
66
*
67
* @param options How to focus the window, defaults to {@link FocusMode.Transfer}
68
*/
69
focus(targetWindow: Window, options?: { mode?: FocusMode }): Promise<void>;
70
71
//#endregion
72
73
//#region Window
74
75
/**
76
* Emitted when the active window changes between main window
77
* and auxiliary windows.
78
*/
79
readonly onDidChangeActiveWindow: Event<number>;
80
81
/**
82
* Emitted when the window with the given identifier changes
83
* its fullscreen state.
84
*/
85
readonly onDidChangeFullScreen: Event<{ windowId: number; fullscreen: boolean }>;
86
87
/**
88
* Opens an empty window. The optional parameter allows to define if
89
* a new window should open or the existing one change to an empty.
90
*/
91
openWindow(options?: IOpenEmptyWindowOptions): Promise<void>;
92
93
/**
94
* Opens the provided array of openables in a window with the provided options.
95
*/
96
openWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>;
97
98
/**
99
* Switch between fullscreen and normal window.
100
*/
101
toggleFullScreen(targetWindow: Window): Promise<void>;
102
103
/**
104
* Bring a window to the front and restore it if needed.
105
*/
106
moveTop(targetWindow: Window): Promise<void>;
107
108
/**
109
* Get the location of the mouse cursor and its display bounds or `undefined` if unavailable.
110
*/
111
getCursorScreenPoint(): Promise<{ readonly point: IPoint; readonly display: IRectangle } | undefined>;
112
113
/**
114
* Get the list of opened windows, optionally including auxiliary windows.
115
*/
116
getWindows(options: { includeAuxiliaryWindows: true }): Promise<Array<IOpenedMainWindow | IOpenedAuxiliaryWindow>>;
117
getWindows(options: { includeAuxiliaryWindows: false }): Promise<Array<IOpenedMainWindow>>;
118
119
//#endregion
120
121
//#region Lifecycle
122
123
/**
124
* Restart the entire application.
125
*/
126
restart(): Promise<void>;
127
128
/**
129
* Reload the currently active main window.
130
*/
131
reload(options?: { disableExtensions?: boolean }): Promise<void>;
132
133
/**
134
* Attempt to close the active main window.
135
*/
136
close(): Promise<void>;
137
138
/**
139
* Execute an asynchronous `expectedShutdownTask`. While this task is
140
* in progress, attempts to quit the application will not be vetoed with a dialog.
141
*/
142
withExpectedShutdown<T>(expectedShutdownTask: () => Promise<T>): Promise<T>;
143
144
//#endregion
145
146
//#region Screenshots
147
148
/**
149
* Captures a screenshot.
150
*/
151
getScreenshot(rect?: IRectangle): Promise<VSBuffer | undefined>;
152
153
//#endregion
154
155
//#region Native Handle
156
157
/**
158
* Get the native handle of the window.
159
*/
160
getNativeWindowHandle(windowId: number): Promise<VSBuffer | undefined>;
161
162
//#endregion
163
164
//#region Toast Notifications
165
166
/**
167
* Show an OS-level toast notification.
168
*/
169
showToast(options: IToastOptions, token: CancellationToken): Promise<IToastResult>;
170
171
//#endregion
172
}
173
174