UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

141 lines • 5.9 kB
// ***************************************************************************** // Copyright (C) 2023 EclipseSource and others. // // This program and the accompanying materials are made available under the // terms of the Eclipse Public License v. 2.0 which is available at // http://www.eclipse.org/legal/epl-2.0. // // This Source Code may also be made available under the following Secondary // Licenses when the conditions for such availability set forth in the Eclipse // Public License v. 2.0 are satisfied: GNU General Public License, version 2 // with the GNU Classpath Exception which is available at // https://www.gnu.org/software/classpath/license.html. // // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 // ***************************************************************************** import { ContainerModule } from 'inversify'; import { BackendStopwatch, CommandRegistry, Emitter, OS } from '../common/index.js'; import { ApplicationServer } from '../common/application-protocol.js'; import { EnvVariablesServer } from './../common/env-variables/index.js'; import { bindMessageService } from '../browser/frontend-application-bindings.js'; import { KeyStoreService } from '../common/key-store.js'; import { QuickPickService } from '../common/quick-pick-service.js'; import { QuickPickServiceImpl } from '../browser/quick-input/index.js'; import { BackendRequestService } from '@theia/request'; import { ConnectionStatus, ConnectionStatusService } from '../browser/connection-status-service.js'; export { bindMessageService }; // is loaded directly after the regular frontend module export const frontendOnlyApplicationModule = new ContainerModule((bind, unbind, isBound, rebind) => { if (isBound(CommandRegistry)) { rebind(CommandRegistry).toSelf().inSingletonScope(); } else { bind(CommandRegistry).toSelf().inSingletonScope(); } const stopwatch = { start: async (_name, _options) => -1, stop: async (_measurement, _message, _messageArgs) => { } }; if (isBound(BackendStopwatch)) { rebind(BackendStopwatch).toConstantValue(stopwatch); } else { bind(BackendStopwatch).toConstantValue(stopwatch); } if (isBound(CommandRegistry)) { rebind(QuickPickService).to(QuickPickServiceImpl).inSingletonScope(); } else { bind(QuickPickService).to(QuickPickServiceImpl).inSingletonScope(); } let extensionsCache; const mockedApplicationServer = { getExtensionsInfos: async () => { if (extensionsCache === undefined) { extensionsCache = (async () => { try { const res = await fetch('./extensions.json'); if (!res.ok) { extensionsCache = undefined; return []; } const raw = await res.json(); if (!Array.isArray(raw)) { extensionsCache = undefined; return []; } return raw; } catch { extensionsCache = undefined; return []; } })(); } return extensionsCache; }, getApplicationInfo: async () => undefined, getApplicationRoot: async () => '', getApplicationPlatform: () => Promise.resolve('web'), getBackendOS: async () => OS.Type.Linux }; if (isBound(ApplicationServer)) { rebind(ApplicationServer).toConstantValue(mockedApplicationServer); } else { bind(ApplicationServer).toConstantValue(mockedApplicationServer); } const varServer = { getExecPath: async () => '', getVariables: async () => [], getValue: async (_key) => undefined, // Matches the backend's default '.theia' configuration folder. getConfigDirUri: async () => 'file:///.theia', // Has to be a directory that already exists: consumers such as the file dialog only // resolve this, they never create it, and nothing seeds a home folder in OPFS. getHomeDirUri: async () => 'file:///', getDrives: async () => [] }; if (isBound(EnvVariablesServer)) { rebind(EnvVariablesServer).toConstantValue(varServer); } else { bind(EnvVariablesServer).toConstantValue(varServer); } const keyStoreService = { deletePassword: () => Promise.resolve(false), findCredentials: () => Promise.resolve([]), findPassword: () => Promise.resolve(undefined), setPassword: () => Promise.resolve(), getPassword: () => Promise.resolve(undefined), keys: () => Promise.resolve([]), }; if (isBound(KeyStoreService)) { rebind(KeyStoreService).toConstantValue(keyStoreService); } else { bind(KeyStoreService).toConstantValue(keyStoreService); } const requestService = { configure: () => Promise.resolve(), request: () => Promise.reject(), resolveProxy: () => Promise.resolve(undefined) }; if (isBound(BackendRequestService)) { rebind(BackendRequestService).toConstantValue(requestService); } else { bind(BackendRequestService).toConstantValue(requestService); } const connectionStatusService = { currentStatus: ConnectionStatus.ONLINE, onStatusChange: new Emitter().event }; if (isBound(ConnectionStatusService)) { rebind(ConnectionStatusService).toConstantValue(connectionStatusService); } else { bind(ConnectionStatusService).toConstantValue(connectionStatusService); } }); //# sourceMappingURL=frontend-only-application-module.js.map