main
Bob Mottram 2023-09-29 15:36:08 +01:00
parent 8127b6b2be
commit 690fa50bcf
2 changed files with 46 additions and 44 deletions

46
pwa.py
View File

@ -7,7 +7,51 @@ __email__ = "bob@libreserver.org"
__status__ = "Production"
__module_group__ = "Web Interface"
from webapp_utils import get_pwa_theme_colors
import os
from utils import remove_html
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', encoding='utf-8') 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 pwa_manifest(base_dir: str) -> {}:

View File

@ -45,6 +45,7 @@ from posts import is_moderator
from blocking import is_blocked
from blocking import allowed_announce
from shares import vf_proposal_from_share
from pwa import get_pwa_theme_colors
def minimizing_attached_images(base_dir: str, nickname: str, domain: str,
@ -713,49 +714,6 @@ def get_right_image_file(base_dir: str,
return _get_image_file(base_dir, 'right_col_image', account_dir, 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', encoding='utf-8') 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: