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

@@ -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)