refactor: remove minimuxerToOperationError in favor of extending MinimuxerError to be a LocalizedError and remove unused cases from OperationError

This commit is contained in:
naturecodevoid
2023-04-11 21:04:07 -07:00
parent 40bcef1dcb
commit b3d827f56a
8 changed files with 68 additions and 81 deletions

View File

@@ -153,7 +153,7 @@ final class LaunchViewController: RSTLaunchViewController, UIDocumentPickerDeleg
try start(pairing_file, documentsDirectory) try start(pairing_file, documentsDirectory)
} catch { } catch {
try! FileManager.default.removeItem(at: FileManager.default.documentsDirectory.appendingPathComponent("\(pairingFileName)")) try! FileManager.default.removeItem(at: FileManager.default.documentsDirectory.appendingPathComponent("\(pairingFileName)"))
displayError("minimuxer failed to start, please restart SideStore. \(minimuxerToOperationError(error).failureReason ?? "UNKNOWN ERROR!!!!!! REPORT TO GITHUB ISSUES!")") displayError("minimuxer failed to start, please restart SideStore. \((error as? LocalizedError)?.failureReason ?? "UNKNOWN ERROR!!!!!! REPORT TO GITHUB ISSUES!")")
} }
start_auto_mounter(documentsDirectory) start_auto_mounter(documentsDirectory)
} }

View File

@@ -46,7 +46,7 @@ final class DeactivateAppOperation: ResultOperation<InstalledApp>
do { do {
try remove_provisioning_profile(profile) try remove_provisioning_profile(profile)
} catch { } catch {
return self.finish(.failure(minimuxerToOperationError(error))) return self.finish(.failure(error))
} }
} }

View File

@@ -48,7 +48,7 @@ final class EnableJITOperation<Context: EnableJITContext>: ResultOperation<Void>
do { do {
try debug_app(installedApp.resignedBundleIdentifier) try debug_app(installedApp.resignedBundleIdentifier)
} catch { } catch {
return self.finish(.failure(minimuxerToOperationError(error))) return self.finish(.failure(error))
} }
self.finish(.success(())) self.finish(.success(()))

View File

@@ -152,7 +152,7 @@ final class InstallAppOperation: ResultOperation<InstalledApp>
do { do {
try install_ipa(installedApp.bundleIdentifier) try install_ipa(installedApp.bundleIdentifier)
} catch { } catch {
return self.finish(.failure(minimuxerToOperationError(error))) return self.finish(.failure(error))
} }
installedApp.refreshedDate = Date() installedApp.refreshedDate = Date()

View File

