Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/browser/web.factory.ts
13389 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 { IWorkbench, IWorkbenchConstructionOptions } from '../../workbench/browser/web.api.js';
7
import { SessionsBrowserMain } from './web.main.js';
8
import { IDisposable, toDisposable } from '../../base/common/lifecycle.js';
9
import { mark } from '../../base/common/performance.js';
10
import { DeferredPromise } from '../../base/common/async.js';
11
import { CommandsRegistry } from '../../platform/commands/common/commands.js';
12
import { MenuRegistry, MenuId } from '../../platform/actions/common/actions.js';
13
14
const workbenchPromise = new DeferredPromise<IWorkbench>();
15
16
/**
17
* Creates the Sessions workbench with the provided options in the provided container.
18
*/
19
export function create(domElement: HTMLElement, options: IWorkbenchConstructionOptions): IDisposable {
20
21
mark('code/didLoadWorkbenchMain');
22
23
// Register embedder commands (same as workbench/browser/web.factory.ts)
24
if (Array.isArray(options.commands)) {
25
for (const command of options.commands) {
26
CommandsRegistry.registerCommand(command.id, (_accessor, ...args) => {
27
return command.handler(...args);
28
});
29
30
if (command.label) {
31
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: command.id, title: command.label } });
32
}
33
}
34
}
35
36
let instantiatedWorkbench: IWorkbench | undefined = undefined;
37
new SessionsBrowserMain(domElement, options).open().then(workbench => {
38
instantiatedWorkbench = workbench;
39
workbenchPromise.complete(workbench);
40
});
41
42
return toDisposable(() => {
43
if (instantiatedWorkbench) {
44
instantiatedWorkbench.shutdown();
45
} else {
46
workbenchPromise.p.then(w => w.shutdown());
47
}
48
});
49
}
50
51