From 31bcb289b005e26c2ff04cca875274568bcaaa6f Mon Sep 17 00:00:00 2001 From: onevcat Date: Sat, 6 Jun 2026 13:38:23 +0900 Subject: [PATCH] Preserve downloaded update install flow --- .../Updates/Reducer/UpdatesFeature.swift | 19 ++++++++---- supacodeTests/UpdatesFeatureTests.swift | 29 +++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/supacode/Features/Updates/Reducer/UpdatesFeature.swift b/supacode/Features/Updates/Reducer/UpdatesFeature.swift index d2d27cd2..488fbb3d 100644 --- a/supacode/Features/Updates/Reducer/UpdatesFeature.swift +++ b/supacode/Features/Updates/Reducer/UpdatesFeature.swift @@ -48,16 +48,14 @@ struct UpdatesFeature { case .activateUpdateButton: if state.isUpdateReadyToInstall { - state.isUpdateAvailable = false - state.isUpdateReadyToInstall = false - state.availableVersion = nil - return .run { _ in - await updaterClient.installDownloadedUpdate() - } + return installDownloadedUpdate(&state) } return .send(.checkForUpdates) case .checkForUpdates: + if state.isUpdateReadyToInstall { + return installDownloadedUpdate(&state) + } analyticsClient.capture("update_checked", nil) // Clear the badge so a fresh user-initiated check drives the standard dialog. // If the update is still available, Sparkle re-triggers `showUpdateFound` and @@ -91,4 +89,13 @@ struct UpdatesFeature { } } } + + private func installDownloadedUpdate(_ state: inout State) -> Effect { + state.isUpdateAvailable = false + state.isUpdateReadyToInstall = false + state.availableVersion = nil + return .run { _ in + await updaterClient.installDownloadedUpdate() + } + } } diff --git a/supacodeTests/UpdatesFeatureTests.swift b/supacodeTests/UpdatesFeatureTests.swift index 85e443d9..c0fbbcd8 100644 --- a/supacodeTests/UpdatesFeatureTests.swift +++ b/supacodeTests/UpdatesFeatureTests.swift @@ -103,4 +103,33 @@ struct UpdatesFeatureTests { #expect(checkCount.value == 1) } + + @Test(.dependencies) func checkForUpdatesInstallsDownloadedUpdateWhenReady() async { + let checkCount = LockIsolated(0) + let installCount = LockIsolated(0) + var state = UpdatesFeature.State() + state.isUpdateAvailable = true + state.isUpdateReadyToInstall = true + state.availableVersion = "2026.6.6" + let store = TestStore(initialState: state) { + UpdatesFeature() + } withDependencies: { + $0.analyticsClient.capture = { _, _ in } + $0.updaterClient.checkForUpdates = { + checkCount.withValue { $0 += 1 } + } + $0.updaterClient.installDownloadedUpdate = { + installCount.withValue { $0 += 1 } + } + } + + await store.send(.checkForUpdates) { + $0.isUpdateAvailable = false + $0.isUpdateReadyToInstall = false + $0.availableVersion = nil + } + + #expect(checkCount.value == 0) + #expect(installCount.value == 1) + } } -- 2.51.2