v0.21.0 — System health banner with colored indicators + tooltips

New row between top bar and content showing pill-shaped status indicators
for the system dependencies that PROSERVE needs (SteamVR, Vive Business
Streaming process, VR headset reachable on the network, etc.). Each pill
is colored : 🟢 OK, 🟠 limitation détectée (e.g. ping élevé), 🔴 KO,
gris = non configuré. Hover → tooltip with full check kind, target,
last RTT/process count and timestamp.

Architecture
- LocalConfig.HealthChecksConfig : list of HealthCheckEntry (Kind=Ping
  or Process, Target=IP/host or process name, ping thresholds in ms,
  refresh interval in s).
- ISystemHealthService + SystemHealthService : ping via
  System.Net.NetworkInformation.Ping (no admin required), process
  lookup via System.Diagnostics.Process.GetProcessesByName. Returns
  HealthResult { Severity, Detail }.
- HealthIndicatorViewModel : observable wrapper per entry with
  Severity-driven Brushes (background pill, border, icon colour) and
  composed Tooltip text.
- MainViewModel.InitHealthIndicators + StartHealthLoop : populates
  ObservableCollection<HealthIndicatorViewModel> from config and runs
  parallel checks every RefreshIntervalSeconds (default 10s).
- MainWindow.xaml : new Row 1 (between top bar and body) hosting an
  ItemsControl bound to HealthIndicators. Row collapses cleanly if the
  list is empty (HasHealthIndicators=false).

Defaults shipped (all editable in %LocalAppData%\PSLauncher\config.json)
- 🎮 SteamVR (Process : vrserver)
- 📡 Vive Business Streaming (Process : HtcConnectionUtility)
- 🥽 Casque VR (Ping : empty, user fills in the headset IP)

The Settings UI editor for managing the list is intentionally deferred
to a future iteration — config.json edit is enough to start using it.

Versions bumped to 0.21.0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-03 18:44:15 +02:00
parent 30eceaea2c
commit 60358a6cf5
10 changed files with 450 additions and 26 deletions

View File

@@ -0,0 +1,92 @@
using System.Windows.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using PSLauncher.Core.Health;
using PSLauncher.Models;
namespace PSLauncher.App.ViewModels;
/// <summary>
/// Représente un indicateur visuel (pill colorée) dans le bandeau de santé
/// système. Mis à jour périodiquement par <see cref="MainViewModel"/> à
/// partir du résultat de <see cref="ISystemHealthService.RunCheckAsync"/>.
/// </summary>
public sealed partial class HealthIndicatorViewModel : ObservableObject
{
public HealthCheckEntry Entry { get; }
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(StatusBrush))]
[NotifyPropertyChangedFor(nameof(BorderBrush))]
[NotifyPropertyChangedFor(nameof(IconForeground))]
[NotifyPropertyChangedFor(nameof(Tooltip))]
private HealthSeverity _severity = HealthSeverity.Unknown;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(Tooltip))]
private string _detail = "Pas encore vérifié";
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(Tooltip))]
private DateTime _lastCheckedUtc = DateTime.MinValue;
public string Name => Entry.Name;
public string Icon => Entry.Icon;
public Brush StatusBrush => Severity switch
{
// Pill background : un peu transparent pour que le bandeau reste discret
HealthSeverity.Ok => new SolidColorBrush(Color.FromArgb(0x40, 0x16, 0xA3, 0x4A)), // vert
HealthSeverity.Warning => new SolidColorBrush(Color.FromArgb(0x50, 0xF5, 0x9E, 0x0B)), // orange
HealthSeverity.Error => new SolidColorBrush(Color.FromArgb(0x50, 0xEF, 0x44, 0x44)), // rouge
_ => new SolidColorBrush(Color.FromArgb(0x30, 0x80, 0x80, 0x90)), // gris
};
public Brush BorderBrush => Severity switch
{
HealthSeverity.Ok => new SolidColorBrush(Color.FromRgb(0x16, 0xA3, 0x4A)),
HealthSeverity.Warning => new SolidColorBrush(Color.FromRgb(0xF5, 0x9E, 0x0B)),
HealthSeverity.Error => new SolidColorBrush(Color.FromRgb(0xEF, 0x44, 0x44)),
_ => new SolidColorBrush(Color.FromRgb(0x60, 0x60, 0x70)),
};
public Brush IconForeground => Severity switch
{
HealthSeverity.Ok => new SolidColorBrush(Color.FromRgb(0x4A, 0xDE, 0x80)),
HealthSeverity.Warning => new SolidColorBrush(Color.FromRgb(0xFB, 0xBF, 0x24)),
HealthSeverity.Error => new SolidColorBrush(Color.FromRgb(0xF8, 0x71, 0x71)),
_ => new SolidColorBrush(Color.FromRgb(0xA0, 0xA0, 0xA8)),
};
public string Tooltip
{
get
{
var status = Severity switch
{
HealthSeverity.Ok => "✓ OK",
HealthSeverity.Warning => "⚠ Limitation détectée",
HealthSeverity.Error => "⛔ Problème",
_ => "❓ Non vérifié",
};
var ts = LastCheckedUtc == DateTime.MinValue
? ""
: $"\n\nDernière vérif : {LastCheckedUtc.ToLocalTime():HH:mm:ss}";
var kindLabel = Entry.Kind?.Equals("ping", StringComparison.OrdinalIgnoreCase) == true
? $"Ping {Entry.Target}"
: $"Processus {Entry.Target}";
return $"{Entry.Icon} {Entry.Name} — {status}\n{kindLabel}\n\n{Detail}{ts}";
}
}
public HealthIndicatorViewModel(HealthCheckEntry entry)
{
Entry = entry;
}
public void Apply(HealthResult result)
{
Severity = result.Severity;
Detail = result.Detail;
LastCheckedUtc = DateTime.UtcNow;
}
}

