Skip to content

Commit 64ca848

Browse files
chore(preprod): Include idiom and colorspace info in asssets.json (#2860)
So we can show users why they have duplicate images despite not having intended to (and nudge them to consider app thinning on their side)
1 parent b182669 commit 64ca848

1 file changed

Lines changed: 36 additions & 2 deletions

File tree

apple-catalog-parsing/native/swift/AssetCatalogParser/Sources/AssetCatalogParser/AssetCatalogReader.swift

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ struct AssetCatalogEntry: Encodable {
3838
let height: Int?
3939
let filename: String?
4040
let type: AssetType?
41+
let idiom: String?
42+
let colorspace: String?
4143
}
4244

4345
enum Error: Swift.Error {
@@ -49,6 +51,31 @@ typealias objectiveCMethodImp = @convention(c) (AnyObject, Selector, UnsafeRawPo
4951
>?
5052

5153
enum AssetUtil {
54+
private static func idiomToString(_ idiom: UInt?) -> String? {
55+
guard let idiom = idiom else { return nil }
56+
switch idiom {
57+
case 0: return "universal"
58+
case 1: return "phone"
59+
case 2: return "pad"
60+
case 3: return "tv"
61+
case 4: return "carplay"
62+
case 5: return "watch"
63+
case 6: return "marketing"
64+
default: return nil
65+
}
66+
}
67+
68+
private static func colorSpaceIDToString(_ colorSpaceID: UInt?) -> String? {
69+
guard let colorSpaceID = colorSpaceID else { return nil }
70+
switch colorSpaceID {
71+
case 1: return "srgb"
72+
case 2: return "gray gamma 22"
73+
case 3: return "displayP3"
74+
case 4: return "extended srgb"
75+
default: return nil
76+
}
77+
}
78+
5279
private static func createResultsPath(assetURL: URL, outputURL: URL) throws -> URL {
5380
var archiveURL = assetURL
5481
var tailComponents: [String] = []
@@ -136,6 +163,9 @@ enum AssetUtil {
136163
if !fileExtension.isEmpty && fileExtension != "svg", let unslicedImage = unslicedImage {
137164
images[imageId] = (cgImage: unslicedImage, format: fileExtension)
138165
}
166+
167+
let idiomValue = key.getUInt(forKey: "themeIdiom")
168+
let colorSpaceID = rendition.getUInt(forKey: "colorSpaceID")
139169

140170
let asset = AssetCatalogEntry(
141171
imageId: imageId,
@@ -145,7 +175,9 @@ enum AssetUtil {
145175
width: width,
146176
height: height,
147177
filename: renditionTypeName,
148-
type: assetType
178+
type: assetType,
179+
idiom: idiomToString(idiomValue),
180+
colorspace: colorSpaceIDToString(colorSpaceID)
149181
)
150182
assets.append(asset)
151183
}
@@ -158,7 +190,9 @@ enum AssetUtil {
158190
width: nil,
159191
height: nil,
160192
filename: nil,
161-
type: nil
193+
type: nil,
194+
idiom: nil,
195+
colorspace: nil
162196
))
163197

164198
let data = try! JSONEncoder().encode(assets)

0 commit comments

Comments
 (0)