Files
HC_APTBS/App.xaml.cs
LucianoDev 197e9d1775 feat: redesign dashboard with Fluent KPI tiles, connection strip, and devices column
- Replace LCD-style readings with a 3×2 KPI tile grid (Fluent card surfaces, 52pt values)
- Add persistent top connection strip with horizontal chips + pump name badge
- Add elapsed test timer (DispatcherTimer, mm:ss) to Test Summary card
- Restyle Test Summary and Active Alarms with Fluent brushes/iconography
- Add Devices column (CAN / K-Line / Bench tiles) between KPI grid and test/alarms
  - Enumerates attached PCAN USB channels via PCAN_ATTACHED_CHANNELS API
  - Enumerates FTDI K-Line adapters via existing FtdiInterface helpers
  - Click to connect/disconnect; confirmation dialog when session active or test running
  - Hover tint: blue = will connect, red = will disconnect; Bench row is read-only stub
- Extend ICanService with SelectedChannel + EnumerateAttachedChannels()
- Expose IKwpService.ConnectedPort for active session device tracking
- Add DeviceRow button style with MultiDataTrigger hover colour logic
- Add 30+ new localization keys (ES + EN) for KPI labels, devices, confirmations

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-19 22:25:00 +02:00

94 lines
4.1 KiB
C#

using System.Windows;
using System.Windows.Media;
using HC_APTBS.Infrastructure.Logging;
using Wpf.Ui.Appearance;
using HC_APTBS.Infrastructure.Pcan;
using HC_APTBS.Models;
using HC_APTBS.Services;
using HC_APTBS.Services.Impl;
using HC_APTBS.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using Peak.Can.Basic;
namespace HC_APTBS;
/// <summary>
/// Application entry-point and DI container host.
///
/// <para>
/// Registers all services, ViewModels, and the main window with
/// <see cref="ServiceCollection"/>, then resolves and shows <see cref="MainWindow"/>
/// on startup. The container is disposed when the application exits.
/// </para>
/// </summary>
public partial class App : Application
{
private ServiceProvider? _serviceProvider;
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
// Apply WPF-UI theme and accent colour before any UI is constructed.
ApplicationThemeManager.Apply(ApplicationTheme.Light);
ApplicationAccentColorManager.Apply(Color.FromRgb(0x21, 0x96, 0xF3));
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
// Wire runtime-warning hooks on pure Model classes before any config is loaded.
// Keeps the Models layer DI-free while still routing warnings through IAppLogger.
var logger = _serviceProvider.GetRequiredService<IAppLogger>();
CanBusParameter.WarningLogger = logger.Warning;
SensorConfiguration.WarningLogger = logger.Warning;
// Initialise the ViewModel (loads pump IDs, starts refresh timer, connects CAN).
var mainVm = _serviceProvider.GetRequiredService<MainViewModel>();
await mainVm.InitialiseAsync();
var window = _serviceProvider.GetRequiredService<MainWindow>();
window.Show();
}
protected override void OnExit(ExitEventArgs e)
{
_serviceProvider?.Dispose();
base.OnExit(e);
}
// ── Service registration ──────────────────────────────────────────────────
private static void ConfigureServices(IServiceCollection services)
{
// ── Infrastructure ────────────────────────────────────────────────────
services.AddSingleton<IAppLogger, AppLogger>();
// PcanAdapter requires a channel handle and baudrate read from configuration.
services.AddSingleton<ICanService>(sp =>
{
var cfg = sp.GetRequiredService<IConfigurationService>();
var logger = sp.GetRequiredService<IAppLogger>();
var channel = cfg.Bench.Channel;
// Default to 500 kbps; the channel can switch at runtime via ICanService.SwitchBaudrate.
return new PcanAdapter(channel, TPCANBaudrate.PCAN_BAUD_500K, logger);
});
services.AddSingleton<IKwpService, KwpService>();
// ── Application services ──────────────────────────────────────────────
services.AddSingleton<IConfigurationService, ConfigurationService>();
services.AddSingleton<IBenchService, BenchService>();
services.AddSingleton<IUnlockService, UnlockService>();
services.AddSingleton<ICalibrationService, CalibrationService>();
services.AddSingleton<IPdfService, PdfService>();
services.AddSingleton<ILocalizationService, LocalizationService>();
// ── ViewModels ────────────────────────────────────────────────────────
services.AddSingleton<MainViewModel>();
// ── Views ─────────────────────────────────────────────────────────────
services.AddSingleton<MainWindow>();
}
}