From dfec8f2e8a7a63e617f34097e61972303a30577b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Tue, 13 Aug 2019 22:44:48 +0200 Subject: [PATCH] Initial commit. --- .gitignore | 1 + README.md | 47 +++++++++++++++++++++++ custom_components/favicon/__init__.py | 50 +++++++++++++++++++++++++ custom_components/favicon/manifest.json | 8 ++++ 4 files changed, 106 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 custom_components/favicon/__init__.py create mode 100644 custom_components/favicon/manifest.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..61f2dc9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/__pycache__/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..044092a --- /dev/null +++ b/README.md @@ -0,0 +1,47 @@ +favicon +======= + +Change the favicon and app icons of your Home Assistant instance + +![browser](https://user-images.githubusercontent.com/1299821/62975860-ad283a80-be1b-11e9-836a-d58a1732fb21.png) + +# Installation instructions + +- Copy the contents of `custom_components/favicon/` to `/custom_components/favicon/`. + +- Get some icons + + There are some nice ones available [here](https://github.com/home-assistant/home-assistant-assets/tree/master/Alternates), and you can generate favicons from them using an online tool, such as [this one](https://realfavicongenerator.net/). + +- Put your icons in e.g. `/www/favicons/` + +- Add the following to your `configuration.yaml`: + +```yaml +favicon: + favicon: /local/favicons/favicon.ico + apple: /local/favicons/apple-touch-icon-180x180.png + 32: /local/favicons/favicon-32x32.png + 512: /local/favicons/android-chrome-512x512.png +``` + +- Restart Home Assistant + +- Make sure to clear the cache of your browser to get the new icons. + +# Options + +- `favicon` - an .ico file which is displayed in your browser tab or bookmark menu. + +- `apple` - a 180 x 180 px image that will be displayed on your iDevice home screen if you save the link there + +- `` - a `` x `` px image that will be displayed wherever it's needed for non-apple devices. + +You can add as few or as many of those you'd like. It's my understanding that the next smaller size will be used if one is requested which doesn't quite fit the need. + +For reference, Home Assistant includes icons of sizes 192, 384, 512 and 1024 px square by default. Specifying even a single size will override all of those. + +![iphone](https://user-images.githubusercontent.com/1299821/62975899-c29d6480-be1b-11e9-9b6b-9d160ef8b439.jpg) + +--- +Buy Me A Coffee diff --git a/custom_components/favicon/__init__.py b/custom_components/favicon/__init__.py new file mode 100644 index 0000000..85b1ec7 --- /dev/null +++ b/custom_components/favicon/__init__.py @@ -0,0 +1,50 @@ +import logging + +import homeassistant.components.frontend +from homeassistant.components.frontend import _frontend_root + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = "favicon" + +async def async_setup(hass, config): + + favicon = config[DOMAIN].get('favicon') + apple = config[DOMAIN].get('apple') + + if favicon or apple: + get_template = homeassistant.components.frontend.IndexView.get_template + + def new_get_template(self): + tpl = get_template(self) + render = tpl.render + def new_render(*args, **kwargs): + text = render(*args, **kwargs) + if favicon: + text = text.replace("/static/icons/favicon.ico", favicon) + if apple: + text = text.replace("/static/icons/favicon-apple-180x180.png", apple) + return text + tpl.render = new_render + return tpl + + homeassistant.components.frontend.IndexView.get_template = new_get_template + + icons = [] + for size in config[DOMAIN]: + if not isinstance(size, int): + continue + i = config[DOMAIN].get(size) + if i: + icons.append({ + "src": i, + "sizes": f"{size}x{size}", + "type": "image/png", + }) + + if icons: + homeassistant.components.frontend.MANIFEST_JSON["icons"] = icons + + return True + + diff --git a/custom_components/favicon/manifest.json b/custom_components/favicon/manifest.json new file mode 100644 index 0000000..897b953 --- /dev/null +++ b/custom_components/favicon/manifest.json @@ -0,0 +1,8 @@ +{ + "domain": "favicon", + "name": "Favicon changer", + "documentation": "", + "dependencies": ["frontend"], + "codeowners": [], + "requirements": [] +}