Skip to content

Commit ada09f7

Browse files
Tweak icon parsing once more to handle adjusted name format (#442)
1 parent c8947a8 commit ada09f7

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

src/launchpad/artifacts/apple/zipped_xcarchive.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -441,18 +441,14 @@ def _parse_asset_element(self, item: dict[str, Any], parent_path: Path) -> Asset
441441
colorspace = item.get("colorspace")
442442

443443
file_extension = Path(filename).suffix.lower()
444-
full_path = None
445-
446-
if filename:
447-
if file_extension in {".png", ".jpg", ".jpeg", ".heic", ".heif"}:
448-
potential_path = parent_path / f"{image_id}{file_extension}"
449-
if potential_path.exists():
450-
full_path = potential_path
451-
elif not file_extension:
452-
# No extension, try .png as default (for some asset catalog entries)
453-
potential_path = parent_path / f"{image_id}.png"
454-
if potential_path.exists():
455-
full_path = potential_path
444+
if filename and file_extension in {".png", ".jpg", ".jpeg", ".heic", ".heif"}:
445+
potential_path = parent_path / f"{image_id}{file_extension}"
446+
if potential_path.exists():
447+
full_path = potential_path
448+
else:
449+
full_path = None
450+
else:
451+
full_path = None
456452

457453
return AssetCatalogElement(
458454
name=name,

src/launchpad/size/insights/apple/alternate_icons_optimization.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io
44

5-
from pathlib import Path
65
from typing import List
76

87
from PIL import Image
@@ -69,8 +68,3 @@ def _resize_icon_for_analysis(self, img: Image.Image) -> Image.Image:
6968
return img.resize((self.IPHONE_3X_ICON_SIZE, self.IPHONE_3X_ICON_SIZE), Image.Resampling.LANCZOS).resize(
7069
(self.APP_STORE_ICON_SIZE, self.APP_STORE_ICON_SIZE), Image.Resampling.LANCZOS
7170
)
72-
73-
def _is_alternate_icon_file(self, file_info: FileInfo, alternate_icon_names: set[str]) -> bool:
74-
# Some asset catalog entries have no extension, so we include "other" in the OPTIMIZABLE_FORMATS
75-
file_type_match = file_info.file_type.lower() in (self.OPTIMIZABLE_FORMATS | {"other"})
76-
return file_type_match and Path(file_info.path).stem in alternate_icon_names

src/launchpad/size/insights/apple/image_optimization.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,24 @@ def _check_heic_minification(self, img: Image.Image, file_size: int) -> _Optimiz
182182
logger.exception("HEIC image minification failed")
183183
return None
184184

185+
def _is_alternate_icon_file(self, file_info: FileInfo, alternate_icon_names: set[str]) -> bool:
186+
file_type_match = file_info.file_type.lower() in self.OPTIMIZABLE_FORMATS
187+
188+
if not file_type_match:
189+
return False
190+
191+
stem = Path(file_info.path).stem
192+
parent_str = str(Path(file_info.path).parent)
193+
194+
if stem in alternate_icon_names:
195+
return True
196+
197+
for name in alternate_icon_names:
198+
if parent_str == f"Assets.car/{name}":
199+
return True
200+
201+
return False
202+
185203

186204
class ImageOptimizationInsight(BaseImageOptimizationInsight):
187205
"""Analyse image optimisation opportunities in iOS apps."""
@@ -225,4 +243,14 @@ def _is_optimizable_image_file(
225243
return not Path(file_info.path).name.startswith(("AppIcon", "iMessage App Icon"))
226244

227245
stem = Path(file_info.path).stem
228-
return stem != primary_icon_name and stem not in alternate_icon_names
246+
parent_str = str(Path(file_info.path).parent)
247+
248+
# Exclude primary icon
249+
if stem == primary_icon_name or parent_str == f"Assets.car/{primary_icon_name}":
250+
return False
251+
252+
# Exclude alternate icons (they have their own insight)
253+
if self._is_alternate_icon_file(file_info, alternate_icon_names):
254+
return False
255+
256+
return True

0 commit comments

Comments
 (0)