feat(installer): add WPF installer/configurator project

Standalone WPF app (ClaudeDo.Installer) that handles full installation
and ongoing configuration of ClaudeDo. Two modes: wizard for first run,
tabbed settings panel for subsequent launches. Page-based extensibility
via IInstallerPage interface — adding new config sections requires only
one new class.

Install pipeline: dotnet publish, deploy binaries, write configs, init
DB (via SchemaInitializer from ClaudeDo.Data), register Windows Service,
create shortcuts. Dark theme matching the Avalonia app (forest teal accent).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
CubeGameLP
2026-04-14 21:01:03 +02:00
parent 2479bb6ea1
commit 78831b2263
47 changed files with 2351 additions and 0 deletions

View File

@@ -0,0 +1,109 @@
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using ClaudeDo.Data;
namespace ClaudeDo.Installer.Core;
/// <summary>
/// Mirrors ClaudeDo.Worker.Config.WorkerConfig JSON shape.
/// Keep in sync with src/ClaudeDo.Worker/Config/WorkerConfig.cs.
/// </summary>
public sealed class InstallerWorkerConfig
{
[JsonPropertyName("db_path")]
public string DbPath { get; set; } = "~/.todo-app/todo.db";
[JsonPropertyName("sandbox_root")]
public string SandboxRoot { get; set; } = "~/.todo-app/sandbox";
[JsonPropertyName("log_root")]
public string LogRoot { get; set; } = "~/.todo-app/logs";
[JsonPropertyName("worktree_root_strategy")]
public string WorktreeRootStrategy { get; set; } = "sibling";
[JsonPropertyName("central_worktree_root")]
public string CentralWorktreeRoot { get; set; } = "~/.todo-app/worktrees";
[JsonPropertyName("queue_backstop_interval_ms")]
public int QueueBackstopIntervalMs { get; set; } = 30_000;
[JsonPropertyName("signalr_port")]
public int SignalRPort { get; set; } = 47_821;
[JsonPropertyName("claude_bin")]
public string ClaudeBin { get; set; } = "claude";
private static readonly JsonSerializerOptions ReadOpts = new()
{
ReadCommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true,
};
private static readonly JsonSerializerOptions WriteOpts = new()
{
WriteIndented = true,
};
public static InstallerWorkerConfig Load()
{
var path = Path.Combine(Paths.AppDataRoot(), "worker.config.json");
if (!File.Exists(path)) return new();
var json = File.ReadAllText(path);
return JsonSerializer.Deserialize<InstallerWorkerConfig>(json, ReadOpts) ?? new();
}
public void Save()
{
var dir = Paths.AppDataRoot();
Directory.CreateDirectory(dir);
var path = Path.Combine(dir, "worker.config.json");
var json = JsonSerializer.Serialize(this, WriteOpts);
File.WriteAllText(path, json);
}
}
/// <summary>
/// Mirrors ClaudeDo.Ui.AppSettings JSON shape.
/// Keep in sync with src/ClaudeDo.Ui/AppSettings.cs.
/// </summary>
public sealed class InstallerAppSettings
{
public string DbPath { get; set; } = "~/.todo-app/todo.db";
public string SignalRUrl { get; set; } = "http://127.0.0.1:47821/hub";
private static readonly JsonSerializerOptions ReadOpts = new()
{
PropertyNameCaseInsensitive = true,
};
private static readonly JsonSerializerOptions WriteOpts = new()
{
WriteIndented = true,
};
public static InstallerAppSettings Load()
{
var path = Path.Combine(Paths.AppDataRoot(), "ui.config.json");
if (!File.Exists(path)) return new();
try
{
var json = File.ReadAllText(path);
return JsonSerializer.Deserialize<InstallerAppSettings>(json, ReadOpts) ?? new();
}
catch
{
return new();
}
}
public void Save()
{
var dir = Paths.AppDataRoot();
Directory.CreateDirectory(dir);
var path = Path.Combine(dir, "ui.config.json");
var json = JsonSerializer.Serialize(this, WriteOpts);
File.WriteAllText(path, json);
}
}