View File

@@ -15,6 +15,7 @@ using PSLauncher.Core.Licensing;
using PSLauncher.Core.Localization;
using PSLauncher.Core.Manifests;
using PSLauncher.Core.DocTool;
using PSLauncher.Core.Health;
using PSLauncher.Core.Migrations;
using PSLauncher.Core.Process;
using PSLauncher.Core.ReportTool;
@@ -45,6 +46,7 @@ public sealed partial class MainViewModel : ObservableObject
private readonly IDatabaseMigrationService _migrationService;
private readonly IReportToolDeployer _reportDeployer;
private readonly IDocToolDeployer _docDeployer;
private readonly ISystemHealthService _healthService;
private readonly IServiceProvider _serviceProvider;
private readonly ILogger<MainViewModel> _logger;
@@ -63,6 +65,15 @@ public sealed partial class MainViewModel : ObservableObject
public ObservableCollection<VersionRowViewModel> OtherVersions { get; } = new();
/// <summary>
/// Indicateurs affichés dans le bandeau de santé sous la top bar : pings,
/// processus requis (SteamVR, Vive Streaming, etc.). Liste construite depuis
/// <see cref="HealthChecksConfig.Checks"/> au démarrage. Refresh périodique
/// piloté par <see cref="StartHealthLoop"/>.
/// </summary>
public ObservableCollection<HealthIndicatorViewModel> HealthIndicators { get; } = new();
public bool HasHealthIndicators => HealthIndicators.Count > 0;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(HasFeaturedVersion))]
[NotifyPropertyChangedFor(nameof(HasOtherVersions))]
@@ -236,6 +247,7 @@ public sealed partial class MainViewModel : ObservableObject
IDatabaseMigrationService migrationService,
IReportToolDeployer reportDeployer,
IDocToolDeployer docDeployer,
ISystemHealthService healthService,
IServiceProvider serviceProvider,
ILogger<MainViewModel> logger)
{
@@ -253,6 +265,7 @@ public sealed partial class MainViewModel : ObservableObject
_migrationService = migrationService;
_reportDeployer = reportDeployer;
_docDeployer = docDeployer;
_healthService = healthService;
_serviceProvider = serviceProvider;
_logger = logger;
@@ -261,6 +274,7 @@ public sealed partial class MainViewModel : ObservableObject
_license = _licenseService.GetCached();
RebuildList();
InitHealthIndicators();
// Vérification automatique des MAJ au démarrage (silencieuse et non bloquante)
_ = Task.Run(async () =>
@@ -275,6 +289,62 @@ public sealed partial class MainViewModel : ObservableObject
}
catch (Exception ex) { _logger.LogWarning(ex, "Auto check at startup failed"); }
});
// Boucle périodique des health checks. Ne tourne que si la config en
// contient au moins un. Premier passage immédiat puis re-check tous les
// RefreshIntervalSeconds.
StartHealthLoop();
}
/// <summary>
/// Construit la collection observable des indicateurs depuis la config et
/// notifie HasHealthIndicators pour que la UI cache le bandeau si la liste
/// est vide. Idempotent — appelée au startup uniquement, pas à chaque refresh.
/// </summary>
private void InitHealthIndicators()
{
HealthIndicators.Clear();
foreach (var entry in _config.HealthChecks.Checks)
HealthIndicators.Add(new HealthIndicatorViewModel(entry));
OnPropertyChanged(nameof(HasHealthIndicators));
}
/// <summary>
/// Lance une tâche en arrière-plan qui exécute tous les checks en parallèle,
/// applique les résultats sur les VM via le dispatcher UI, puis attend
/// RefreshIntervalSeconds avant de recommencer. La tâche tourne tant que
/// l'app vit ; pas de cancel explicite (l'arrêt suit la fermeture du process).
/// </summary>
private void StartHealthLoop()
{
if (HealthIndicators.Count == 0) return;
var interval = TimeSpan.FromSeconds(Math.Max(2, _config.HealthChecks.RefreshIntervalSeconds));
_ = Task.Run(async () =>
{
while (true)
{
try
{
var snapshot = HealthIndicators.ToList();
var tasks = snapshot.Select(async vm =>
{
try
{
var result = await _healthService.RunCheckAsync(vm.Entry, CancellationToken.None);
await Application.Current.Dispatcher.InvokeAsync(() => vm.Apply(result));
}
catch (Exception ex)
{
_logger.LogDebug(ex, "Health check {Name} threw", vm.Entry.Name);
}
});
await Task.WhenAll(tasks).ConfigureAwait(false);
}
catch (Exception ex) { _logger.LogDebug(ex, "Health loop tick"); }
try { await Task.Delay(interval).ConfigureAwait(false); }
catch { break; }
}
});
}
/// <summary>