#!/usr/bin/env python3 """Sync Aligner's macOS app icon assets from the design handoff.""" from __future__ import annotations import json import shutil from pathlib import Path OUTPUT_ROOT = Path(__file__).resolve().parents[1] PROJECT_ROOT = OUTPUT_ROOT.parent RESOURCES = OUTPUT_ROOT / "C1.source" / "Resources" APPICONSET = RESOURCES / "Assets.xcassets" / "AppIcon.appiconset" ICNS_PATH = RESOURCES / "AppIcon.icns" HANDOFF_DIR = ( PROJECT_ROOT / "02-P" / "Round01-QuickSwitch-MVP" / "02.ui设计稿" / "AppIcon-D1-BigBars-Handoff-20260604" ) HANDOFF_ICONSET = HANDOFF_DIR / "AppIcon-D1-BigBars.iconset" HANDOFF_ICNS = HANDOFF_DIR / "Aligner-AppIcon-D1-BigBars.icns" HANDOFF_PREVIEW = HANDOFF_DIR / "Aligner-AppIcon-D1-BigBars-1024.png" ICON_FILES = [ "icon_16x16.png", "icon_16x16@2x.png", "icon_32x32.png", "icon_32x32@2x.png", "icon_128x128.png", "icon_128x128@2x.png", "icon_256x256.png", "icon_256x256@2x.png", "icon_512x512.png", "icon_512x512@2x.png", ] def require_file(path: Path) -> None: if not path.is_file(): raise FileNotFoundError(f"missing app icon source: {path}") def load_contents_json() -> dict: contents_path = HANDOFF_ICONSET / "Contents.json" require_file(contents_path) with contents_path.open("r", encoding="utf-8") as file: return json.load(file) def sync_iconset() -> None: APPICONSET.mkdir(parents=True, exist_ok=True) contents = load_contents_json() for filename in ICON_FILES: source = HANDOFF_ICONSET / filename require_file(source) shutil.copy2(source, APPICONSET / filename) require_file(HANDOFF_PREVIEW) shutil.copy2(HANDOFF_PREVIEW, APPICONSET / "icon_1024_preview.png") with (APPICONSET / "Contents.json").open("w", encoding="utf-8") as file: json.dump(contents, file, indent=2, ensure_ascii=False) file.write("\n") def sync_icns() -> None: require_file(HANDOFF_ICNS) shutil.copy2(HANDOFF_ICNS, ICNS_PATH) def main() -> None: sync_iconset() sync_icns() print(f"Synced AppIcon assets from: {HANDOFF_DIR}") if __name__ == "__main__": main()