From 3d70271306f1e6bbda6b53052326f658ce77b28f 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 cf82b825..0f90ae70 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -27,6 +27,12 @@ extension AppManager static let expirationWarningNotificationID = "altstore-expiration-warning" static let enableJITResultNotificationID = "altstore-enable-jit" + + enum PreferredAppVersion + { + case latestSupportedVersion + case latestAvailableVersionWithFallback + } } @available(iOS 13, *) @@ -499,10 +505,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) } @@ -519,8 +532,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)