Finally fix retries for minimuxer calls

This commit is contained in:
Nythepegasus
2023-07-24 16:58:09 -04:00
committed by nythepegasus
parent 090456bba1
commit cc5c280882
6 changed files with 55 additions and 33 deletions

View File

@@ -46,10 +46,7 @@ class BackupAppOperation: ResultOperation<Void>
do
{
if let error = self.context.error
{
throw error
}
if let error = self.context.error { throw error }
guard let installedApp = self.context.installedApp, let context = installedApp.managedObjectContext else { throw OperationError.invalidParameters }
context.perform {

View File

@@ -31,10 +31,7 @@ final class DeactivateAppOperation: ResultOperation<InstalledApp>
{
super.main()
if let error = self.context.error
{
return self.finish(.failure(error))
}
if let error = self.context.error { return self.finish(.failure(error)) }
DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in
let installedApp = context.object(with: self.app.objectID) as! InstalledApp
@@ -42,13 +39,21 @@ final class DeactivateAppOperation: ResultOperation<InstalledApp>
let allIdentifiers = [installedApp.resignedBundleIdentifier] + appExtensionProfiles
for profile in allIdentifiers {
do {
try remove_provisioning_profile(profile)
self.progress.completedUnitCount += 1
installedApp.isActive = false
return self.finish(.success(installedApp))
} catch {
return self.finish(.failure(error))
var attempts = 5
while (attempts > 0){
print("Remove Provisioning profile attempts left: \(attempts)")
do {
try remove_provisioning_profile(profile)
self.progress.completedUnitCount += 1
installedApp.isActive = false
self.finish(.success(installedApp))
break
} catch {
attempts -= 1
if (attempts <= 0){
self.finish(.failure(error))
}
}
}
}
}

View File

@@ -45,13 +45,19 @@ final class EnableJITOperation<Context: EnableJITContext>: ResultOperation<Void>
guard let installedApp = self.context.installedApp else { return self.finish(.failure(OperationError.invalidParameters)) }
installedApp.managedObjectContext?.perform {
do {
try debug_app(installedApp.resignedBundleIdentifier)
} catch {
return self.finish(.failure(error))
var retries = 3
while (retries > 0){
do {
try debug_app(installedApp.resignedBundleIdentifier)
self.finish(.success(()))
break
} catch {
retries -= 1
if (retries <= 0){
return self.finish(.failure(error))
}
}
}
self.finish(.success(()))
}
}
}

View File

@@ -150,7 +150,7 @@ final class InstallAppOperation: ResultOperation<InstalledApp>
}
var installing = true
if installedApp.storeApp?.bundleIdentifier == Bundle.Info.appbundleIdentifier {
if installedApp.storeApp?.bundleIdentifier.range(of: Bundle.Info.appbundleIdentifier) != nil {
// Reinstalling ourself will hang until we leave the app, so we need to exit it without force closing
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
if UIApplication.shared.applicationState != .active {
@@ -172,12 +172,13 @@ final class InstallAppOperation: ResultOperation<InstalledApp>
try install_ipa(installedApp.bundleIdentifier)
installing = false
installedApp.refreshedDate = Date()
return self.finish(.success(installedApp))
self.finish(.success(installedApp))
break
} catch {
if (attempts == 0){
installing = false
return self.finish(.failure(error))
} else { attempts -= 1 }
self.finish(.failure(MinimuxerError.InstallApp))
}
}
}
}

View File

@@ -40,21 +40,31 @@ final class RefreshAppOperation: ResultOperation<InstalledApp>
guard let profiles = self.context.provisioningProfiles else { return self.finish(.failure(OperationError.invalidParameters)) }
guard let app = self.context.app else { return self.finish(.failure(OperationError.appNotFound)) }
DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in
print("Sending refresh app request...")
for p in profiles {
for p in profiles {
var attempts = 5
while (attempts > 0){
print("Install provisioning profile attempts left: \(attempts)")
do {
let bytes = p.value.data.toRustByteSlice()
try install_provisioning_profile(bytes.forRust())
break
} catch {
return self.finish(.failure(error))
attempts -= 1
if (attempts <= 0) {
self.finish(.failure(MinimuxerError.ProfileInstall))
}
}
}
DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in
print("Sending refresh app request...")
self.progress.completedUnitCount += 1
let predicate = NSPredicate(format: "%K == %@", #keyPath(InstalledApp.bundleIdentifier), app.bundleIdentifier)
self.managedObjectContext.perform {
guard let installedApp = InstalledApp.first(satisfying: predicate, in: self.managedObjectContext) else {
self.finish(.failure(OperationError.appNotFound))
return
}
installedApp.update(provisioningProfile: p.value)

View File

@@ -51,18 +51,21 @@ final class SendAppOperation: ResultOperation<()>
do {
let bytes = Data(data).toRustByteSlice()
try yeet_app_afc(app.bundleIdentifier, bytes.forRust())
self.progress.completedUnitCount += 1
self.finish(.success(()))
break
} catch {
attempts -= 1
if (attempts == 0) {
return self.finish(.failure(error))
} else { continue }
self.finish(.failure(MinimuxerError.RwAfc))
}
}
self.progress.completedUnitCount += 1
return self.finish(.success(()))
}
} else {
print("IPA doesn't exist????")
return self.finish(.failure(ALTServerError(.underlyingError)))
self.finish(.failure(OperationError.appNotFound))
}
}
}