refactor(launcher): add DI, IUpdateEngine facade, and architecture tests

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
lincube
2026-05-28 11:13:14 +08:00
parent a26b6faace
commit 1ef47c780b
31 changed files with 167 additions and 1511 deletions

View File

@@ -19,17 +19,8 @@ internal static class LauncherCompositionRoot
CommandContext context,
string appRoot,
StartupAttemptRegistry startupAttemptRegistry,
LauncherCoordinatorIpcServer coordinatorServer)
{
var deploymentLocator = new DeploymentLocator(appRoot);
return new LauncherOrchestrator(
context,
deploymentLocator,
new OobeStateService(appRoot),
new UpdateEngineService(deploymentLocator),
startupAttemptRegistry,
coordinatorServer);
}
LauncherCoordinatorIpcServer coordinatorServer) =>
LauncherServiceRegistration.CreateOrchestrator(context, startupAttemptRegistry, coordinatorServer);
public static async Task RunOrchestratorWithSplashAsync(
IClassicDesktopStyleApplicationLifetime desktop,
@@ -161,7 +152,7 @@ internal static class LauncherCompositionRoot
{
var appRoot = Commands.ResolveAppRoot(context);
var deploymentLocator = new DeploymentLocator(appRoot);
var updateEngine = new UpdateEngineService(deploymentLocator);
var updateEngine = new UpdateEngineFacade(deploymentLocator);
var pluginInstaller = new PluginInstallerService();
var pluginUpgrades = new PluginUpgradeQueueService(pluginInstaller);

View File

@@ -13,7 +13,7 @@ internal sealed class LauncherOrchestrator
private readonly CommandContext _context;
private readonly DeploymentLocator _deploymentLocator;
private readonly OobeStateService _oobeStateService;
private readonly UpdateEngineService _updateEngine;
private readonly IUpdateEngine _updateEngine;
private readonly StartupAttemptRegistry _startupAttemptRegistry;
private readonly LauncherCoordinatorIpcServer? _coordinatorIpcServer;
private readonly DataLocationResolver _dataLocationResolver;
@@ -24,9 +24,10 @@ internal sealed class LauncherOrchestrator
CommandContext context,
DeploymentLocator deploymentLocator,
OobeStateService oobeStateService,
UpdateEngineService updateEngine,
IUpdateEngine updateEngine,
StartupAttemptRegistry startupAttemptRegistry,
LauncherCoordinatorIpcServer? coordinatorIpcServer = null)
LauncherCoordinatorIpcServer? coordinatorIpcServer = null,
LaunchPipeline? pipeline = null)
{
_context = context;
_deploymentLocator = deploymentLocator;
@@ -40,7 +41,7 @@ internal sealed class LauncherOrchestrator
new WelcomeOobeStep(_oobeStateService, _context),
new DataLocationOobeStep(_dataLocationResolver)
];
_pipeline = new LaunchPipeline(
_pipeline = pipeline ?? new LaunchPipeline(
[
new CleanupDeploymentsPhase(),
new ExistingHostProbePhase(),

View File

@@ -0,0 +1,55 @@
using Microsoft.Extensions.DependencyInjection;
namespace LanMountainDesktop.Launcher.Shell;
internal static class LauncherServiceRegistration
{
private static ServiceProvider? _provider;
public static IServiceProvider Provider =>
_provider ?? throw new InvalidOperationException("Launcher services are not initialized.");
public static void Initialize(CommandContext context)
{
if (_provider is not null)
{
return;
}
var appRoot = Commands.ResolveAppRoot(context);
var services = new ServiceCollection();
services.AddSingleton(context);
services.AddSingleton(new DeploymentLocator(appRoot));
services.AddSingleton(sp => new OobeStateService(appRoot));
services.AddSingleton(sp => new DataLocationResolver(appRoot));
services.AddSingleton<IUpdateEngine>(sp => new UpdateEngineFacade(sp.GetRequiredService<DeploymentLocator>()));
services.AddSingleton<HostLaunchService>();
services.AddSingleton<StartupAttemptRegistry>();
services.AddSingleton<ILaunchPhase, CleanupDeploymentsPhase>();
services.AddSingleton<ILaunchPhase, ExistingHostProbePhase>();
services.AddSingleton<ILaunchPhase, ApplyPendingUpdatePhase>();
services.AddSingleton<ILaunchPhase, OobeGatePhase>();
services.AddSingleton<ILaunchPhase, LaunchHostPhase>();
services.AddSingleton<ILaunchPhase, MonitorStartupPhase>();
services.AddSingleton(sp => new LaunchPipeline(sp.GetServices<ILaunchPhase>()));
_provider = services.BuildServiceProvider();
}
public static LauncherOrchestrator CreateOrchestrator(
CommandContext context,
StartupAttemptRegistry startupAttemptRegistry,
LauncherCoordinatorIpcServer coordinatorServer)
{
Initialize(context);
var services = Provider;
return new LauncherOrchestrator(
context,
services.GetRequiredService<DeploymentLocator>(),
services.GetRequiredService<OobeStateService>(),
services.GetRequiredService<IUpdateEngine>(),
startupAttemptRegistry,
coordinatorServer,
services.GetRequiredService<LaunchPipeline>());
}
}