mirror of https://gitlab.com/bashrc2/epicyon
Reading pwa colors into the meta html headers
parent
08dc7d0f29
commit
1ef6b83979
32
daemon.py
32
daemon.py
|
@ -167,6 +167,7 @@ from webapp_utils import html_hashtag_blocked
|
|||
from webapp_utils import html_following_list
|
||||
from webapp_utils import set_blog_address
|
||||
from webapp_utils import html_show_share
|
||||
from webapp_utils import get_pwa_theme_colors
|
||||
from webapp_calendar import html_calendar_delete_confirm
|
||||
from webapp_calendar import html_calendar
|
||||
from webapp_about import html_about
|
||||
|
@ -6878,35 +6879,10 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
getreq_start_time) -> None:
|
||||
"""gets the PWA manifest
|
||||
"""
|
||||
default_pwa_theme_color = 'apple-mobile-web-app-status-bar-style'
|
||||
default_pwa_theme_background_color = 'black-translucent'
|
||||
pwa_theme_color = default_pwa_theme_color
|
||||
pwa_theme_background_color = default_pwa_theme_background_color
|
||||
|
||||
css_filename = base_dir + '/epicyon.css'
|
||||
if os.path.isfile(css_filename):
|
||||
css_str = ''
|
||||
with open(css_filename, 'r') as fp_css:
|
||||
css_str = fp_css.read()
|
||||
if '--pwa-theme-color:' in css_str:
|
||||
pwa_theme_color = css_str.split('--pwa-theme-color:')[1]
|
||||
if ';' in pwa_theme_color:
|
||||
pwa_theme_color = pwa_theme_color.split(';')[0].strip()
|
||||
pwa_theme_color = remove_html(pwa_theme_color)
|
||||
if ' ' in pwa_theme_color:
|
||||
pwa_theme_color = \
|
||||
default_pwa_theme_color
|
||||
if '--pwa-theme-background-color:' in css_str:
|
||||
pwa_theme_background_color = \
|
||||
css_str.split('--pwa-theme-background-color:')[1]
|
||||
if ';' in pwa_theme_background_color:
|
||||
pwa_theme_background_color = \
|
||||
pwa_theme_background_color.split(';')[0].strip()
|
||||
pwa_theme_background_color = \
|
||||
remove_html(pwa_theme_background_color)
|
||||
if ' ' in pwa_theme_background_color:
|
||||
pwa_theme_background_color = \
|
||||
default_pwa_theme_background_color
|
||||
pwa_theme_color, pwa_theme_background_color = \
|
||||
get_pwa_theme_colors(css_filename)
|
||||
|
||||
app1 = "https://f-droid.org/en/packages/eu.siacs.conversations"
|
||||
app2 = "https://staging.f-droid.org/en/packages/im.vector.app"
|
||||
app3 = \
|
||||
|
|
|
@ -538,11 +538,56 @@ def get_right_image_file(base_dir: str,
|
|||
account_dir, nickname, domain, theme)
|
||||
|
||||
|
||||
def _get_variable_from_css(css_str: str, variable: str) -> str:
|
||||
"""Gets a variable value from the css file text
|
||||
"""
|
||||
if '--' + variable + ':' not in css_str:
|
||||
return None
|
||||
value = css_str.split('--' + variable + ':')[1]
|
||||
if ';' in value:
|
||||
value = value.split(';')[0].strip()
|
||||
value = remove_html(value)
|
||||
if ' ' in value:
|
||||
value = None
|
||||
return value
|
||||
|
||||
|
||||
def get_pwa_theme_colors(css_filename: str) -> (str, str):
|
||||
"""Gets the theme/statusbar color for progressive web apps
|
||||
"""
|
||||
default_pwa_theme_color = 'apple-mobile-web-app-status-bar-style'
|
||||
pwa_theme_color = default_pwa_theme_color
|
||||
|
||||
default_pwa_theme_background_color = 'black-translucent'
|
||||
pwa_theme_background_color = default_pwa_theme_background_color
|
||||
|
||||
if not os.path.isfile(css_filename):
|
||||
return pwa_theme_color, pwa_theme_background_color
|
||||
|
||||
css_str = ''
|
||||
with open(css_filename, 'r') as fp_css:
|
||||
css_str = fp_css.read()
|
||||
|
||||
pwa_theme_color = \
|
||||
_get_variable_from_css(css_str, 'pwa-theme-color')
|
||||
if not pwa_theme_color:
|
||||
pwa_theme_color = default_pwa_theme_color
|
||||
|
||||
pwa_theme_background_color = \
|
||||
_get_variable_from_css(css_str, 'pwa-theme-background-color')
|
||||
if not pwa_theme_background_color:
|
||||
pwa_theme_background_color = default_pwa_theme_background_color
|
||||
|
||||
return pwa_theme_color, pwa_theme_background_color
|
||||
|
||||
|
||||
def html_header_with_external_style(css_filename: str, instance_title: str,
|
||||
metadata: str, lang='en') -> str:
|
||||
if metadata is None:
|
||||
metadata = ''
|
||||
css_file = '/' + css_filename.split('/')[-1]
|
||||
pwa_theme_color, pwa_theme_background_color = \
|
||||
get_pwa_theme_colors(css_filename)
|
||||
html_str = \
|
||||
'<!DOCTYPE html>\n' + \
|
||||
'<html lang="' + lang + '">\n' + \
|
||||
|
@ -557,8 +602,10 @@ def html_header_with_external_style(css_filename: str, instance_title: str,
|
|||
' <meta content="yes" name="apple-mobile-web-app-capable">\n' + \
|
||||
' <link href="/apple-touch-icon.png" rel="apple-touch-icon" ' + \
|
||||
'sizes="180x180">\n' + \
|
||||
' <meta name="theme-color" content="grey">\n' + \
|
||||
' <meta name="theme-color" content="' + pwa_theme_color + '">\n' + \
|
||||
metadata + \
|
||||
' <meta name="apple-mobile-web-app-status-bar-style" ' + \
|
||||
'content="' + pwa_theme_background_color + '">' + \
|
||||
' <title>' + instance_title + '</title>\n' + \
|
||||
' </head>\n' + \
|
||||
' <body>\n'
|
||||
|
|
Loading…
Reference in New Issue