diff --git a/daemon.py b/daemon.py index e035d2860..649cf4335 100644 --- a/daemon.py +++ b/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,24 +6879,10 @@ class PubServer(BaseHTTPRequestHandler): getreq_start_time) -> None: """gets the PWA manifest """ - pwa_theme_color = 'grey' - pwa_theme_background_color = 'black' - 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() - 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_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 = \ diff --git a/epicyon-profile.css b/epicyon-profile.css index 7f87a1329..c6463cb9a 100644 --- a/epicyon-profile.css +++ b/epicyon-profile.css @@ -1,7 +1,7 @@ @charset "UTF-8"; :root { - --pwa-theme-color: apple-mobile-statusbar-color; + --pwa-theme-color: apple-mobile-web-app-status-bar-style; --pwa-theme-background-color: black-translucent; --avatar-rounding: 10%; --timeline-icon-width: 50px; diff --git a/theme.py b/theme.py index a80a12e0b..52000e0c2 100644 --- a/theme.py +++ b/theme.py @@ -16,6 +16,7 @@ from utils import copytree from utils import acct_dir from utils import dangerous_svg from utils import local_actor_url +from utils import remove_html from shutil import copyfile from shutil import make_archive from shutil import unpack_archive @@ -272,6 +273,7 @@ def _remove_theme(base_dir: str): def set_css_param(css: str, param: str, value: str) -> str: """Sets a CSS parameter to a given value """ + value = remove_html(value) # is this just a simple string replacement? if ';' in param: return css.replace(param, value) diff --git a/theme/blue/theme.json b/theme/blue/theme.json index f48cf7ace..5002e9e62 100644 --- a/theme/blue/theme.json +++ b/theme/blue/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "newswire-publish-icon": "True", "full-width-timeline-buttons": "False", diff --git a/theme/debian/theme.json b/theme/debian/theme.json index 3dddacb11..6455abd19 100644 --- a/theme/debian/theme.json +++ b/theme/debian/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "#222", "dropdown-bg-color": "white", diff --git a/theme/hacker/theme.json b/theme/hacker/theme.json index c6e048b45..aae604cee 100644 --- a/theme/hacker/theme.json +++ b/theme/hacker/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "#9ad791", "dropdown-bg-color": "#222", diff --git a/theme/henge/theme.json b/theme/henge/theme.json index 8b55b24f5..98c3ee28e 100644 --- a/theme/henge/theme.json +++ b/theme/henge/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "white", "dropdown-bg-color": "#483335", diff --git a/theme/indymediaclassic/theme.json b/theme/indymediaclassic/theme.json index 35cbc3e89..104abcbeb 100644 --- a/theme/indymediaclassic/theme.json +++ b/theme/indymediaclassic/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "white", "dropdown-bg-color": "#222", diff --git a/theme/indymediamodern/theme.json b/theme/indymediamodern/theme.json index 19468eeff..eb8434688 100644 --- a/theme/indymediamodern/theme.json +++ b/theme/indymediamodern/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "black", "dropdown-bg-color": "#dedede", diff --git a/theme/lcd/theme.json b/theme/lcd/theme.json index 5104a5a1a..cb4693d32 100644 --- a/theme/lcd/theme.json +++ b/theme/lcd/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "#33390d", "dropdown-bg-color": "#9fb42b", diff --git a/theme/light/theme.json b/theme/light/theme.json index cd67f7f56..7fdcecec1 100644 --- a/theme/light/theme.json +++ b/theme/light/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "#2d2c37", "dropdown-bg-color": "#d6dbf0", diff --git a/theme/night/theme.json b/theme/night/theme.json index 3180453ea..d7d6b2867 100644 --- a/theme/night/theme.json +++ b/theme/night/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "#0481f5", "dropdown-bg-color": "#0d0d10", diff --git a/theme/pixel/theme.json b/theme/pixel/theme.json index 93c8664ec..4e12d68ff 100644 --- a/theme/pixel/theme.json +++ b/theme/pixel/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "black", "dropdown-bg-color": "#aba0d4", diff --git a/theme/purple/theme.json b/theme/purple/theme.json index 1b1037ee3..5d2fc3ce4 100644 --- a/theme/purple/theme.json +++ b/theme/purple/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "#f98bb0", "dropdown-bg-color": "#2f152d", diff --git a/theme/rc3/theme.json b/theme/rc3/theme.json index 2c23e7597..b334a4944 100644 --- a/theme/rc3/theme.json +++ b/theme/rc3/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "white", "dropdown-bg-color": "#002a3a", diff --git a/theme/solidaric/theme.json b/theme/solidaric/theme.json index 6a94546bb..70eabbac2 100644 --- a/theme/solidaric/theme.json +++ b/theme/solidaric/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "#2d2c37", "dropdown-bg-color": "#ddd", diff --git a/theme/starlight/theme.json b/theme/starlight/theme.json index 22959c723..128a61807 100644 --- a/theme/starlight/theme.json +++ b/theme/starlight/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "#ffc4bc", "dropdown-bg-color": "#1f0d10", diff --git a/theme/zen/theme.json b/theme/zen/theme.json index aef8ab9ca..8bae85a10 100644 --- a/theme/zen/theme.json +++ b/theme/zen/theme.json @@ -1,5 +1,5 @@ { - "pwa-theme-color": "apple-mobile-statusbar-color", + "pwa-theme-color": "apple-mobile-web-app-status-bar-style", "pwa-theme-background-color": "black-translucent", "dropdown-fg-color": "#d5c7b7", "dropdown-bg-color": "#4c4e41", diff --git a/webapp_utils.py b/webapp_utils.py index 3ea3d5c06..627f0eab6 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -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 = \ '\n' + \ '\n' + \ @@ -557,8 +602,10 @@ def html_header_with_external_style(css_filename: str, instance_title: str, ' \n' + \ ' \n' + \ - ' \n' + \ + ' \n' + \ metadata + \ + ' \n' + \ ' ' + instance_title + '\n' + \ ' \n' + \ ' \n'