From 3e74e4ae5d58d1aeeb1130e7abc7320618b17f3f Mon Sep 17 00:00:00 2001 From: Magesh K <47920326+mahee96@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:33:20 +0530 Subject: [PATCH] [removeExtensions]: Bug-Fix: appExtensions is not available later at async contect, so capture it prematurely when available --- AltStore/Managing Apps/AppManager.swift | 4 ++- .../RemoveAppExtensionsOperation.swift | 28 ++++++++----------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/AltStore/Managing Apps/AppManager.swift b/AltStore/Managing Apps/AppManager.swift index a6524501..de6257d3 100644 --- a/AltStore/Managing Apps/AppManager.swift +++ b/AltStore/Managing Apps/AppManager.swift @@ -1343,7 +1343,9 @@ private extension AppManager verifyOperation.addDependency(downloadOperation) /* Remove App Extensions */ - let removeAppExtensionsOperation = RemoveAppExtensionsOperation(context: context, appInDatabase: app) + let localAppExtensions = (app as? ALTApplication)?.appExtensions + let removeAppExtensionsOperation = RemoveAppExtensionsOperation(context: context, + localAppExtensions: localAppExtensions) removeAppExtensionsOperation.resultHandler = { (result) in switch result { diff --git a/AltStore/Operations/RemoveAppExtensionsOperation.swift b/AltStore/Operations/RemoveAppExtensionsOperation.swift index 1b07e123..da12500a 100644 --- a/AltStore/Operations/RemoveAppExtensionsOperation.swift +++ b/AltStore/Operations/RemoveAppExtensionsOperation.swift @@ -16,12 +16,12 @@ import AltSign final class RemoveAppExtensionsOperation: ResultOperation { let context: AppOperationContext - let appInDatabase: AppProtocol + let localAppExtensions: Set? - init(context: AppOperationContext, appInDatabase: AppProtocol) + init(context: AppOperationContext, localAppExtensions: Set?) { self.context = context - self.appInDatabase = appInDatabase + self.localAppExtensions = localAppExtensions super.init() } @@ -41,9 +41,8 @@ final class RemoveAppExtensionsOperation: ResultOperation )) } - self.removeAppExtensions(from: targetAppBundle, - appInDatabase: appInDatabase as? ALTApplication, + localAppExtensions: localAppExtensions, extensions: targetAppBundle.appExtensions, context.authenticatedContext.presentingViewController) @@ -60,7 +59,7 @@ final class RemoveAppExtensionsOperation: ResultOperation private func removeAppExtensions(from targetAppBundle: ALTApplication, - appInDatabase: ALTApplication?, + localAppExtensions: Set?, extensions: Set, _ presentingViewController: UIViewController?) { @@ -71,13 +70,13 @@ final class RemoveAppExtensionsOperation: ResultOperation } // process extensionsInfo - let excessExtensions = processExtensionsInfo(from: targetAppBundle, appInDatabase: appInDatabase) + let excessExtensions = processExtensionsInfo(from: targetAppBundle, localAppExtensions: localAppExtensions) DispatchQueue.main.async { guard let presentingViewController: UIViewController = presentingViewController, presentingViewController.viewIfLoaded?.window != nil else { // background mode: remove only the excess extensions automatically for re-installs - // keep all extensions for fresh install (appInDatabase = nil) + // keep all extensions for fresh install (localAppBundle = nil) return self.backgroundModeExtensionsCleanup(excessExtensions: excessExtensions) } @@ -177,13 +176,13 @@ final class RemoveAppExtensionsOperation: ResultOperation } private func processExtensionsInfo(from targetAppBundle: ALTApplication, - appInDatabase: ALTApplication?) -> Set + localAppExtensions: Set?) -> Set { //App-Extensions: Ensure existing app's extensions in DB and currently installing app bundle's extensions must match let targetAppEx: Set = targetAppBundle.appExtensions let targetAppExNames = targetAppEx.map{ appEx in appEx.bundleIdentifier} - guard let extensionsInExistingApp = appInDatabase?.appExtensions else { + guard let extensionsInExistingApp = localAppExtensions else { let diagnosticsMsg = "RemoveAppExtensionsOperation: ExistingApp is nil, Hence keeping all app extensions from targetAppBundle" + "RemoveAppExtensionsOperation: ExistingAppEx: nil; targetAppBundleEx: \(targetAppExNames)" print(diagnosticsMsg) @@ -191,20 +190,15 @@ final class RemoveAppExtensionsOperation: ResultOperation } let existingAppEx: Set = extensionsInExistingApp - let existingAppExNames = existingAppEx.map{ appEx in appEx.bundleIdentifier} let excessExtensionsInTargetApp = targetAppEx.filter{ !(existingAppExNames.contains($0.bundleIdentifier)) } - - let excessExtensionsInExistingApp = existingAppEx.filter{ - !(targetAppExNames.contains($0.bundleIdentifier)) - } let isMatching = (targetAppEx.count == existingAppEx.count) && excessExtensionsInTargetApp.isEmpty - let diagnosticsMsg = "RemoveAppExtensionsOperation: App Extensions in existingApp and targetAppBundle are matching: \(isMatching)\n" - + "RemoveAppExtensionsOperation: existingAppEx: \(existingAppExNames); targetAppBundleEx: \(String(describing: targetAppExNames))\n" + let diagnosticsMsg = "RemoveAppExtensionsOperation: App Extensions in localAppBundle and targetAppBundle are matching: \(isMatching)\n" + + "RemoveAppExtensionsOperation: \nlocalAppBundleEx: \(existingAppExNames); \ntargetAppBundleEx: \(String(describing: targetAppExNames))\n" print(diagnosticsMsg) return excessExtensionsInTargetApp