From 1444afa2b526913a696a095d2ed61e2991d10297 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Wed, 16 Nov 2022 17:41:21 -0600 Subject: [PATCH] Fixes updating apps to latest version instead of latest supported version from My Apps tab --- AltStore/Managing Apps/AppManager.swift | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index ce36742c..74bccfe2 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -25,6 +25,12 @@ extension AppManager static let expirationWarningNotificationID = "altstore-expiration-warning" static let enableJITResultNotificationID = "altstore-enable-jit" + + enum PreferredAppVersion + { + case latestSupportedVersion + case latestAvailableVersionWithFallback + } } @available(iOS 13, *) @@ -477,10 +483,17 @@ extension AppManager } @discardableResult - func update(_ app: InstalledApp, presentingViewController: UIViewController?, context: AuthenticatedOperationContext = AuthenticatedOperationContext(), completionHandler: @escaping (Result) -> Void) -> Progress + func update(_ installedApp: InstalledApp, to preferredAppVersion: PreferredAppVersion = .latestSupportedVersion, presentingViewController: UIViewController?, context: AuthenticatedOperationContext = AuthenticatedOperationContext(), completionHandler: @escaping (Result) -> Void) -> Progress { - guard let storeApp = app.storeApp else { - completionHandler(.failure(OperationError.appNotFound(name: app.name))) + let preferredApp: AppProtocol? + switch preferredAppVersion + { + case .latestSupportedVersion: preferredApp = installedApp.storeApp?.latestSupportedVersion + case .latestAvailableVersionWithFallback: preferredApp = installedApp.storeApp // Use StoreApp directly to correctly handle min/max OS versions in DownloadAppOperation. + } + + guard let app = preferredApp else { + completionHandler(.failure(OperationError.appNotFound(name: installedApp.name))) return Progress.discreteProgress(totalUnitCount: 1) } @@ -497,8 +510,8 @@ extension AppManager } } - let operation = AppOperation.update(storeApp) - assert(operation.app as AnyObject === storeApp) // Make sure we never accidentally "update" to already installed app. + let operation = AppOperation.update(app) + assert(operation.app as AnyObject !== installedApp) // Make sure we never accidentally "update" to already installed app. self.perform([operation], presentingViewController: presentingViewController, group: group)