Updates build_whitelabel to regenerate album art for android auto app
This commit is contained in:
1 parent
f069fcdbfb
commit
58ea55f359
164 files changed
+111
-185
No files matched your search
Regular → Executable
+73
@@ -256,6 +256,75 @@ def generate_icon(theme: dict, dry_run: bool = False) -> None:
|
||||
print(" [icon] Install cairosvg (`pip install cairosvg`) or rsvg-convert")
|
||||
|
||||
|
||||
def generate_android_auto_art(theme: dict, dry_run: bool = False) -> None:
|
||||
"""Decode embedded hero_icon (JPEG, PNG, or SVG) and write kryz_auto_art.png."""
|
||||
embedded = theme["images_embedded"]
|
||||
hero_data = embedded["hero_icon"]["data"]
|
||||
hero_content_type = embedded["hero_icon"].get("content_type", "")
|
||||
print(" [android-auto-art] Using 'hero_icon' from images_embedded")
|
||||
|
||||
raw_bytes = base64.b64decode(hero_data)
|
||||
icon_path = os.path.join(PROJECT_ROOT, "android", "app", "src", "main", "res", "drawable-nodpi", "kryz_auto_art.png")
|
||||
|
||||
if dry_run:
|
||||
print(f" [android-auto-art] Would generate PNG from embedded {hero_content_type or 'image'} at android/app/src/main/res/drawable-nodpi/kryz_auto_art.png")
|
||||
return
|
||||
|
||||
# --- JPEG / PNG: convert to PNG via Pillow, or write as-is ---
|
||||
if hero_content_type in ("image/jpeg", "image/png"):
|
||||
try:
|
||||
from PIL import Image
|
||||
import io
|
||||
img = Image.open(io.BytesIO(raw_bytes)).convert("RGBA")
|
||||
img = img.resize((1024, 1024), Image.LANCZOS)
|
||||
img.save(icon_path, "PNG")
|
||||
print(f" [android-auto-art] Converted {hero_content_type} → PNG (Pillow, 1024×1024)")
|
||||
return
|
||||
except ImportError:
|
||||
pass
|
||||
except Exception as e:
|
||||
print(f" [android-auto-art] Pillow conversion failed: {e} — writing raw bytes")
|
||||
|
||||
# Fallback: write raw bytes directly
|
||||
if hero_content_type == "image/jpeg":
|
||||
fallback = os.path.join(PROJECT_ROOT, "android", "app", "src", "main", "res", "drawable-nodpi", "kryz_auto_art.jpg")
|
||||
else:
|
||||
fallback = icon_path
|
||||
with open(fallback, "wb") as f:
|
||||
f.write(raw_bytes)
|
||||
print(f" [android-auto-art] Wrote embedded {hero_content_type} (no Pillow — using raw bytes)")
|
||||
if fallback != icon_path:
|
||||
os.replace(fallback, icon_path)
|
||||
return
|
||||
|
||||
# --- SVG: render to PNG via cairosvg or rsvg-convert ---
|
||||
try:
|
||||
import cairosvg
|
||||
cairosvg.svg2png(bytestring=raw_bytes, write_to=icon_path, output_width=1024, output_height=1024)
|
||||
print(" [android-auto-art] Rendered SVG → PNG (cairosvg)")
|
||||
return
|
||||
except ImportError:
|
||||
pass
|
||||
except Exception as e:
|
||||
print(f" [android-auto-art] cairosvg failed: {e} — trying rsvg-convert")
|
||||
|
||||
try:
|
||||
import tempfile
|
||||
with tempfile.NamedTemporaryFile(suffix=".svg", delete=False) as tmp:
|
||||
tmp.write(raw_bytes)
|
||||
tmp_path = tmp.name
|
||||
subprocess.run(
|
||||
["rsvg-convert", "-w", "1024", "-h", "1024", "-o", icon_path, tmp_path],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
os.unlink(tmp_path)
|
||||
print(" [android-auto-art] Rendered SVG → PNG (rsvg-convert)")
|
||||
except Exception as e:
|
||||
print(f" [android-auto-art] WARNING: Could not render icon: {e}")
|
||||
print(" [android-auto-art] Install cairosvg (`pip install cairosvg`) or rsvg-convert")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Native file patching
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -467,6 +536,10 @@ def main():
|
||||
print()
|
||||
generate_icon(theme, dry_run=args.dry_run)
|
||||
|
||||
# Generate Android Auto album art
|
||||
print()
|
||||
generate_android_auto_art(theme, dry_run=args.dry_run)
|
||||
|
||||
# Patch native files
|
||||
print()
|
||||
patch_android_manifest(theme, dry_run=args.dry_run)
|
||||
|
||||
Reference in new issue
Block a user