Path: blob/main/src/vs/sessions/browser/web.factory.ts
13389 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 { IWorkbench, IWorkbenchConstructionOptions } from '../../workbench/browser/web.api.js';6import { SessionsBrowserMain } from './web.main.js';7import { IDisposable, toDisposable } from '../../base/common/lifecycle.js';8import { mark } from '../../base/common/performance.js';9import { DeferredPromise } from '../../base/common/async.js';10import { CommandsRegistry } from '../../platform/commands/common/commands.js';11import { MenuRegistry, MenuId } from '../../platform/actions/common/actions.js';1213const workbenchPromise = new DeferredPromise<IWorkbench>();1415/**16* Creates the Sessions workbench with the provided options in the provided container.17*/18export function create(domElement: HTMLElement, options: IWorkbenchConstructionOptions): IDisposable {1920mark('code/didLoadWorkbenchMain');2122// Register embedder commands (same as workbench/browser/web.factory.ts)23if (Array.isArray(options.commands)) {24for (const command of options.commands) {25CommandsRegistry.registerCommand(command.id, (_accessor, ...args) => {26return command.handler(...args);27});2829if (command.label) {30MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: command.id, title: command.label } });31}32}33}3435let instantiatedWorkbench: IWorkbench | undefined = undefined;36new SessionsBrowserMain(domElement, options).open().then(workbench => {37instantiatedWorkbench = workbench;38workbenchPromise.complete(workbench);39});4041return toDisposable(() => {42if (instantiatedWorkbench) {43instantiatedWorkbench.shutdown();44} else {45workbenchPromise.p.then(w => w.shutdown());46}47});48}495051