Supports both iPhone + iPad screenshots

Prefers showing screenshots for current device, but falls back to all screenshots if there are no relevant ones.
This commit is contained in:
Riley Testut
2023-10-13 13:40:08 -05:00
committed by Magesh K
parent 57059967c6
commit a49e16f591
13 changed files with 258 additions and 76 deletions

View File

@@ -23,6 +23,7 @@ extension SourceError
case duplicate
case missingPermissionUsageDescription
case missingScreenshotSize
}
static func unsupported(_ source: Source) -> SourceError { SourceError(code: .unsupported, source: source) }
@@ -36,6 +37,10 @@ extension SourceError
static func missingPermissionUsageDescription(for permission: any ALTAppPermission, app: StoreApp, source: Source) -> SourceError {
SourceError(code: .missingPermissionUsageDescription, source: source, app: app, permission: permission)
}
static func missingScreenshotSize(for screenshot: AppScreenshot, source: Source) -> SourceError {
SourceError(code: .missingScreenshotSize, source: source, app: screenshot.app, screenshotURL: screenshot.imageURL)
}
}
struct SourceError: ALTLocalizedError
@@ -59,6 +64,9 @@ struct SourceError: ALTLocalizedError
@UserInfoValue
var permission: (any ALTAppPermission)?
@UserInfoValue
var screenshotURL: URL?
var errorFailureReason: String {
switch self.code
{
@@ -112,6 +120,14 @@ struct SourceError: ALTLocalizedError
let permissionType = permission.type.localizedName ?? NSLocalizedString("Permission", comment: "")
let failureReason = String(format: NSLocalizedString("The %@ '%@' for %@ is missing a usage description.", comment: ""), permissionType.lowercased(), permission.rawValue, appName)
return failureReason
case .missingScreenshotSize:
let appName = self.$app.name ?? String(format: NSLocalizedString("an app in source “%@”", comment: ""), self.$source.name)
let baseMessage = String(format: NSLocalizedString("An iPad screenshot for %@ does not specify its size", comment: ""), appName)
guard let screenshotURL else { return baseMessage + "." }
let failureReason = baseMessage + ": \(screenshotURL.absoluteString)"
return failureReason
}
}