View File

@@ -0,0 +1,29 @@
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
namespace ClaudeDo.Installer.Core;
public static class DarkTitleBar
{
[DllImport("dwmapi.dll", PreserveSig = true)]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
public static void Apply(Window window)
{
if (window.IsLoaded)
SetDarkMode(window);
else
window.SourceInitialized += (_, _) => SetDarkMode(window);
}
private static void SetDarkMode(Window window)
{
var hwnd = new WindowInteropHelper(window).Handle;
if (hwnd == IntPtr.Zero) return;
int value = 1;
DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE, ref value, sizeof(int));
}
}

View File

@@ -0,0 +1,20 @@
namespace ClaudeDo.Installer.Core;
public interface IInstallStep
{
string Name { get; }
Task<StepResult> ExecuteAsync(InstallContext ctx, IProgress<string> progress, CancellationToken ct);
}
public sealed class StepResult
{
public bool Success { get; init; }
public string? ErrorMessage { get; init; }
public static StepResult Ok() => new() { Success = true };
public static StepResult Fail(string error) => new() { Success = false, ErrorMessage = error };
}
public enum StepStatus { Pending, Running, Done, Failed, Skipped }
public sealed record StepProgress(string StepName, StepStatus Status, string? Message = null);

View File

@@ -0,0 +1,16 @@
using System.Windows.Controls;
namespace ClaudeDo.Installer.Core;
public interface IInstallerPage
{
string Title { get; }
string Icon { get; }
int Order { get; }
bool ShowInWizard { get; }
bool ShowInSettings { get; }
UserControl View { get; }
Task LoadAsync();
Task ApplyAsync();
bool Validate();
}

View File

@@ -0,0 +1,30 @@
namespace ClaudeDo.Installer.Core;
public sealed class InstallContext
{
// WelcomePage
public string SourceDirectory { get; set; } = "";
public string InstallDirectory { get; set; } = @"C:\Program Files\ClaudeDo";
// PathsPage
public string DbPath { get; set; } = "~/.todo-app/todo.db";
public string LogRoot { get; set; } = "~/.todo-app/logs";
public string SandboxRoot { get; set; } = "~/.todo-app/sandbox";
public string WorktreeRootStrategy { get; set; } = "sibling";
public string CentralWorktreeRoot { get; set; } = "~/.todo-app/worktrees";
// ServicePage
public int SignalRPort { get; set; } = 47_821;
public int QueueBackstopIntervalMs { get; set; } = 30_000;
public string ClaudeBin { get; set; } = "claude";
public string ServiceAccount { get; set; } = "LocalSystem";
public bool AutoStart { get; set; } = true;
public int RestartDelayMs { get; set; } = 5000;
// UiSettingsPage
public string SignalRUrl { get; set; } = "http://127.0.0.1:47821/hub";
public string UiDbPath { get; set; } = "~/.todo-app/todo.db";
// InstallPage
public bool CreateDesktopShortcut { get; set; } = true;
}

View File

@@ -0,0 +1,19 @@
using System.IO;
using ClaudeDo.Data;
namespace ClaudeDo.Installer.Core;
public enum InstallerMode { Wizard, Settings }
public static class ModeDetector
{
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;
}
}

View File

