[AltStoreCore] Adds AppProtocol.storeApp

Simplifies retrieving the associated StoreApp for an app.
This commit is contained in:
Riley Testut
2023-11-29 15:15:36 -06:00
parent a1038d8850
commit 45da6b626f
5 changed files with 21 additions and 5 deletions

View File

@@ -1246,7 +1246,7 @@ private extension AppManager
let patchAppURL = URL(string: patchAppLink) let patchAppURL = URL(string: patchAppLink)
else { throw OperationError.invalidApp } else { throw OperationError.invalidApp }
let patchApp = AnyApp(name: app.name, bundleIdentifier: app.bundleIdentifier, url: patchAppURL) let patchApp = AnyApp(name: app.name, bundleIdentifier: app.bundleIdentifier, url: patchAppURL, storeApp: nil)
DispatchQueue.main.async { DispatchQueue.main.async {
let storyboard = UIStoryboard(name: "PatchApp", bundle: nil) let storyboard = UIStoryboard(name: "PatchApp", bundle: nil)

View File

@@ -110,7 +110,7 @@ class PatchAppOperation: ResultOperation<Void>
.flatMap { self.patch(resignedApp, withBinaryAt: $0) } .flatMap { self.patch(resignedApp, withBinaryAt: $0) }
.tryMap { try FileManager.default.zipAppBundle(at: $0) } .tryMap { try FileManager.default.zipAppBundle(at: $0) }
.tryMap { (fileURL) in .tryMap { (fileURL) in
let app = AnyApp(name: resignedApp.name, bundleIdentifier: self.context.bundleIdentifier, url: resignedApp.fileURL) let app = AnyApp(name: resignedApp.name, bundleIdentifier: self.context.bundleIdentifier, url: resignedApp.fileURL, storeApp: nil)
let destinationURL = InstalledApp.refreshedIPAURL(for: app) let destinationURL = InstalledApp.refreshedIPAURL(for: app)
try FileManager.default.copyItem(at: fileURL, to: destinationURL, shouldReplace: true) try FileManager.default.copyItem(at: fileURL, to: destinationURL, shouldReplace: true)

View File

@@ -44,7 +44,7 @@ class SendAppOperation: ResultOperation<ServerConnection>
Logger.sideload.notice("Sending app \(self.context.bundleIdentifier, privacy: .public) to AltServer \(server.localizedName ?? "nil", privacy: .public)...") Logger.sideload.notice("Sending app \(self.context.bundleIdentifier, privacy: .public) to AltServer \(server.localizedName ?? "nil", privacy: .public)...")
// self.context.resignedApp.fileURL points to the app bundle, but we want the .ipa. // self.context.resignedApp.fileURL points to the app bundle, but we want the .ipa.
let app = AnyApp(name: resignedApp.name, bundleIdentifier: self.context.bundleIdentifier, url: resignedApp.fileURL) let app = AnyApp(name: resignedApp.name, bundleIdentifier: self.context.bundleIdentifier, url: resignedApp.fileURL, storeApp: nil)
let fileURL = InstalledApp.refreshedIPAURL(for: app) let fileURL = InstalledApp.refreshedIPAURL(for: app)
// Connect to server. // Connect to server.

View File

@@ -107,7 +107,7 @@ public extension LoggedError
{ {
var app: AppProtocol { var app: AppProtocol {
// `as AppProtocol` needed to fix "cannot convert AnyApp to StoreApp" compiler error with Xcode 14. // `as AppProtocol` needed to fix "cannot convert AnyApp to StoreApp" compiler error with Xcode 14.
let app = self.installedApp ?? self.storeApp ?? AnyApp(name: self.appName, bundleIdentifier: self.appBundleID, url: nil) as AppProtocol let app = self.installedApp ?? self.storeApp ?? AnyApp(name: self.appName, bundleIdentifier: self.appBundleID, url: nil, storeApp: nil) as AppProtocol
return app return app
} }

View File

@@ -14,6 +14,8 @@ public protocol AppProtocol
var name: String { get } var name: String { get }
var bundleIdentifier: String { get } var bundleIdentifier: String { get }
var url: URL? { get } var url: URL? { get }
var storeApp: StoreApp? { get }
} }
public struct AnyApp: AppProtocol public struct AnyApp: AppProtocol
@@ -21,12 +23,14 @@ public struct AnyApp: AppProtocol
public var name: String public var name: String
public var bundleIdentifier: String public var bundleIdentifier: String
public var url: URL? public var url: URL?
public var storeApp: StoreApp?
public init(name: String, bundleIdentifier: String, url: URL?) public init(name: String, bundleIdentifier: String, url: URL?, storeApp: StoreApp?)
{ {
self.name = name self.name = name
self.bundleIdentifier = bundleIdentifier self.bundleIdentifier = bundleIdentifier
self.url = url self.url = url
self.storeApp = storeApp
} }
} }
@@ -35,6 +39,10 @@ extension ALTApplication: AppProtocol
public var url: URL? { public var url: URL? {
return self.fileURL return self.fileURL
} }
public var storeApp: StoreApp? {
return nil
}
} }
extension StoreApp: AppProtocol extension StoreApp: AppProtocol
@@ -42,6 +50,10 @@ extension StoreApp: AppProtocol
public var url: URL? { public var url: URL? {
return self.latestAvailableVersion?.downloadURL return self.latestAvailableVersion?.downloadURL
} }
public var storeApp: StoreApp? {
return self
}
} }
extension InstalledApp: AppProtocol extension InstalledApp: AppProtocol
@@ -64,4 +76,8 @@ extension AppVersion: AppProtocol
public var url: URL? { public var url: URL? {
return self.downloadURL return self.downloadURL
} }
public var storeApp: StoreApp? {
return self.app
}
} }