"""Stable desktop identity shared by the launcher and Wine game window.""" from __future__ import annotations import os from pathlib import Path from typing import Mapping APPLICATION_NAME = "PristonTale EU" APPLICATION_WM_CLASS = "PristonTaleEU" APPLICATION_WM_INSTANCE = "pristontale-eu" APPLICATION_ICON_FILENAME = "eu.pristontale.PTLinux.png" APPLICATION_ICON_VARIABLE = "PTLINUX_ICON_PATH" def find_application_icon( environment: Mapping[str, str] | None = None, ) -> Path | None: """Find the installed icon, with source-tree fallbacks for development.""" env = os.environ if environment is None else environment candidates: list[Path] = [] explicit = env.get(APPLICATION_ICON_VARIABLE) if explicit: candidates.append(Path(explicit).expanduser()) # Some distributions bundle the icon beside this module. The installer # publishes the same asset through the user's XDG data directory. candidates.append(Path(__file__).with_name(APPLICATION_ICON_FILENAME)) home_value = env.get("HOME") if home_value: home = Path(home_value).expanduser() data_home_value = env.get("XDG_DATA_HOME") data_home = ( Path(data_home_value).expanduser() if data_home_value else home / ".local/share" ) candidates.append(data_home / "pixmaps" / APPLICATION_ICON_FILENAME) default_icon = home / ".local/share/pixmaps" / APPLICATION_ICON_FILENAME if default_icon not in candidates: candidates.append(default_icon) # The source checkout keeps installer assets under packaging/. candidates.append( Path(__file__).resolve().parent.parent / "packaging" / APPLICATION_ICON_FILENAME ) seen: set[Path] = set() for candidate in candidates: resolved = candidate.resolve(strict=False) if resolved in seen: continue seen.add(resolved) if resolved.is_file(): return resolved return None