From b49412a800b17aaecb8a7bbf913281c81cdc0bc3 Mon Sep 17 00:00:00 2001 From: Jage9 Date: Mon, 9 Mar 2026 01:39:30 -0400 Subject: [PATCH] Load grid branding before connect --- client/public/version.js | 2 +- client/src/main.ts | 20 ++++++++++++++++++++ deploy/README.md | 1 + deploy/scripts/deploy_client.sh | 28 ++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/client/public/version.js b/client/public/version.js index de19643..1207c09 100644 --- a/client/public/version.js +++ b/client/public/version.js @@ -1,6 +1,6 @@ // Maintainer-controlled web client version metadata. window.CHGRID_RELEASE_VERSION = "0.1.0"; -window.CHGRID_BUILD_REVISION = "R347"; +window.CHGRID_BUILD_REVISION = "R348"; window.CHGRID_WEB_VERSION = `${window.CHGRID_RELEASE_VERSION} ${window.CHGRID_BUILD_REVISION}`; // Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid. window.CHGRID_TIME_ZONE = "America/Detroit"; diff --git a/client/src/main.ts b/client/src/main.ts index 95ee5e6..3dc14e3 100644 --- a/client/src/main.ts +++ b/client/src/main.ts @@ -366,6 +366,7 @@ loadMasterVolume(); void loadHelp(); void itemBehaviorRegistry.initialize(); void loadChangelog(); +void loadClientBranding(); function applyGridBranding(gridName: string | null | undefined, welcomeMessage: string | null | undefined): void { const nextGridName = String(gridName ?? '').trim() || DEFAULT_GRID_NAME; @@ -378,6 +379,25 @@ function applyGridBranding(gridName: string | null | undefined, welcomeMessage: dom.canvas.setAttribute('aria-label', `${nextGridName}, press question mark for help.`); } +async function loadClientBranding(): Promise { + try { + const response = await fetch(withBase('client_branding.json'), { cache: 'no-store' }); + if (!response.ok) { + return; + } + const data = (await response.json()) as { gridName?: unknown; welcomeMessage?: unknown }; + applyGridBranding( + typeof data.gridName === 'string' ? data.gridName : null, + typeof data.welcomeMessage === 'string' ? data.welcomeMessage : null, + ); + if (!state.running && !isVersionReloadedSession()) { + setConnectionStatus(activeWelcomeMessage); + } + } catch { + // Branding falls back to built-in defaults when deploy-time branding is unavailable. + } +} + /** Fetches a required DOM element and casts it to the requested element type. */ function requiredById(id: string): T { const found = document.getElementById(id); diff --git a/deploy/README.md b/deploy/README.md index f29eb07..eba9dfd 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -49,6 +49,7 @@ cd "$REPO_ROOT" Optional 4th arg: - server config path used when generating `media_proxy.config.php` - use this for secondary grids that do not use `server/config.toml` +- the same config is also used to generate `client_branding.json` for pre-login client branding ## 4) Install/Reload Service Unit diff --git a/deploy/scripts/deploy_client.sh b/deploy/scripts/deploy_client.sh index 55f1079..4424562 100755 --- a/deploy/scripts/deploy_client.sh +++ b/deploy/scripts/deploy_client.sh @@ -45,6 +45,32 @@ if [[ -n "${CHGRID_HOST_ORIGIN:-}" ]]; then if [[ -x "$SERVER_VENV_PYTHON" ]]; then config_python="$SERVER_VENV_PYTHON" fi + branding_json="$( + "$config_python" - "$SERVER_CONFIG_PATH" <<'PY' +from pathlib import Path +import json +import sys + +try: + import tomllib +except ModuleNotFoundError: # pragma: no cover - compatibility fallback + import tomli as tomllib + +config_path = Path(sys.argv[1]) +grid_name = "Chat Grid" +welcome_message = ( + "Welcome to the Chat Grid, your immersive audio playground. " + "Configure your audio, then Log in or register to join the grid." +) +if config_path.exists(): + with config_path.open("rb") as fp: + data = tomllib.load(fp) + server = data.get("server", {}) + grid_name = str(server.get("grid_name", grid_name)).strip() or grid_name + welcome_message = str(server.get("welcome_message", welcome_message)).strip() or welcome_message +print(json.dumps({"gridName": grid_name, "welcomeMessage": welcome_message})) +PY + )" session_check_url="$( "$config_python" - "$SERVER_CONFIG_PATH" <<'PY' from pathlib import Path @@ -83,6 +109,7 @@ PY escaped_host_origin=${escaped_host_origin//\'/\\\'} escaped_session_check_url=${session_check_url//\\/\\\\} escaped_session_check_url=${escaped_session_check_url//\'/\\\'} + printf '%s\n' "$branding_json" > "$PUBLISH_DIR/client_branding.json" cat > "$PUBLISH_DIR/media_proxy.config.php" <