Skip to content

Commit

Permalink
Use GitHub URL for background image (#77)
Browse files Browse the repository at this point in the history
* Use GitHub URL for background image

* Bump CI

* Make alternative theme in folder

* Type hints

* Fix /
  • Loading branch information
basnijholt authored Sep 7, 2024
1 parent a37376d commit 25ec8d3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.8, 3.12]
python-version: [3.9, 3.12]

steps:
- uses: actions/checkout@v3
Expand Down
28 changes: 18 additions & 10 deletions create-themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from pathlib import Path

import base64
import jinja2
import yaml
from PIL import Image
Expand All @@ -13,6 +12,12 @@
with open("settings-light-dark.yaml", "r") as f:
all_settings = yaml.safe_load(f)

COMMIT = "a37376d918fcfe4785be99910dc9a7200ac37da9"

BASE_URL = (
f"https://raw.githubusercontent.com/basnijholt/lovelace-ios-themes/{COMMIT}/themes"
)


def parse(x):
return x if "#" not in x else f'"{x}"'
Expand All @@ -25,11 +30,13 @@ def average_color(fname):
return "rgba({}, {}, {}, 0.4)".format(*rgb_color)


def base64_encode_file(fname):
with open(fname, 'rb') as image_file:
extension = fname.suffix.split('.')[-1]
base64_utf8_str = base64.b64encode(image_file.read()).decode('utf-8')
return f'data:image/{extension};base64,{base64_utf8_str}'
def fname_to_url(background: Path):
return f"{BASE_URL}/{background.name}"


def fname_to_local_path(folder: str, background: Path):
return f"/{folder}/themes/ios-themes/{background.name}"


BACKGROUND_COLORS = {
# Suggested by @okets in issue #42
Expand Down Expand Up @@ -58,10 +65,10 @@ def base64_encode_file(fname):
else:
app_header_background_color = average_color(background)
for which in ["light", "dark"]:
for state_icon_yellow in [False, True]:
for standard in [False, True]:
settings = {k: parse(v[which]) for k, v in all_settings.items()}

if state_icon_yellow:
if standard:
settings["state_icon_active_color"] = "rgba(255, 214, 10, 1)"
suffix = ""
else:
Expand All @@ -75,8 +82,9 @@ def base64_encode_file(fname):
folder=folder,
which=which,
app_header_background_color=app_header_background_color,
background_jpg=base64_encode_file(background),
# background_jpg=str(background.name),
background=fname_to_url(background)
if standard
else fname_to_local_path(folder, background),
color=color,
suffix=suffix,
)
Expand Down
56 changes: 28 additions & 28 deletions manual-install/ios-themes.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion template.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
ios-{{ which }}-mode-{{ color }}{{ suffix }}:
# Global
background-image: "center / cover no-repeat fixed url('{{ background_jpg }}')"
background-image: "center / cover no-repeat fixed url('{{ background }}')"
lovelace-background: var(--background-image)
primary-color: {{ primary_color }} # from Apple systemOrange {{ which }} mode
light-primary-color: {{ light_primary_color }} # (icons on left menu) (light: systemGray5 from iOS dark mode, dark: XXX)
Expand Down
56 changes: 28 additions & 28 deletions themes/ios-themes.yaml

Large diffs are not rendered by default.

0 comments on commit 25ec8d3

Please sign in to comment.