diff --git a/supervisor/addons/model.py b/supervisor/addons/model.py index f50c7ea53..1c3ed1512 100644 --- a/supervisor/addons/model.py +++ b/supervisor/addons/model.py @@ -543,6 +543,11 @@ class AddonModel(CoreSysAttributes, ABC): """Return path to add-on icon.""" return Path(self.path_location, "icon.png") + @property + def path_dark_icon(self) -> Path: + """Return path to the dark variant of the add-on icon.""" + return Path(self.path_location, "dark_icon.png") + @property def path_logo(self) -> Path: """Return path to add-on logo.""" diff --git a/supervisor/api/addons.py b/supervisor/api/addons.py index 89f4fd021..78de786c6 100644 --- a/supervisor/api/addons.py +++ b/supervisor/api/addons.py @@ -69,6 +69,7 @@ from ..const import ( ATTR_NETWORK_RX, ATTR_NETWORK_TX, ATTR_OPTIONS, + ATTR_PREFER_DARK_ICON, ATTR_PRIVILEGED, ATTR_PROTECTED, ATTR_PWNED, @@ -113,6 +114,12 @@ _LOGGER: logging.Logger = logging.getLogger(__name__) SCHEMA_VERSION = vol.Schema({vol.Optional(ATTR_VERSION): str}) +SCHEMA_ICON = vol.Schema( + { + vol.Optional(ATTR_PREFER_DARK_ICON, default=False): bool, + } +) + # pylint: disable=no-value-for-parameter SCHEMA_OPTIONS = vol.Schema( { @@ -463,6 +470,11 @@ class APIAddons(CoreSysAttributes): if not addon.with_icon: raise APIError(f"No icon found for add-on {addon.slug}!") + body = await api_validate(SCHEMA_ICON, request) + if body[ATTR_PREFER_DARK_ICON] and addon.path_dark_icon.exists(): + with addon.path_dark_icon.open("rb") as png: + return png.read() + with addon.path_icon.open("rb") as png: return png.read() diff --git a/supervisor/const.py b/supervisor/const.py index 3c35e2b87..c7ce63ecb 100644 --- a/supervisor/const.py +++ b/supervisor/const.py @@ -255,6 +255,7 @@ ATTR_PASSWORD = "password" ATTR_PORT = "port" ATTR_PORTS = "ports" ATTR_PORTS_DESCRIPTION = "ports_description" +ATTR_PREFER_DARK_ICON = "prefer_dark_icon" ATTR_PREFIX = "prefix" ATTR_PRIMARY = "primary" ATTR_PRIORITY = "priority"