logo as well

This commit is contained in:
Ludeeus 2022-06-10 07:21:53 +00:00
parent 0073660bdf
commit 20a6c53c2d
3 changed files with 16 additions and 6 deletions

View File

@ -553,6 +553,11 @@ class AddonModel(CoreSysAttributes, ABC):
"""Return path to add-on logo."""
return Path(self.path_location, "logo.png")
@property
def path_dark_logo(self) -> Path:
"""Return path to the dark variant of the add-on logo."""
return Path(self.path_location, "dark_logo.png")
@property
def path_changelog(self) -> Path:
"""Return path to add-on changelog."""

View File

@ -69,7 +69,7 @@ from ..const import (
ATTR_NETWORK_RX,
ATTR_NETWORK_TX,
ATTR_OPTIONS,
ATTR_PREFER_DARK_ICON,
ATTR_PREFER_DARK,
ATTR_PRIVILEGED,
ATTR_PROTECTED,
ATTR_PWNED,
@ -114,9 +114,9 @@ _LOGGER: logging.Logger = logging.getLogger(__name__)
SCHEMA_VERSION = vol.Schema({vol.Optional(ATTR_VERSION): str})
SCHEMA_ICON = vol.Schema(
SCHEMA_DARK = vol.Schema(
{
vol.Optional(ATTR_PREFER_DARK_ICON, default=False): bool,
vol.Optional(ATTR_PREFER_DARK, default=False): bool,
}
)
@ -470,8 +470,8 @@ 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():
body = await api_validate(SCHEMA_DARK, request)
if body[ATTR_PREFER_DARK] and addon.path_dark_icon.exists():
with addon.path_dark_icon.open("rb") as png:
return png.read()
@ -485,6 +485,11 @@ class APIAddons(CoreSysAttributes):
if not addon.with_logo:
raise APIError(f"No logo found for add-on {addon.slug}!")
body = await api_validate(SCHEMA_DARK, request)
if body[ATTR_PREFER_DARK] and addon.path_dark_logo.exists():
with addon.path_dark_logo.open("rb") as png:
return png.read()
with addon.path_logo.open("rb") as png:
return png.read()

View File

@ -255,7 +255,7 @@ ATTR_PASSWORD = "password"
ATTR_PORT = "port"
ATTR_PORTS = "ports"
ATTR_PORTS_DESCRIPTION = "ports_description"
ATTR_PREFER_DARK_ICON = "prefer_dark_icon"
ATTR_PREFER_DARK = "prefer_dark_icon"
ATTR_PREFIX = "prefix"
ATTR_PRIMARY = "primary"
ATTR_PRIORITY = "priority"