@@ -0,0 +1,49 @@
namespace ClaudeDo.Installer.Core;
public sealed class InstallerService
{
private readonly IEnumerable<IInstallStep> _steps;
public InstallerService(IEnumerable<IInstallStep> steps) => _steps = steps;
public async Task<IReadOnlyList<(IInstallStep Step, StepResult Result)>> ExecuteAsync(
InstallContext ctx,
IProgress<StepProgress> progress,
CancellationToken ct)
{
var results = new List<(IInstallStep, StepResult)>();
foreach (var step in _steps)
{
ct.ThrowIfCancellationRequested();
progress.Report(new StepProgress(step.Name, StepStatus.Running));
var lineProgress = new Progress<string>(msg =>
progress.Report(new StepProgress(step.Name, StepStatus.Running, msg)));
try
{
var result = await step.ExecuteAsync(ctx, lineProgress, ct);
var status = result.Success ? StepStatus.Done : StepStatus.Failed;
progress.Report(new StepProgress(step.Name, status, result.ErrorMessage));
results.Add((step, result));
if (!result.Success) break;
}
catch (OperationCanceledException)
{
progress.Report(new StepProgress(step.Name, StepStatus.Failed, "Cancelled"));
results.Add((step, StepResult.Fail("Cancelled")));
break;
}
catch (Exception ex)
{
progress.Report(new StepProgress(step.Name, StepStatus.Failed, ex.Message));
results.Add((step, StepResult.Fail(ex.Message)));
break;
}
}
return results;
}
}

View File

@@ -0,0 +1,14 @@
using System.Globalization;
using System.Windows;
using System.Windows.Data;
namespace ClaudeDo.Installer.Core;
public sealed class NullToCollapsedConverter : IValueConverter
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
=> value is null or "" ? Visibility.Collapsed : Visibility.Visible;
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotSupportedException();
}

View File

@@ -0,0 +1,17 @@
namespace ClaudeDo.Installer.Core;
public sealed class PageResolver
{
private readonly IReadOnlyList<IInstallerPage> _allPages;
public PageResolver(IEnumerable<IInstallerPage> pages)
{
_allPages = pages.OrderBy(p => p.Order).ToList();
}
public IReadOnlyList<IInstallerPage> WizardPages =>
_allPages.Where(p => p.ShowInWizard).ToList();
public IReadOnlyList<IInstallerPage> SettingsPages =>
_allPages.Where(p => p.ShowInSettings).ToList();
}

View File

@@ -0,0 +1,60 @@
using System.Diagnostics;
using System.IO;
using System.Text;
namespace ClaudeDo.Installer.Core;
public static class ProcessRunner
{
public static async Task<(int ExitCode, string Output)> RunAsync(
string fileName,
string arguments,
string? workingDirectory,
IProgress<string>? progress,
CancellationToken ct)
{
var output = new StringBuilder();
var outputLock = new object();
using var process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = fileName,
Arguments = arguments,
WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
};
if (!process.Start())
return (-1, "Failed to start process");
var stdoutTask = ReadStreamAsync(process.StandardOutput, output, outputLock, progress);
var stderrTask = ReadStreamAsync(process.StandardError, output, outputLock, progress);
using var reg = ct.Register(() =>
{
try { process.Kill(entireProcessTree: true); } catch { }
});
await Task.WhenAll(stdoutTask, stderrTask);
await process.WaitForExitAsync(ct);
return (process.ExitCode, output.ToString());
}
private static async Task ReadStreamAsync(
StreamReader reader,
StringBuilder output,
object outputLock,
IProgress<string>? progress)
{
while (await reader.ReadLineAsync() is { } line)
{
lock (outputLock) { output.AppendLine(line); }
progress?.Report(line);
}
}
}

View File

@@ -0,0 +1,37 @@
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media;
namespace ClaudeDo.Installer.Core;
/// <summary>
/// Multi-value converter: compares the page's index with the current page index
/// to determine step indicator styling.
/// </summary>
public sealed class StepActiveConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values.Length < 2 ||
values[0] is not IInstallerPage page ||
values[1] is not IInstallerPage currentPage)
return DependencyProperty.UnsetValue;
var isActive = ReferenceEquals(page, currentPage);
var key = parameter?.ToString() switch
{
"Background" => isActive ? "AccentBrush" : "WindowBgBrush",
"Foreground" => isActive ? "TextPrimaryBrush" : "TextMutedBrush",
"BorderBrush" => isActive ? "AccentBrush" : "BorderSubtleBrush",
_ => null
};
if (key is null) return DependencyProperty.UnsetValue;
return Application.Current.Resources[key] as SolidColorBrush ?? DependencyProperty.UnsetValue;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
=> throw new NotSupportedException();
}