@@ -34,21 +34,6 @@ enum OperationError: LocalizedError
case openAppFailed(name: String) case openAppFailed(name: String)
case missingAppGroup case missingAppGroup
case noDevice
case createService(name: String)
case getFromDevice(name: String)
case setArgument(name: String)
case afc
case install
case uninstall
case lookupApps
case detach
case attach
case functionArguments
case profileManage
case noConnection
case invalidPairingFile
var failureReason: String? { var failureReason: String? {
switch self { switch self {
case .unknown: return NSLocalizedString("An unknown error occured.", comment: "") case .unknown: return NSLocalizedString("An unknown error occured.", comment: "")
@@ -64,20 +49,6 @@ enum OperationError: LocalizedError
case .openAppFailed(let name): return String(format: NSLocalizedString("SideStore was denied permission to launch %@.", comment: ""), name) case .openAppFailed(let name): return String(format: NSLocalizedString("SideStore was denied permission to launch %@.", comment: ""), name)
case .missingAppGroup: return NSLocalizedString("SideStore's shared app group could not be found.", comment: "") case .missingAppGroup: return NSLocalizedString("SideStore's shared app group could not be found.", comment: "")
case .maximumAppIDLimitReached: return NSLocalizedString("Cannot register more than 10 App IDs.", comment: "") case .maximumAppIDLimitReached: return NSLocalizedString("Cannot register more than 10 App IDs.", comment: "")
case .noDevice: return NSLocalizedString("Cannot fetch the device from the muxer", comment: "")
case .createService(let name): return String(format: NSLocalizedString("Cannot start a %@ server on the device.", comment: ""), name)
case .getFromDevice(let name): return String(format: NSLocalizedString("Cannot fetch %@ from the device.", comment: ""), name)
case .setArgument(let name): return String(format: NSLocalizedString("Cannot set %@ on the device.", comment: ""), name)
case .afc: return NSLocalizedString("AFC was unable to manage files on the device", comment: "")
case .install: return NSLocalizedString("Unable to install the app from the staging directory", comment: "")
case .uninstall: return NSLocalizedString("Unable to uninstall the app", comment: "")
case .lookupApps: return NSLocalizedString("Unable to fetch apps from the device", comment: "")
case .detach: return NSLocalizedString("Unable to detach from the app's process", comment: "")
case .attach: return NSLocalizedString("Unable to attach to the app's process", comment: "")
case .functionArguments: return NSLocalizedString("A function was passed invalid arguments", comment: "")
case .profileManage: return NSLocalizedString("Unable to manage profiles on the device", comment: "")
case .noConnection: return NSLocalizedString("Unable to connect to the device, make sure Wireguard is enabled and you're connected to WiFi", comment: "")
case .invalidPairingFile: return NSLocalizedString("Invalid pairing file. Your pairing file either didn't have a UDID, or it wasn't a valid plist. Please use jitterbugpair to generate it", comment: "")
} }
} }
@@ -123,50 +94,66 @@ enum OperationError: LocalizedError
} }
} }
/// crashes if error is not a MinimuxerError extension MinimuxerError: LocalizedError {
func minimuxerToOperationError(_ error: Error) -> OperationError { public var failureReason: String? {
switch error as! MinimuxerError { switch self {
case .NoDevice: case .NoDevice:
return OperationError.noDevice return NSLocalizedString("Cannot fetch the device from the muxer", comment: "")
case .NoConnection: case .NoConnection:
return OperationError.noConnection return NSLocalizedString("Unable to connect to the device, make sure Wireguard is enabled and you're connected to WiFi", comment: "")
case .PairingFile: case .PairingFile:
return OperationError.invalidPairingFile return NSLocalizedString("Invalid pairing file. Your pairing file either didn't have a UDID, or it wasn't a valid plist. Please use jitterbugpair to generate it", comment: "")
case .CreateDebug:
return OperationError.createService(name: "debug") case .CreateDebug:
case .CreateInstproxy: return self.createService(name: "debug")
return OperationError.createService(name: "instproxy") case .LookupApps:
case .LookupApps: return self.getFromDevice(name: "installed apps")
return OperationError.getFromDevice(name: "installed apps") case .FindApp:
case .FindApp: return self.getFromDevice(name: "path to the app")
return OperationError.getFromDevice(name: "path to the app") case .BundlePath:
case .BundlePath: return self.getFromDevice(name: "bundle path")
return OperationError.getFromDevice(name: "bundle path") case .MaxPacket:
case .MaxPacket: return self.setArgument(name: "max packet")
return OperationError.setArgument(name: "max packet") case .WorkingDirectory:
case .WorkingDirectory: return self.setArgument(name: "working directory")
return OperationError.setArgument(name: "working directory") case .Argv:
case .Argv: return self.setArgument(name: "argv")
return OperationError.setArgument(name: "argv") case .LaunchSuccess:
case .LaunchSuccess: return self.getFromDevice(name: "launch success")
return OperationError.getFromDevice(name: "launch success") case .Detach:
case .Detach: return NSLocalizedString("Unable to detach from the app's process", comment: "")
return OperationError.detach case .Attach:
case .Attach: return NSLocalizedString("Unable to attach to the app's process", comment: "")
return OperationError.attach
case .CreateAfc: case .CreateInstproxy:
return OperationError.createService(name: "AFC") return self.createService(name: "instproxy")
case .RwAfc: case .CreateAfc:
return OperationError.afc return self.createService(name: "AFC")
case .InstallApp: case .RwAfc:
return OperationError.install return NSLocalizedString("AFC was unable to manage files on the device", comment: "")
case .UninstallApp: case .InstallApp:
return OperationError.uninstall return NSLocalizedString("Unable to install the app from the staging directory", comment: "")
case .CreateMisagent: case .UninstallApp:
return OperationError.createService(name: "misagent") return NSLocalizedString("Unable to uninstall the app", comment: "")
case .ProfileInstall:
return OperationError.profileManage case .CreateMisagent:
case .ProfileRemove: return self.createService(name: "misagent")
return OperationError.profileManage case .ProfileInstall:
return NSLocalizedString("Unable to manage profiles on the device", comment: "")
case .ProfileRemove:
return NSLocalizedString("Unable to manage profiles on the device", comment: "")
}
}
fileprivate func createService(name: String) -> String {
return String(format: NSLocalizedString("Cannot start a %@ server on the device.", comment: ""), name)
}
fileprivate func getFromDevice(name: String) -> String {
return String(format: NSLocalizedString("Cannot fetch %@ from the device.", comment: ""), name)
}
fileprivate func setArgument(name: String) -> String {
return String(format: NSLocalizedString("Cannot set %@ on the device.", comment: ""), name)
} }
} }

View File

@@ -52,7 +52,7 @@ final class RefreshAppOperation: ResultOperation<InstalledApp>
let bytes = p.value.data.toRustByteSlice() let bytes = p.value.data.toRustByteSlice()
try install_provisioning_profile(bytes.forRust()) try install_provisioning_profile(bytes.forRust())
} catch { } catch {
return self.finish(.failure(minimuxerToOperationError(error))) return self.finish(.failure(error))
} }
self.progress.completedUnitCount += 1 self.progress.completedUnitCount += 1

View File

@@ -41,7 +41,7 @@ final class RemoveAppOperation: ResultOperation<InstalledApp>
do { do {
try remove_app(resignedBundleIdentifier) try remove_app(resignedBundleIdentifier)
} catch { } catch {
return self.finish(.failure(minimuxerToOperationError(error))) return self.finish(.failure(error))
} }
DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in DatabaseManager.shared.persistentContainer.performBackgroundTask { (context) in

View File

@@ -50,7 +50,7 @@ final class SendAppOperation: ResultOperation<()>
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())
} catch { } catch {
return self.finish(.failure(minimuxerToOperationError(error))) return self.finish(.failure(error))
} }
self.progress.completedUnitCount += 1 self.progress.completedUnitCount += 1