From 1c7184378c1a71e90063832fafc5055aabbb3ef5 Mon Sep 17 00:00:00 2001 From: Maxim Date: Tue, 17 Sep 2024 23:12:43 +0500 Subject: [PATCH] Add forceVisualConfig --- docs/frontend-tricks.md | 7 +++++++ src/frontend/overlay/package.json | 2 +- src/frontend/overlay/src/config.ts | 7 +++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/frontend-tricks.md b/docs/frontend-tricks.md index b59e4a444..d96dc2669 100644 --- a/docs/frontend-tricks.md +++ b/docs/frontend-tricks.md @@ -9,3 +9,10 @@ Examples: - `https://host/overlay?forceWidgets=[{"type":"ScoreboardWidget","widgetId":"scoreboard","location":{"positionX":16,"positionY":16,"sizeX":1488,"sizeY":984},"settings":{"isInfinite":true,"startFromRow":1,"optimismLevel":"normal","group":"all"}}]` + +## forceVisualConfig + +You can pass forces visual config using the forceVisualConfig + +Examples: +- `http://host/overelay?forceVisualConfig=` diff --git a/src/frontend/overlay/package.json b/src/frontend/overlay/package.json index 091a6f558..e2e7c799c 100644 --- a/src/frontend/overlay/package.json +++ b/src/frontend/overlay/package.json @@ -37,7 +37,7 @@ "web-vitals": "^1.1.2" }, "scripts": { - "start": "vite", + "start": "VITE_WEBSOCKET_URL=ws://localhost:8080/api/overlay vite", "build": "vite build", "lint:css": "stylelint -f verbose './src/**/*.{js,jsx,ts,tsx,css,scss}'", "lint:js": "eslint \"**/*.{js,jsx,ts,tsx}\"", diff --git a/src/frontend/overlay/src/config.ts b/src/frontend/overlay/src/config.ts index 014a8d0a0..e0a7a7a2c 100644 --- a/src/frontend/overlay/src/config.ts +++ b/src/frontend/overlay/src/config.ts @@ -7,6 +7,9 @@ const WS_PROTO = window.location.protocol === "https:" ? "wss://" : "ws://"; const WS_PORT = import.meta.env.VITE_WEBSOCKET_PORT ?? window.location.port; const VISUAL_CONFIG_URL = import.meta.env.VITE_VISUAL_CONFIG_URL ?? `${window.location.protocol}//${window.location.hostname}:${WS_PORT}/api/overlay/visualConfig.json`; +const urlParams = new URLSearchParams(window.location.search); +const queryVisualConfig = JSON.parse(urlParams.get("forceVisualConfig") ?? "{}"); + const visualConfig = await fetch(VISUAL_CONFIG_URL) .then(r => r.json()) .catch((e) => console.error("failed to load visual config: " + e)) ?? {}; @@ -17,10 +20,10 @@ const config_: typeof config = {}; // eslint-disable-next-line @typescript-eslint/no-explicit-any const config: Record = new Proxy(config_, { get(target, key) { - return visualConfig[key] ?? target[key as string]; + return queryVisualConfig[key] ?? visualConfig[key] ?? target[key as string]; }, set(target, key, value) { - target[key as string] = visualConfig[key] ?? value; + target[key as string] = queryVisualConfig[key] ?? visualConfig[key] ?? value; return true; } });