From 0e0ce0c9f3a5403014b6459290b0994099404275 Mon Sep 17 00:00:00 2001 From: Owen McGirr Date: Tue, 21 Jul 2026 11:18:25 +0100 Subject: [PATCH] Add one-click update installation --- src/SwitchifyPc.App/App.xaml.cs | 14 +- src/SwitchifyPc.App/MainWindow.xaml | 3 +- src/SwitchifyPc.App/MainWindow.xaml.cs | 42 ++- src/SwitchifyPc.App/SettingsWindow.xaml | 19 +- src/SwitchifyPc.App/SettingsWindow.xaml.cs | 50 ++-- src/SwitchifyPc.Core/Ui/MainWindowCopy.cs | 50 +++- .../Ui/MainWindowViewModel.cs | 5 +- src/SwitchifyPc.Core/Ui/SettingsController.cs | 7 + src/SwitchifyPc.Core/Ui/SettingsViewModel.cs | 64 ++++- src/SwitchifyPc.Core/Ui/UpdateUiCopy.cs | 37 +++ src/SwitchifyPc.Core/Updates/UpdateModels.cs | 43 ++- src/SwitchifyPc.Core/Updates/UpdateService.cs | 132 ++++++++- src/SwitchifyPc.Tests/MainWindowCopyTests.cs | 50 +++- src/SwitchifyPc.Tests/MainWindowTests.cs | 51 ++++ .../MainWindowViewModelTests.cs | 3 +- .../SettingsControllerTests.cs | 43 +++ .../SettingsViewModelTests.cs | 65 ++++- src/SwitchifyPc.Tests/SettingsWindowTests.cs | 33 +++ src/SwitchifyPc.Tests/UpdateServiceTests.cs | 271 +++++++++++++++++- 19 files changed, 914 insertions(+), 68 deletions(-) create mode 100644 src/SwitchifyPc.Core/Ui/UpdateUiCopy.cs diff --git a/src/SwitchifyPc.App/App.xaml.cs b/src/SwitchifyPc.App/App.xaml.cs index e1ca353..17a2796 100644 --- a/src/SwitchifyPc.App/App.xaml.cs +++ b/src/SwitchifyPc.App/App.xaml.cs @@ -182,7 +182,7 @@ private Window CreateMainWindow() mainWindowViewModel, ShowSettingsWindow, ShowSetupGuideWindow, - ShowSettingsWindow, + InstallAvailableUpdateAsync, DisconnectBluetoothDevices, AcceptPairingApprovalAsync, RejectPairingApproval); @@ -325,6 +325,12 @@ private UpdateService CreateUpdateService() OnStateChanged: UpdateMainWindowState)); } + private Task InstallAvailableUpdateAsync() + { + return updateService?.InstallAvailableUpdateAsync() + ?? Task.FromResult(UpdateApplyResult.DownloadFailure(UpdateFailureReason.NotAvailable)); + } + private PairingApprovalManager CreatePairingApprovalManager() { return new PairingApprovalManager(new JsonPairingStore(Path.Combine(UserDataDirectory(), "pairing-state.json"))); @@ -743,7 +749,11 @@ private static bool IsInstalledApp() private void UpdateMainWindowState(UpdateState state) { RecordUpdateStateDiagnostic(state); - Dispatcher.BeginInvoke(() => mainWindowViewModel.SetUpdateState(state)); + Dispatcher.BeginInvoke(() => + { + mainWindowViewModel.SetUpdateState(state); + settingsWindow?.ApplyUpdateState(state); + }); } private void UpdateBluetoothState(BluetoothStatus status) diff --git a/src/SwitchifyPc.App/MainWindow.xaml b/src/SwitchifyPc.App/MainWindow.xaml index 4e03297..98a1b4b 100644 --- a/src/SwitchifyPc.App/MainWindow.xaml +++ b/src/SwitchifyPc.App/MainWindow.xaml @@ -314,7 +314,8 @@