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 do
{ {
if let error = self.context.error if let error = self.context.error { throw error }
{
throw error
}
guard let installedApp = self.context.installedApp, let context = installedApp.managedObjectContext else { throw OperationError.invalidParameters } guard let installedApp = self.context.installedApp, let context = installedApp.managedObjectContext else { throw OperationError.invalidParameters }
context.perform { context.perform {

View File

@@ -31,10 +31,7 @@ final class DeactivateAppOperation: ResultOperation<InstalledApp>
{ {
super.main() super.main()
if let error = self.context.error if let error = self.context.error { return self.finish(.failure(error)) }
{
return self.finish(.failure(error))
}
DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in
let installedApp = context.object(with: self.app.objectID) as! InstalledApp let installedApp = context.object(with: self.app.objectID) as! InstalledApp
@@ -42,13 +39,21 @@ final class DeactivateAppOperation: ResultOperation<InstalledApp>
let allIdentifiers = [installedApp.resignedBundleIdentifier] + appExtensionProfiles let allIdentifiers = [installedApp.resignedBundleIdentifier] + appExtensionProfiles
for profile in allIdentifiers { for profile in allIdentifiers {
do { var attempts = 5
try remove_provisioning_profile(profile) while (attempts > 0){
self.progress.completedUnitCount += 1 print("Remove Provisioning profile attempts left: \(attempts)")
installedApp.isActive = false do {
return self.finish(.success(installedApp)) try remove_provisioning_profile(profile)
} catch { self.progress.completedUnitCount += 1
return self.finish(.failure(error)) 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)) } guard let installedApp = self.context.installedApp else { return self.finish(.failure(OperationError.invalidParameters)) }
installedApp.managedObjectContext?.perform { installedApp.managedObjectContext?.perform {
do { var retries = 3
try debug_app(installedApp.resignedBundleIdentifier) while (retries > 0){
} catch { do {
return self.finish(.failure(error)) 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 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 // Reinstalling ourself will hang until we leave the app, so we need to exit it without force closing
DispatchQueue.main.asyncAfter(deadline: .now() + 3) { DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
if UIApplication.shared.applicationState != .active { if UIApplication.shared.applicationState != .active {
@@ -172,12 +172,13 @@ final class InstallAppOperation: ResultOperation<InstalledApp>
try install_ipa(installedApp.bundleIdentifier) try install_ipa(installedApp.bundleIdentifier)
installing = false installing = false
installedApp.refreshedDate = Date() installedApp.refreshedDate = Date()
return self.finish(.success(installedApp)) self.finish(.success(installedApp))
break
} catch { } catch {
if (attempts == 0){ if (attempts == 0){
installing = false installing = false
return self.finish(.failure(error)) self.finish(.failure(MinimuxerError.InstallApp))
} else { attempts -= 1 } }
} }
} }
} }

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

View File

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