From 2f4ab60004d40f23d1878b56f7857287342e72c6 Mon Sep 17 00:00:00 2001 From: JusterZhu Date: Wed, 20 May 2026 23:26:04 +0800 Subject: [PATCH] fix: Platform/AppType ComboBox binding - use record types, not int - Changed Config.Platform from int to PlatformItem (with default 'Windows') - Changed Config.AppType from int to AppTypeItem (with default 'ClientApp') - Moved PlatformItem/AppTypeItem records to SimulateConfigModel.cs - Fixed XAML SelectedItem binding (no more InvalidCastException) - Updated SimulationService and ReportGeneratorService to use .Value/.DisplayName - Layout: AppSecret + ProductID on same row, ComboBox defaults via SelectedIndex=0 --- src/Models/SimulateConfigModel.cs | 11 +++++++---- src/Services/ReportGeneratorService.cs | 4 ++-- src/Services/SimulationService.cs | 2 +- src/ViewModels/SimulateViewModel.cs | 3 --- src/Views/SimulateView.axaml | 22 +++++++++++----------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Models/SimulateConfigModel.cs b/src/Models/SimulateConfigModel.cs index 3044d17..beb9539 100644 --- a/src/Models/SimulateConfigModel.cs +++ b/src/Models/SimulateConfigModel.cs @@ -2,6 +2,9 @@ namespace GeneralUpdate.Tools.Models; +public record PlatformItem(int Value, string DisplayName) { public override string ToString() => DisplayName; } +public record AppTypeItem(int Value, string DisplayName) { public override string ToString() => DisplayName; } + /// /// Configuration for the simulate-update module. /// @@ -19,11 +22,11 @@ public partial class SimulateConfigModel : ObservableObject /// The target version the patch upgrades to. [ObservableProperty] private string _targetVersion = "2.0.0.0"; - /// Platform selector (1=Windows, 2=Linux). - [ObservableProperty] private int _platform = 1; + /// Platform selector. + [ObservableProperty] private PlatformItem _platform = new(1, "Windows"); - /// AppType sent to the server (1=ClientApp, 2=UpgradeApp). - [ObservableProperty] private int _appType = 1; + /// AppType selector. + [ObservableProperty] private AppTypeItem _appType = new(1, "ClientApp"); /// Application secret key for the update API. [ObservableProperty] private string _appSecretKey = "dfeb5833-975e-4afb-88f1-6278ee9aeff6"; diff --git a/src/Services/ReportGeneratorService.cs b/src/Services/ReportGeneratorService.cs index 899cb92..45dba05 100644 --- a/src/Services/ReportGeneratorService.cs +++ b/src/Services/ReportGeneratorService.cs @@ -26,8 +26,8 @@ public async Task GenerateAsync( sb.AppendLine("|-------|-------|"); sb.AppendLine($"| Patch | {EscapeMd(config.PatchFilePath)} |"); sb.AppendLine($"| App Directory | {EscapeMd(config.AppDirectory)} |"); - sb.AppendLine($"| Platform | {config.Platform} |"); - sb.AppendLine($"| AppType | {config.AppType} |"); + sb.AppendLine($"| Platform | {config.Platform.DisplayName} |"); + sb.AppendLine($"| AppType | {config.AppType.DisplayName} |"); sb.AppendLine($"| Version | {config.CurrentVersion} → {config.TargetVersion} |"); sb.AppendLine($"| Server Port | {config.ServerPort} |"); sb.AppendLine($"| Simulation Time | {DateTime.Now:yyyy-MM-dd HH:mm:ss} |"); diff --git a/src/Services/SimulationService.cs b/src/Services/SimulationService.cs index 0e828d9..9e7d6c0 100644 --- a/src/Services/SimulationService.cs +++ b/src/Services/SimulationService.cs @@ -50,7 +50,7 @@ public async Task RunAsync( var hash = ComputeQuickHash(patchDest); LocalUpdateServerFiles.Register(patchName, patchDest); - _server.Updates.Add((config.CurrentVersion, config.TargetVersion, hash, patchDest, config.AppType)); + _server.Updates.Add((config.CurrentVersion, config.TargetVersion, hash, patchDest, config.AppType.Value)); await _server.StartAsync(config.ServerPort); Log($" Server running on {_server.BaseUrl}", progress); diff --git a/src/ViewModels/SimulateViewModel.cs b/src/ViewModels/SimulateViewModel.cs index bb2605f..9f1eb3d 100644 --- a/src/ViewModels/SimulateViewModel.cs +++ b/src/ViewModels/SimulateViewModel.cs @@ -107,6 +107,3 @@ async Task StartSimulation() void L(string msg) => Log.Add($"[{DateTime.Now:HH:mm:ss}] {msg}"); } - -public record PlatformItem(int Value, string DisplayName) { public override string ToString() => DisplayName; } -public record AppTypeItem(int Value, string DisplayName) { public override string ToString() => DisplayName; } diff --git a/src/Views/SimulateView.axaml b/src/Views/SimulateView.axaml index aa2dc5d..39064cd 100644 --- a/src/Views/SimulateView.axaml +++ b/src/Views/SimulateView.axaml @@ -13,12 +13,12 @@ - +