File size: 1,601 Bytes
4e23b01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { createDecorator, type ServiceIdentifier } from '#/_base/di/instantiation';
import { ScopeActivation, registerScopedService } from '#/_base/di/scope';
import { LifecycleScope } from '#/app/scopes';
import { IHostEnvironment } from '#/os/interface/hostEnvironment';
import { IHostFileSystem } from '#/os/interface/hostFileSystem';
import { IHostProcessService } from '#/os/interface/hostProcess';
import { IHostTerminalService } from '#/os/interface/terminal';

import { LocalRuntime } from './localRuntime';
import type { Runtime } from './runtime';

export interface IStandaloneRuntimeFactory {
  readonly _serviceBrand: undefined;
  createLocalRuntime(workspaceId: string): Runtime;
}

export const IStandaloneRuntimeFactory: ServiceIdentifier<IStandaloneRuntimeFactory> =
  createDecorator<IStandaloneRuntimeFactory>('standaloneRuntimeFactory');

export class StandaloneRuntimeFactory implements IStandaloneRuntimeFactory {
  declare readonly _serviceBrand: undefined;

  constructor(
    @IHostEnvironment private readonly environment: IHostEnvironment,
    @IHostFileSystem private readonly fs: IHostFileSystem,
    @IHostProcessService private readonly process: IHostProcessService,
    @IHostTerminalService private readonly terminal: IHostTerminalService,
  ) {}

  createLocalRuntime(workspaceId: string): Runtime {
    return new LocalRuntime(workspaceId, this.environment, this.fs, this.process, this.terminal);
  }
}

registerScopedService(
  LifecycleScope.App,
  IStandaloneRuntimeFactory,
  StandaloneRuntimeFactory,
  ScopeActivation.OnDemand,
  'standaloneRuntimeFactory',
);