From 45a330ae4625398bbda0fa173fe734bf618f48ff Mon Sep 17 00:00:00 2001 From: Jakob Pinterits Date: Fri, 27 Sep 2024 22:14:09 +0200 Subject: [PATCH] flashbang prevention prevention --- frontend/code/rpc.ts | 3 +++ frontend/index.html | 31 +++++++++++++++++++++++++------ rio/app_server/fastapi_server.py | 20 ++++++++++++++++++-- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/frontend/code/rpc.ts b/frontend/code/rpc.ts index a571eaa4..1efd7104 100644 --- a/frontend/code/rpc.ts +++ b/frontend/code/rpc.ts @@ -417,6 +417,9 @@ export async function processMessageReturnResponse( message.params.themeVariant ); + // Remove the default anti-flashbang color + document.documentElement.style.background = ""; + response = null; break; diff --git a/frontend/index.html b/frontend/index.html index 5d4b2fa7..ab40566b 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,10 +1,5 @@ - - + {title} @@ -26,4 +21,28 @@ white screen + + diff --git a/rio/app_server/fastapi_server.py b/rio/app_server/fastapi_server.py index 8b17c394..61093da1 100644 --- a/rio/app_server/fastapi_server.py +++ b/rio/app_server/fastapi_server.py @@ -483,8 +483,6 @@ class FastapiServer(fastapi.FastAPI, AbstractAppServer): # Load the template html_ = read_frontend_template("index.html") - self.app._theme.background_color - html_ = html_.replace( "{session_token}", session_token, @@ -528,6 +526,24 @@ class FastapiServer(fastapi.FastAPI, AbstractAppServer): html_base_url, ) + theme = self.app._theme + if isinstance(theme, tuple): + light_theme_background_color = theme[0].background_color + dark_theme_background_color = theme[1].background_color + else: + light_theme_background_color = theme.background_color + dark_theme_background_color = theme.background_color + + html_ = html_.replace( + "{light_theme_background_color}", + f"#{light_theme_background_color.hex}", + ) + + html_ = html_.replace( + "{dark_theme_background_color}", + f"#{dark_theme_background_color.hex}", + ) + # Since the title is user-defined, it might contain placeholders like # `{debug_mode}`. So it's important that user-defined content is # inserted last.