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
3296 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 { Event } from '../../../../base/common/event.js';
8
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
9
import { FocusMode } from '../../../../platform/native/common/native.js';
10
import { IWindowOpenable, IOpenWindowOptions, IOpenEmptyWindowOptions, IPoint, IRectangle } from '../../../../platform/window/common/window.js';
11
12
export const IHostService = createDecorator<IHostService>('hostService');
13
14
/**
15
* A set of methods supported in both web and native environments.
16
*
17
* @see {@link INativeHostService} for methods that are specific to native
18
* environments.
19
*/
20
export interface IHostService {
21
22
readonly _serviceBrand: undefined;
23
24
//#region Focus
25
26
/**
27
* Emitted when the focus of the window changes.
28
*
29
* Note: this considers the main window as well as auxiliary windows
30
* when they are in focus. As long as the main window or any of its
31
* auxiliary windows have focus, this event fires with `true`. It will
32
* fire with `false` when neither the main window nor any of its
33
* auxiliary windows have focus.
34
*/
35
readonly onDidChangeFocus: Event<boolean>;
36
37
/**
38
* Find out if the window or any of its auxiliary windows have focus.
39
*/
40
readonly hasFocus: boolean;
41
42
/**
43
* Find out if the window had the last focus.
44
*/
45
hadLastFocus(): Promise<boolean>;
46
47
/**
48
* Attempt to bring the window to the foreground and focus it.
49
*
50
* @param options How to focus the window, defaults to {@link FocusMode.Transfer}
51
*/
52
focus(targetWindow: Window, options?: { mode?: FocusMode }): Promise<void>;
53
54
//#endregion
55
56
//#region Window
57
58
/**
59
* Emitted when the active window changes between main window
60
* and auxiliary windows.
61
*/
62
readonly onDidChangeActiveWindow: Event<number>;
63
64
/**
65
* Emitted when the window with the given identifier changes
66
* its fullscreen state.
67
*/
68
readonly onDidChangeFullScreen: Event<{ windowId: number; fullscreen: boolean }>;
69
70
/**
71
* Opens an empty window. The optional parameter allows to define if
72
* a new window should open or the existing one change to an empty.
73
*/
74
openWindow(options?: IOpenEmptyWindowOptions): Promise<void>;
75
76
/**
77
* Opens the provided array of openables in a window with the provided options.
78
*/
79
openWindow(toOpen: IWindowOpenable[], options?: IOpenWindowOptions): Promise<void>;
80
81
/**
82
* Switch between fullscreen and normal window.
83
*/
84
toggleFullScreen(targetWindow: Window): Promise<void>;
85
86
/**
87
* Bring a window to the front and restore it if needed.
88
*/
89
moveTop(targetWindow: Window): Promise<void>;
90
91
/**
92
* Get the location of the mouse cursor and its display bounds or `undefined` if unavailable.
93
*/
94
getCursorScreenPoint(): Promise<{ readonly point: IPoint; readonly display: IRectangle } | undefined>;
95
96
//#endregion
97
98
//#region Lifecycle
99
100
/**
101
* Restart the entire application.
102
*/
103
restart(): Promise<void>;
104
105
/**
106
* Reload the currently active main window.
107
*/
108
reload(options?: { disableExtensions?: boolean }): Promise<void>;
109
110
/**
111
* Attempt to close the active main window.
112
*/
113
close(): Promise<void>;
114
115
/**
116
* Execute an asynchronous `expectedShutdownTask`. While this task is
117
* in progress, attempts to quit the application will not be vetoed with a dialog.
118
*/
119
withExpectedShutdown<T>(expectedShutdownTask: () => Promise<T>): Promise<T>;
120
121
//#endregion
122
123
//#region Screenshots
124
125
/**
126
* Captures a screenshot.
127
*/
128
getScreenshot(rect?: IRectangle): Promise<VSBuffer | undefined>;
129
130
//#endregion
131
132
//#region Native Handle
133
134
/**
135
* Get the native handle of the window.
136
*/
137
getNativeWindowHandle(windowId: number): Promise<VSBuffer | undefined>;
138
139
//#endregion
140
}
141
142