@codingame/monaco-vscode-host-service-override 1.85.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ function __decorate(decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ }
7
+ function __param(paramIndex, decorator) {
8
+ return function (target, key) { decorator(target, key, paramIndex); }
9
+ }
10
+
11
+ export { __decorate, __param };
package/host.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { IEditorOverrideServices } from 'vscode/vscode/vs/editor/standalone/browser/standaloneServices';
2
+
3
+ declare function getServiceOverride(): IEditorOverrideServices;
4
+
5
+ export { getServiceOverride as default };
package/host.js ADDED
@@ -0,0 +1,14 @@
1
+ import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/common/descriptors.js';
2
+ import { IHostService } from 'vscode/vscode/vs/workbench/services/host/browser/host';
3
+ import { IHostColorSchemeService } from 'vscode/vscode/vs/workbench/services/themes/common/hostColorSchemeService';
4
+ import { BrowserHostService } from './vscode/src/vs/workbench/services/host/browser/browserHostService.js';
5
+ import { BrowserHostColorSchemeService } from './vscode/src/vs/workbench/services/themes/browser/browserHostColorSchemeService.js';
6
+
7
+ function getServiceOverride() {
8
+ return {
9
+ [( IHostService.toString())]: new SyncDescriptor(BrowserHostService, [], true),
10
+ [( IHostColorSchemeService.toString())]: new SyncDescriptor(BrowserHostColorSchemeService, [], true)
11
+ };
12
+ }
13
+
14
+ export { getServiceOverride as default };
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default } from './host.js';
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export { default } from './host.js';
@@ -0,0 +1,8 @@
1
+ var ConfirmResult;
2
+ ( (function(ConfirmResult) {
3
+ ConfirmResult[ConfirmResult["SAVE"] = 0] = "SAVE";
4
+ ConfirmResult[ConfirmResult["DONT_SAVE"] = 1] = "DONT_SAVE";
5
+ ConfirmResult[ConfirmResult["CANCEL"] = 2] = "CANCEL";
6
+ })(ConfirmResult || (ConfirmResult = {})));
7
+
8
+ export { ConfirmResult };
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@codingame/monaco-vscode-host-service-override",
3
+ "version": "1.85.2",
4
+ "keywords": [],
5
+ "author": {
6
+ "name": "CodinGame",
7
+ "url": "http://www.codingame.com"
8
+ },
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/CodinGame/monaco-vscode-api.git"
13
+ },
14
+ "type": "module",
15
+ "private": false,
16
+ "description": "VSCode public API plugged on the monaco editor - host service-override",
17
+ "main": "index.js",
18
+ "module": "index.js",
19
+ "types": "index.d.ts",
20
+ "dependencies": {
21
+ "vscode": "npm:@codingame/monaco-vscode-api@1.85.2",
22
+ "monaco-editor": "0.45.0"
23
+ }
24
+ }
@@ -0,0 +1,410 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { Emitter, Event } from 'monaco-editor/esm/vs/base/common/event.js';
3
+ import { ILayoutService } from 'monaco-editor/esm/vs/platform/layout/browser/layoutService.js';
4
+ import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
5
+ import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
6
+ import { isFolderToOpen, isWorkspaceToOpen, isFileToOpen } from 'vscode/vscode/vs/platform/window/common/window';
7
+ import { pathsToEditors, isResourceEditorInput } from 'vscode/vscode/vs/workbench/common/editor';
8
+ import { whenEditorClosed } from 'vscode/vscode/vs/workbench/browser/editor';
9
+ import { IFileService } from 'monaco-editor/esm/vs/platform/files/common/files.js';
10
+ import { ILabelService } from 'monaco-editor/esm/vs/platform/label/common/label.js';
11
+ import { ModifierKeyEmitter, onDidRegisterWindow, trackFocus, getActiveDocument, getWindowId, disposableWindowInterval } from 'monaco-editor/esm/vs/base/browser/dom.js';
12
+ import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
13
+ import { IBrowserWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/browser/environmentService';
14
+ import { memoize } from 'monaco-editor/esm/vs/base/common/decorators.js';
15
+ import { parseLineAndColumnAware } from 'monaco-editor/esm/vs/base/common/extpath.js';
16
+ import { IWorkspaceEditingService } from 'vscode/vscode/vs/workbench/services/workspaces/common/workspaceEditing';
17
+ import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
18
+ import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
19
+ import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
20
+ import { getWorkspaceIdentifier } from 'vscode/vscode/vs/workbench/services/workspaces/browser/workspaces';
21
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
22
+ import Severity from 'monaco-editor/esm/vs/base/common/severity.js';
23
+ import '../../../../../../../override/vs/platform/dialogs/common/dialogs.js';
24
+ import { DomEmitter } from 'monaco-editor/esm/vs/base/browser/event.js';
25
+ import { isUndefined } from 'monaco-editor/esm/vs/base/common/types.js';
26
+ import { isTemporaryWorkspace, IWorkspaceContextService } from 'monaco-editor/esm/vs/platform/workspace/common/workspace.js';
27
+ import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
28
+ import { IUserDataProfileService } from 'vscode/vscode/vs/workbench/services/userDataProfile/common/userDataProfile';
29
+ import { coalesce } from 'monaco-editor/esm/vs/base/common/arrays.js';
30
+ import { mainWindow, isAuxiliaryWindow } from 'monaco-editor/esm/vs/base/browser/window.js';
31
+ import { IDialogService } from 'vscode/vscode/vs/platform/dialogs/common/dialogs';
32
+
33
+ var HostShutdownReason;
34
+ ( (function(HostShutdownReason) {
35
+ HostShutdownReason[HostShutdownReason["Unknown"] = 1] = "Unknown";
36
+ HostShutdownReason[HostShutdownReason["Keyboard"] = 2] = "Keyboard";
37
+ HostShutdownReason[HostShutdownReason["Api"] = 3] = "Api";
38
+ })(HostShutdownReason || (HostShutdownReason = {})));
39
+ let BrowserHostService = class BrowserHostService extends Disposable {
40
+ constructor(layoutService, configurationService, fileService, labelService, environmentService, instantiationService, lifecycleService, logService, dialogService, contextService, userDataProfileService) {
41
+ super();
42
+ this.layoutService = layoutService;
43
+ this.configurationService = configurationService;
44
+ this.fileService = fileService;
45
+ this.labelService = labelService;
46
+ this.environmentService = environmentService;
47
+ this.instantiationService = instantiationService;
48
+ this.lifecycleService = lifecycleService;
49
+ this.logService = logService;
50
+ this.dialogService = dialogService;
51
+ this.contextService = contextService;
52
+ this.userDataProfileService = userDataProfileService;
53
+ this.shutdownReason = HostShutdownReason.Unknown;
54
+ if (environmentService.options?.workspaceProvider) {
55
+ this.workspaceProvider = environmentService.options.workspaceProvider;
56
+ }
57
+ else {
58
+ this.workspaceProvider = new class {
59
+ constructor() {
60
+ this.workspace = undefined;
61
+ this.trusted = undefined;
62
+ }
63
+ async open() { return true; }
64
+ };
65
+ }
66
+ this.registerListeners();
67
+ }
68
+ registerListeners() {
69
+ this._register(this.lifecycleService.onBeforeShutdown(e => this.onBeforeShutdown(e)));
70
+ this._register(ModifierKeyEmitter.getInstance().event(() => this.updateShutdownReasonFromEvent()));
71
+ }
72
+ onBeforeShutdown(e) {
73
+ switch (this.shutdownReason) {
74
+ case HostShutdownReason.Unknown:
75
+ case HostShutdownReason.Keyboard: {
76
+ const confirmBeforeClose = this.configurationService.getValue('window.confirmBeforeClose');
77
+ if (confirmBeforeClose === 'always' || (confirmBeforeClose === 'keyboardOnly' && this.shutdownReason === HostShutdownReason.Keyboard)) {
78
+ e.veto(true, 'veto.confirmBeforeClose');
79
+ }
80
+ break;
81
+ }
82
+ }
83
+ this.shutdownReason = HostShutdownReason.Unknown;
84
+ }
85
+ updateShutdownReasonFromEvent() {
86
+ if (this.shutdownReason === HostShutdownReason.Api) {
87
+ return;
88
+ }
89
+ if (ModifierKeyEmitter.getInstance().isModifierPressed) {
90
+ this.shutdownReason = HostShutdownReason.Keyboard;
91
+ }
92
+ else {
93
+ this.shutdownReason = HostShutdownReason.Unknown;
94
+ }
95
+ }
96
+ get onDidChangeFocus() {
97
+ const emitter = this._register(( new Emitter()));
98
+ this._register(Event.runAndSubscribe(onDidRegisterWindow, ({ window, disposables }) => {
99
+ const focusTracker = disposables.add(trackFocus(window));
100
+ const visibilityTracker = disposables.add(( new DomEmitter(window.document, 'visibilitychange')));
101
+ Event.any(( Event.map(focusTracker.onDidFocus, () => this.hasFocus, disposables)), ( Event.map(focusTracker.onDidBlur, () => this.hasFocus, disposables)), ( Event.map(visibilityTracker.event, () => this.hasFocus, disposables)), ( Event.map(this.onDidChangeActiveWindow, () => this.hasFocus, disposables)))(focus => emitter.fire(focus));
102
+ }, { window: mainWindow, disposables: this._store }));
103
+ return Event.latch(emitter.event, undefined, this._store);
104
+ }
105
+ get hasFocus() {
106
+ return getActiveDocument().hasFocus();
107
+ }
108
+ async hadLastFocus() {
109
+ return true;
110
+ }
111
+ async focus(targetWindow) {
112
+ targetWindow.focus();
113
+ }
114
+ get onDidChangeActiveWindow() {
115
+ const emitter = this._register(( new Emitter()));
116
+ this._register(Event.runAndSubscribe(onDidRegisterWindow, ({ window, disposables }) => {
117
+ const windowId = getWindowId(window);
118
+ const focusTracker = disposables.add(trackFocus(window));
119
+ disposables.add(focusTracker.onDidFocus(() => emitter.fire(windowId)));
120
+ if (isAuxiliaryWindow(window)) {
121
+ disposables.add(disposableWindowInterval(window, () => {
122
+ const hasFocus = window.document.hasFocus();
123
+ if (hasFocus) {
124
+ emitter.fire(windowId);
125
+ }
126
+ return hasFocus;
127
+ }, 100, 20));
128
+ }
129
+ }, { window: mainWindow, disposables: this._store }));
130
+ return Event.latch(emitter.event, undefined, this._store);
131
+ }
132
+ openWindow(arg1, arg2) {
133
+ if (Array.isArray(arg1)) {
134
+ return this.doOpenWindow(arg1, arg2);
135
+ }
136
+ return this.doOpenEmptyWindow(arg1);
137
+ }
138
+ async doOpenWindow(toOpen, options) {
139
+ const payload = this.preservePayload(false );
140
+ const fileOpenables = [];
141
+ const foldersToAdd = [];
142
+ for (const openable of toOpen) {
143
+ openable.label = openable.label || this.getRecentLabel(openable);
144
+ if (isFolderToOpen(openable)) {
145
+ if (options?.addMode) {
146
+ foldersToAdd.push(({ uri: openable.folderUri }));
147
+ }
148
+ else {
149
+ this.doOpen({ folderUri: openable.folderUri }, { reuse: this.shouldReuse(options, false ), payload });
150
+ }
151
+ }
152
+ else if (isWorkspaceToOpen(openable)) {
153
+ this.doOpen({ workspaceUri: openable.workspaceUri }, { reuse: this.shouldReuse(options, false ), payload });
154
+ }
155
+ else if (isFileToOpen(openable)) {
156
+ fileOpenables.push(openable);
157
+ }
158
+ }
159
+ if (foldersToAdd.length > 0) {
160
+ this.withServices(accessor => {
161
+ const workspaceEditingService = accessor.get(IWorkspaceEditingService);
162
+ workspaceEditingService.addFolders(foldersToAdd);
163
+ });
164
+ }
165
+ if (fileOpenables.length > 0) {
166
+ this.withServices(async (accessor) => {
167
+ const editorService = accessor.get(IEditorService);
168
+ if (options?.mergeMode && fileOpenables.length === 4) {
169
+ const editors = coalesce(await pathsToEditors(fileOpenables, this.fileService, this.logService));
170
+ if (editors.length !== 4 || !isResourceEditorInput(editors[0]) || !isResourceEditorInput(editors[1]) || !isResourceEditorInput(editors[2]) || !isResourceEditorInput(editors[3])) {
171
+ return;
172
+ }
173
+ if (this.shouldReuse(options, true )) {
174
+ editorService.openEditor({
175
+ input1: { resource: editors[0].resource },
176
+ input2: { resource: editors[1].resource },
177
+ base: { resource: editors[2].resource },
178
+ result: { resource: editors[3].resource },
179
+ options: { pinned: true }
180
+ });
181
+ }
182
+ else {
183
+ const environment = ( new Map());
184
+ environment.set('mergeFile1', ( editors[0].resource.toString()));
185
+ environment.set('mergeFile2', ( editors[1].resource.toString()));
186
+ environment.set('mergeFileBase', ( editors[2].resource.toString()));
187
+ environment.set('mergeFileResult', ( editors[3].resource.toString()));
188
+ this.doOpen(undefined, { payload: Array.from(environment.entries()) });
189
+ }
190
+ }
191
+ if (options?.diffMode && fileOpenables.length === 2) {
192
+ const editors = coalesce(await pathsToEditors(fileOpenables, this.fileService, this.logService));
193
+ if (editors.length !== 2 || !isResourceEditorInput(editors[0]) || !isResourceEditorInput(editors[1])) {
194
+ return;
195
+ }
196
+ if (this.shouldReuse(options, true )) {
197
+ editorService.openEditor({
198
+ original: { resource: editors[0].resource },
199
+ modified: { resource: editors[1].resource },
200
+ options: { pinned: true }
201
+ });
202
+ }
203
+ else {
204
+ const environment = ( new Map());
205
+ environment.set('diffFileSecondary', ( editors[0].resource.toString()));
206
+ environment.set('diffFilePrimary', ( editors[1].resource.toString()));
207
+ this.doOpen(undefined, { payload: Array.from(environment.entries()) });
208
+ }
209
+ }
210
+ else {
211
+ for (const openable of fileOpenables) {
212
+ if (this.shouldReuse(options, true )) {
213
+ let openables = [];
214
+ if (options?.gotoLineMode) {
215
+ const pathColumnAware = parseLineAndColumnAware(openable.fileUri.path);
216
+ openables = [{
217
+ fileUri: openable.fileUri.with({ path: pathColumnAware.path }),
218
+ options: {
219
+ selection: !isUndefined(pathColumnAware.line) ? { startLineNumber: pathColumnAware.line, startColumn: pathColumnAware.column || 1 } : undefined
220
+ }
221
+ }];
222
+ }
223
+ else {
224
+ openables = [openable];
225
+ }
226
+ editorService.openEditors(coalesce(await pathsToEditors(openables, this.fileService, this.logService)), undefined, { validateTrust: true });
227
+ }
228
+ else {
229
+ const environment = ( new Map());
230
+ environment.set('openFile', ( openable.fileUri.toString()));
231
+ if (options?.gotoLineMode) {
232
+ environment.set('gotoLineMode', 'true');
233
+ }
234
+ this.doOpen(undefined, { payload: Array.from(environment.entries()) });
235
+ }
236
+ }
237
+ }
238
+ const waitMarkerFileURI = options?.waitMarkerFileURI;
239
+ if (waitMarkerFileURI) {
240
+ (async () => {
241
+ await this.instantiationService.invokeFunction(accessor => whenEditorClosed(accessor, ( fileOpenables.map(fileOpenable => fileOpenable.fileUri))));
242
+ await this.fileService.del(waitMarkerFileURI);
243
+ })();
244
+ }
245
+ });
246
+ }
247
+ }
248
+ withServices(fn) {
249
+ this.instantiationService.invokeFunction(accessor => fn(accessor));
250
+ }
251
+ preservePayload(isEmptyWindow) {
252
+ const newPayload = ( new Array());
253
+ if (!isEmptyWindow && this.environmentService.extensionDevelopmentLocationURI) {
254
+ newPayload.push(['extensionDevelopmentPath', ( this.environmentService.extensionDevelopmentLocationURI.toString())]);
255
+ if (this.environmentService.debugExtensionHost.debugId) {
256
+ newPayload.push(['debugId', this.environmentService.debugExtensionHost.debugId]);
257
+ }
258
+ if (this.environmentService.debugExtensionHost.port) {
259
+ newPayload.push(['inspect-brk-extensions', String(this.environmentService.debugExtensionHost.port)]);
260
+ }
261
+ }
262
+ if (!this.userDataProfileService.currentProfile.isDefault) {
263
+ newPayload.push(['lastActiveProfile', this.userDataProfileService.currentProfile.id]);
264
+ }
265
+ return newPayload.length ? newPayload : undefined;
266
+ }
267
+ getRecentLabel(openable) {
268
+ if (isFolderToOpen(openable)) {
269
+ return this.labelService.getWorkspaceLabel(openable.folderUri, { verbose: 2 });
270
+ }
271
+ if (isWorkspaceToOpen(openable)) {
272
+ return this.labelService.getWorkspaceLabel(getWorkspaceIdentifier(openable.workspaceUri), { verbose: 2 });
273
+ }
274
+ return this.labelService.getUriLabel(openable.fileUri);
275
+ }
276
+ shouldReuse(options = Object.create(null), isFile) {
277
+ if (options.waitMarkerFileURI) {
278
+ return true;
279
+ }
280
+ const windowConfig = this.configurationService.getValue('window');
281
+ const openInNewWindowConfig = isFile ? ((windowConfig?.openFilesInNewWindow || 'off') ) : ((windowConfig?.openFoldersInNewWindow || 'default') );
282
+ let openInNewWindow = (options.preferNewWindow || !!options.forceNewWindow) && !options.forceReuseWindow;
283
+ if (!options.forceNewWindow && !options.forceReuseWindow && (openInNewWindowConfig === 'on' || openInNewWindowConfig === 'off')) {
284
+ openInNewWindow = (openInNewWindowConfig === 'on');
285
+ }
286
+ return !openInNewWindow;
287
+ }
288
+ async doOpenEmptyWindow(options) {
289
+ return this.doOpen(undefined, {
290
+ reuse: options?.forceReuseWindow,
291
+ payload: this.preservePayload(true )
292
+ });
293
+ }
294
+ async doOpen(workspace, options) {
295
+ if (workspace && isFolderToOpen(workspace) && workspace.folderUri.scheme === Schemas.file && isTemporaryWorkspace(this.contextService.getWorkspace())) {
296
+ this.withServices(async (accessor) => {
297
+ const workspaceEditingService = accessor.get(IWorkspaceEditingService);
298
+ await workspaceEditingService.updateFolders(0, this.contextService.getWorkspace().folders.length, [{ uri: workspace.folderUri }]);
299
+ });
300
+ return;
301
+ }
302
+ if (options?.reuse) {
303
+ await this.handleExpectedShutdown(4 );
304
+ }
305
+ const opened = await this.workspaceProvider.open(workspace, options);
306
+ if (!opened) {
307
+ const { confirmed } = await this.dialogService.confirm({
308
+ type: Severity.Warning,
309
+ message: ( localizeWithPath(
310
+ 'vs/workbench/services/host/browser/browserHostService',
311
+ 'unableToOpenExternal',
312
+ "The browser interrupted the opening of a new tab or window. Press 'Open' to open it anyway."
313
+ )),
314
+ primaryButton: ( localizeWithPath(
315
+ 'vs/workbench/services/host/browser/browserHostService',
316
+ { key: 'open', comment: ['&& denotes a mnemonic'] },
317
+ "&&Open"
318
+ ))
319
+ });
320
+ if (confirmed) {
321
+ await this.workspaceProvider.open(workspace, options);
322
+ }
323
+ }
324
+ }
325
+ async toggleFullScreen(targetWindow) {
326
+ const target = this.layoutService.getContainer(targetWindow);
327
+ if (targetWindow.document.fullscreen !== undefined) {
328
+ if (!targetWindow.document.fullscreen) {
329
+ try {
330
+ return await target.requestFullscreen();
331
+ }
332
+ catch (error) {
333
+ this.logService.warn('toggleFullScreen(): requestFullscreen failed');
334
+ }
335
+ }
336
+ else {
337
+ try {
338
+ return await targetWindow.document.exitFullscreen();
339
+ }
340
+ catch (error) {
341
+ this.logService.warn('toggleFullScreen(): exitFullscreen failed');
342
+ }
343
+ }
344
+ }
345
+ if (targetWindow.document.webkitIsFullScreen !== undefined) {
346
+ try {
347
+ if (!targetWindow.document.webkitIsFullScreen) {
348
+ target.webkitRequestFullscreen();
349
+ }
350
+ else {
351
+ targetWindow.document.webkitExitFullscreen();
352
+ }
353
+ }
354
+ catch {
355
+ this.logService.warn('toggleFullScreen(): requestFullscreen/exitFullscreen failed');
356
+ }
357
+ }
358
+ }
359
+ async moveTop(targetWindow) {
360
+ }
361
+ async getCursorScreenPoint() {
362
+ return undefined;
363
+ }
364
+ async restart() {
365
+ this.reload();
366
+ }
367
+ async reload() {
368
+ await this.handleExpectedShutdown(3 );
369
+ mainWindow.location.reload();
370
+ }
371
+ async close() {
372
+ await this.handleExpectedShutdown(1 );
373
+ mainWindow.close();
374
+ }
375
+ async withExpectedShutdown(expectedShutdownTask) {
376
+ const previousShutdownReason = this.shutdownReason;
377
+ try {
378
+ this.shutdownReason = HostShutdownReason.Api;
379
+ return await expectedShutdownTask();
380
+ }
381
+ finally {
382
+ this.shutdownReason = previousShutdownReason;
383
+ }
384
+ }
385
+ async handleExpectedShutdown(reason) {
386
+ this.shutdownReason = HostShutdownReason.Api;
387
+ return this.lifecycleService.withExpectedShutdown(reason);
388
+ }
389
+ };
390
+ BrowserHostService.__decorator = ( __decorate([
391
+ memoize
392
+ ], BrowserHostService.prototype, "onDidChangeFocus", null));
393
+ BrowserHostService.__decorator = ( __decorate([
394
+ memoize
395
+ ], BrowserHostService.prototype, "onDidChangeActiveWindow", null));
396
+ BrowserHostService = ( __decorate([
397
+ ( __param(0, ILayoutService)),
398
+ ( __param(1, IConfigurationService)),
399
+ ( __param(2, IFileService)),
400
+ ( __param(3, ILabelService)),
401
+ ( __param(4, IBrowserWorkbenchEnvironmentService)),
402
+ ( __param(5, IInstantiationService)),
403
+ ( __param(6, ILifecycleService)),
404
+ ( __param(7, ILogService)),
405
+ ( __param(8, IDialogService)),
406
+ ( __param(9, IWorkspaceContextService)),
407
+ ( __param(10, IUserDataProfileService))
408
+ ], BrowserHostService));
409
+
410
+ export { BrowserHostService };
@@ -0,0 +1,40 @@
1
+ import { Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
2
+ import { addMatchMediaChangeListener } from 'monaco-editor/esm/vs/base/browser/browser.js';
3
+ import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
4
+ import { mainWindow } from 'monaco-editor/esm/vs/base/browser/window.js';
5
+
6
+ class BrowserHostColorSchemeService extends Disposable {
7
+ constructor() {
8
+ super();
9
+ this._onDidSchemeChangeEvent = this._register(( new Emitter()));
10
+ this.registerListeners();
11
+ }
12
+ registerListeners() {
13
+ addMatchMediaChangeListener('(prefers-color-scheme: dark)', () => {
14
+ this._onDidSchemeChangeEvent.fire();
15
+ });
16
+ addMatchMediaChangeListener('(forced-colors: active)', () => {
17
+ this._onDidSchemeChangeEvent.fire();
18
+ });
19
+ }
20
+ get onDidChangeColorScheme() {
21
+ return this._onDidSchemeChangeEvent.event;
22
+ }
23
+ get dark() {
24
+ if (mainWindow.matchMedia(`(prefers-color-scheme: light)`).matches) {
25
+ return false;
26
+ }
27
+ else if (mainWindow.matchMedia(`(prefers-color-scheme: dark)`).matches) {
28
+ return true;
29
+ }
30
+ return false;
31
+ }
32
+ get highContrast() {
33
+ if (mainWindow.matchMedia(`(forced-colors: active)`).matches) {
34
+ return true;
35
+ }
36
+ return false;
37
+ }
38
+ }
39
+
40
+ export { BrowserHostColorSchemeService };