feat(installer): replace sync ModeDetector with async InstallModeDetector

Placeholder edit to App.xaml.cs to keep the project building until Task 11
wires the new async detector.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Mika Kuns
2026-04-15 09:19:16 +02:00
parent 83d7058b32
commit 97fb215ce6
4 changed files with 153 additions and 26 deletions

View File

@@ -0,0 +1,41 @@
namespace ClaudeDo.Installer.Core;
public sealed record DetectedState(
InstallerMode Mode,
InstallManifest? Existing,
GiteaRelease? LatestRelease,
string? LatestVersion);
public sealed class InstallModeDetector
{
private readonly IReleaseClient _releases;
public InstallModeDetector(IReleaseClient releases)
{
_releases = releases;
}
public async Task<DetectedState> DetectAsync(string installDir, CancellationToken ct)
{
var manifest = InstallManifestStore.TryRead(installDir);
if (manifest is null)
return new DetectedState(InstallerMode.FreshInstall, null, null, null);
var release = await _releases.GetLatestReleaseAsync(ct);
if (release is null)
return new DetectedState(InstallerMode.Config, manifest, null, null);
var latestVersion = release.TagName.TrimStart('v', 'V');
if (IsNewer(latestVersion, manifest.Version))
return new DetectedState(InstallerMode.Update, manifest, release, latestVersion);
return new DetectedState(InstallerMode.Config, manifest, release, latestVersion);
}
private static bool IsNewer(string latest, string current)
{
if (!Version.TryParse(latest, out var lv)) return false;
if (!Version.TryParse(current, out var cv)) return false;
return lv > cv;
}
}

View File

@@ -1,19 +1,8 @@
using System.IO;
using ClaudeDo.Data;
namespace ClaudeDo.Installer.Core;
public enum InstallerMode { Wizard, Settings }
public static class ModeDetector
public enum InstallerMode
{
public static InstallerMode Detect()
{
var root = Paths.AppDataRoot();
var workerConfig = Path.Combine(root, "worker.config.json");
var uiConfig = Path.Combine(root, "ui.config.json");
return File.Exists(workerConfig) && File.Exists(uiConfig)
? InstallerMode.Settings
: InstallerMode.Wizard;
}
FreshInstall, // No install.json present -> run full wizard
Update, // install.json present, newer release available
Config, // install.json present, no update (or API unreachable)
}