Adds a new wizard page (positioned right after Welcome, FreshInstall only) that auto-runs EnvironmentCheckService on entry and shows one row per check with status icon, localized title/message, and hint+help-link on failure/unknown. A "Recheck" button re-runs it, guarded against re-entrancy. IInstallerPage gets a BlocksNavigation default member; WizardViewModel's Next button now binds to CanGoNext, which the current page can veto (used here while a check run is in flight or a blocking Error+Failed result is present — Warnings and Unknown results never block). The summary line names the blocking checks so a disabled Next is self-explanatory. Wires up DI for the check pipeline (IProcessRunner, IPortOwnerResolver, per-run ClaudeCliLookup) and adds the checks.* / installer.systemCheck.* locale keys in en.json + de.json. Visual appearance is NOT verified — needs a manual pass in the running installer.
161 lines
5.3 KiB
C#
161 lines
5.3 KiB
C#
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;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
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 int Order => 1;
|
|
public bool ShowInWizard => true;
|
|
public bool ShowInSettings => false;
|
|
public UserControl View => _view ??= new SystemCheckPageView { DataContext = this };
|
|
|
|
public ObservableCollection<CheckRowViewModel> Rows { get; } = [];
|
|
|
|
[ObservableProperty] private bool _isRunning;
|
|
[ObservableProperty] private bool _hasRun;
|
|
[ObservableProperty] private bool _hasBlockingError;
|
|
[ObservableProperty] private string _summary = string.Empty;
|
|
|
|
public bool BlocksNavigation => IsRunning || HasBlockingError;
|
|
|
|
public SystemCheckPageViewModel(InstallContext context, Func<EnvironmentCheckService> checkServiceFactory)
|
|
{
|
|
_context = context;
|
|
_checkServiceFactory = checkServiceFactory;
|
|
}
|
|
|
|
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();
|
|
}
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
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 });
|
|
}
|
|
}
|