Add support for dark_icon

This commit is contained in:
Ludeeus 2022-06-10 07:13:06 +00:00
parent 3b3cd61e3d
commit 0073660bdf
3 changed files with 18 additions and 0 deletions

View File

@ -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."""

View File

@ -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()

View File

@ -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"