"""Bundled static assets (application icon). The icon ships inside the package so the same file backs the window icon at runtime and the executable icon at build time. Keep this module free of Qt imports: the packaging spec imports it while collecting data files. Regenerate the files with ``py -3.10 scripts/gen_logo.py``. """ from __future__ import annotations import os import sys ICON_NAME = "cmshopee.ico" ICON_PNG_NAME = "cmshopee-256.png" _PACKAGE_DIR = os.path.dirname(os.path.abspath(__file__)) def _candidate_paths(name): """Locations to probe, covering source tree and PyInstaller onedir.""" yield os.path.join(_PACKAGE_DIR, name) bundle_dir = getattr(sys, "_MEIPASS", None) if bundle_dir: yield os.path.join(bundle_dir, "app", "assets", name) if getattr(sys, "frozen", False): yield os.path.join( os.path.dirname(os.path.abspath(sys.executable)), "app", "assets", name, ) def asset_path(name): """Return an existing asset path, or None when it is not bundled.""" for candidate in _candidate_paths(name): if candidate and os.path.isfile(candidate): return candidate return None def icon_path(): """Path to the multi-size Windows icon, or None when unavailable.""" return asset_path(ICON_NAME) def icon_png_path(): """Path to the 256px PNG fallback, or None when unavailable.""" return asset_path(ICON_PNG_NAME)