feat(installer): add Diagnose section to SettingsWindow

Re-runs the environment checks against the installed configuration
(worker.config.json + detected install dir) without blocking navigation
and without auto-running on window open, only on a "Recheck" click.

Extracted the check-row rendering and check-run logic (busy state,
summary, Recheck command) out of SystemCheckPage into a shared
Checks/CheckListViewModel + Checks/CheckListView, composed by both
SystemCheckPage (wizard) and the new DiagnosePage (settings) instead
of duplicating it.
This commit is contained in:
mika kuns
2026-08-06 08:22:45 +02:00
parent b3a8373c70
commit 7e1b1177de
15 changed files with 529 additions and 205 deletions
@@ -1,8 +1,5 @@
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using ClaudeDo.Installer.Checks;
using ClaudeDo.Installer.Core;
using ClaudeDo.Installer.Localization;
@@ -11,85 +8,45 @@ using CommunityToolkit.Mvvm.Input;
namespace ClaudeDo.Installer.Pages.SystemCheckPage;
public sealed class CheckRowViewModel
{
public CheckRowViewModel(CheckResult result)
{
var loc = TrExtension.Localizer;
Status = result.Status;
Severity = result.Severity;
Title = loc?[result.TitleKey] ?? result.TitleKey;
Message = result.Message;
Hint = result.HintKey is not null ? loc?[result.HintKey] ?? result.HintKey : null;
HelpUrl = result.HelpUrl;
StatusBrush = ResolveBrush(Status, Severity);
}
public CheckStatus Status { get; }
public CheckSeverity Severity { get; }
public string Title { get; }
public string Message { get; }
public string? Hint { get; }
public string? HelpUrl { get; }
public Brush StatusBrush { get; }
private static Brush ResolveBrush(CheckStatus status, CheckSeverity severity)
{
var key = status switch
{
CheckStatus.Ok => "StatusGreenBrush",
CheckStatus.Unknown => "StatusGrayBrush",
CheckStatus.Failed when severity == CheckSeverity.Error => "StatusRedBrush",
CheckStatus.Failed => "StatusOrangeBrush",
_ => "StatusGrayBrush",
};
return Application.Current?.Resources[key] as Brush ?? Brushes.Gray;
}
}
public partial class SystemCheckPageViewModel : ObservableObject, IInstallerPage
{
private readonly InstallContext _context;
private readonly Func<EnvironmentCheckService> _checkServiceFactory;
private SystemCheckPageView? _view;
private bool _hasStarted;
public string Title => TrExtension.Localizer?["installer.systemCheck.title"] ?? "System Check";
public string Icon => "";
public string Icon => "";
public int Order => 1;
public bool ShowInWizard => true;
public bool ShowInSettings => false;
public UserControl View => _view ??= new SystemCheckPageView { DataContext = this };
public ObservableCollection<CheckRowViewModel> Rows { get; } = [];
public CheckListViewModel Checks { get; }
[ObservableProperty] private bool _isRunning;
[ObservableProperty] private bool _hasRun;
[ObservableProperty] private bool _hasBlockingError;
[ObservableProperty] private string _summary = string.Empty;
// Pass-through to the shared check-run logic — kept so this page's UI/tests can bind
// directly on it, matching the pre-extraction API.
public ObservableCollection<CheckRowViewModel> Rows => Checks.Rows;
public bool IsRunning => Checks.IsRunning;
public bool HasRun => Checks.HasRun;
public bool HasBlockingError => Checks.HasBlockingError;
public string Summary => Checks.Summary;
public IAsyncRelayCommand RunChecksCommand => Checks.RunChecksCommand;
public bool BlocksNavigation => IsRunning || HasBlockingError;
public bool BlocksNavigation => Checks.IsRunning || Checks.HasBlockingError;
public SystemCheckPageViewModel(InstallContext context, Func<EnvironmentCheckService> checkServiceFactory)
{
_context = context;
_checkServiceFactory = checkServiceFactory;
Checks = new CheckListViewModel(context, checkServiceFactory);
// The wizard listens for PropertyChanged on this page to re-evaluate "Next" — bubble
// any change from the composed check list up so a live recheck can flip it back.
Checks.PropertyChanged += (_, _) => OnPropertyChanged(nameof(BlocksNavigation));
}
partial void OnIsRunningChanged(bool value)
{
OnPropertyChanged(nameof(BlocksNavigation));
RunChecksCommand.NotifyCanExecuteChanged();
}
partial void OnHasBlockingErrorChanged(bool value) => OnPropertyChanged(nameof(BlocksNavigation));
public Task LoadAsync()
{
if (!_hasStarted)
{
_hasStarted = true;
_ = RunChecksAsync();
_ = Checks.RunChecksCommand.ExecuteAsync(null);
}
return Task.CompletedTask;
}
@@ -97,64 +54,4 @@ public partial class SystemCheckPageViewModel : ObservableObject, IInstallerPage
public Task ApplyAsync() => Task.CompletedTask;
public bool Validate() => !HasBlockingError;
[RelayCommand(CanExecute = nameof(CanRunChecks))]
private async Task RunChecksAsync()
{
if (IsRunning) return;
IsRunning = true;
Summary = TrExtension.Localizer?["installer.systemCheck.summary.running"] ?? "Checking your system…";
try
{
var service = _checkServiceFactory();
var report = await service.RunAllAsync(_context, CancellationToken.None);
Rows.Clear();
foreach (var result in report.Results)
Rows.Add(new CheckRowViewModel(result));
HasBlockingError = report.HasBlockingError;
Summary = BuildSummary(report);
HasRun = true;
}
finally
{
IsRunning = false;
}
}
private bool CanRunChecks() => !IsRunning;
private static string BuildSummary(EnvironmentCheckReport report)
{
var loc = TrExtension.Localizer;
var blocking = report.Results
.Where(r => r.Severity == CheckSeverity.Error && r.Status == CheckStatus.Failed)
.ToList();
if (blocking.Count > 0)
{
var names = string.Join(", ", blocking.Select(r => loc?[r.TitleKey] ?? r.TitleKey));
return loc?.Get("installer.systemCheck.summary.blocking", blocking.Count, names)
?? $"{blocking.Count} problem(s) must be fixed: {names}";
}
var warnings = report.Results.Count(r => r.Severity == CheckSeverity.Warning && r.Status == CheckStatus.Failed);
if (warnings > 0)
{
return loc?.Get("installer.systemCheck.summary.warnings", warnings)
?? $"{warnings} warning(s) found.";
}
return loc?["installer.systemCheck.summary.ok"] ?? "Everything looks good.";
}
[RelayCommand]
private static void OpenHelpUrl(string? url)
{
if (string.IsNullOrEmpty(url)) return;
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}
}