From 5f8fbbab1e42a717fb04a588e642e3dab7134e48 Mon Sep 17 00:00:00 2001 From: AbsentData Date: Mon, 2 Jun 2025 18:41:46 -0400 Subject: [PATCH 1/5] feat: add color to safety car --- dash/src/app/dashboard/settings/page.tsx | 5 +++++ dash/src/components/dashboard/Map.tsx | 13 +++++++++++-- dash/src/stores/useSettingsStore.ts | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/dash/src/app/dashboard/settings/page.tsx b/dash/src/app/dashboard/settings/page.tsx index f9d263f4..76334ea6 100644 --- a/dash/src/app/dashboard/settings/page.tsx +++ b/dash/src/app/dashboard/settings/page.tsx @@ -52,6 +52,11 @@ export default function SettingsPage() {

OLED Mode (Pure Black Background)

+
+ settings.setUseSafetyCarColors(v)} /> +

Use Safety Car Colors

+
+

Race Control

diff --git a/dash/src/components/dashboard/Map.tsx b/dash/src/components/dashboard/Map.tsx index d882b738..a1befbd8 100644 --- a/dash/src/components/dashboard/Map.tsx +++ b/dash/src/components/dashboard/Map.tsx @@ -174,32 +174,38 @@ export default function Map() { {centerX && centerY && positions && drivers && ( <> {positions["241"] && positions["241"].Z !== 0 && ( + // Aston Martin )} {positions["242"] && positions["242"].Z !== 0 && ( + // Aston Martin )} {positions["243"] && positions["243"].Z !== 0 && ( + // Mercedes )} @@ -307,9 +313,12 @@ type SafetyCarProps = { rotation: number; centerX: number; centerY: number; + color: string; }; -const SafetyCar = ({ pos, rotation, centerX, centerY }: SafetyCarProps) => { +const SafetyCar = ({ pos, rotation, centerX, centerY, color }: SafetyCarProps) => { + const useSafetyCarColors = useSettingsStore((state) => state.useSafetyCarColors); + return ( { favoriteDriver={false} pit={false} hidden={false} - color={undefined} + color={useSafetyCarColors ? color : "DDD"} /> ); }; diff --git a/dash/src/stores/useSettingsStore.ts b/dash/src/stores/useSettingsStore.ts index 133b6c02..205ef708 100644 --- a/dash/src/stores/useSettingsStore.ts +++ b/dash/src/stores/useSettingsStore.ts @@ -28,6 +28,9 @@ type SettingsStore = { oledMode: boolean; setOledMode: (oledMode: boolean) => void; + useSafetyCarColors: boolean; + setUseSafetyCarColors: (useSafetyCarColors: boolean) => void; + favoriteDrivers: string[]; setFavoriteDrivers: (favoriteDrivers: string[]) => void; removeFavoriteDriver: (driver: string) => void; @@ -70,6 +73,9 @@ export const useSettingsStore = create()( oledMode: false, setOledMode: (oledMode: boolean) => set({ oledMode }), + useSafetyCarColors: false, + setUseSafetyCarColors: (useSafetyCarColors: boolean) => set({ useSafetyCarColors }), + favoriteDrivers: [], setFavoriteDrivers: (favoriteDrivers: string[]) => set({ favoriteDrivers }), removeFavoriteDriver: (driver: string) => From 5b5109ea2d0096c8efd52394bb13f67f9cff9645 Mon Sep 17 00:00:00 2001 From: slowlydev Date: Thu, 5 Jun 2025 08:46:22 +0200 Subject: [PATCH 2/5] chore: by default show SC colors --- dash/src/stores/useSettingsStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/src/stores/useSettingsStore.ts b/dash/src/stores/useSettingsStore.ts index 205ef708..dee5f5a4 100644 --- a/dash/src/stores/useSettingsStore.ts +++ b/dash/src/stores/useSettingsStore.ts @@ -73,7 +73,7 @@ export const useSettingsStore = create()( oledMode: false, setOledMode: (oledMode: boolean) => set({ oledMode }), - useSafetyCarColors: false, + useSafetyCarColors: true, setUseSafetyCarColors: (useSafetyCarColors: boolean) => set({ useSafetyCarColors }), favoriteDrivers: [], From 29a780dd372fbf12452dfbb16c2ab90e8bc33e00 Mon Sep 17 00:00:00 2001 From: Blize <90607489+Blize@users.noreply.github.com> Date: Thu, 5 Jun 2025 10:32:15 +0200 Subject: [PATCH 3/5] feat(Map.tsx): add finishLine to track map --- dash/src/components/dashboard/Map.tsx | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/dash/src/components/dashboard/Map.tsx b/dash/src/components/dashboard/Map.tsx index d882b738..f57ef247 100644 --- a/dash/src/components/dashboard/Map.tsx +++ b/dash/src/components/dashboard/Map.tsx @@ -49,6 +49,7 @@ export default function Map() { const [sectors, setSectors] = useState([]); const [corners, setCorners] = useState([]); const [rotation, setRotation] = useState(0); + const [finishLine, setFinishLine] = useState(null); useEffect(() => { (async () => { @@ -91,12 +92,19 @@ export default function Map() { const cWidthX = Math.max(...pointsX) - cMinX + SPACE * 2; const cWidthY = Math.max(...pointsY) - cMinY + SPACE * 2; + const rotatedFinishLine = rotate(mapJson.x[0], mapJson.y[0], fixedRotation, centerX, centerY); + + const dx = rotatedPoints[3].x - rotatedPoints[0].x; + const dy = rotatedPoints[3].y - rotatedPoints[0].y; + const startAngle = Math.atan2(dy, dx) * (180 / Math.PI); + setCenter([centerX, centerY]); setBounds([cMinX, cMinY, cWidthX, cWidthY]); setSectors(sectors); setPoints(rotatedPoints); setRotation(fixedRotation); setCorners(cornerPositions); + setFinishLine({ x: rotatedFinishLine.x, y: rotatedFinishLine.y, startAngle }); })(); }, [circuitKey]); @@ -161,6 +169,19 @@ export default function Map() { ); })} + {finishLine && ( + + )} + {showCornerNumbers && corners.map((corner) => ( Date: Sat, 14 Jun 2025 00:30:20 +0200 Subject: [PATCH 4/5] fix: add timeouts to trigger more restarts of the manager --- crates/client/src/client.rs | 20 ++++++++++++++++++-- crates/client/src/manager.rs | 31 +++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/crates/client/src/client.rs b/crates/client/src/client.rs index 58608c30..ea4135e2 100644 --- a/crates/client/src/client.rs +++ b/crates/client/src/client.rs @@ -1,3 +1,4 @@ +use std::time::Duration; use std::{env, error::Error}; use axum::http::HeaderValue; @@ -6,6 +7,7 @@ use futures::SinkExt; use reqwest::{header, Url}; use serde_json::Value; +use tokio::time::timeout; use tokio_stream::{Stream, StreamExt}; use tokio_tungstenite::tungstenite::client::IntoClientRequest; use tokio_tungstenite::{tungstenite::http::Request, MaybeTlsStream, WebSocketStream}; @@ -39,7 +41,17 @@ pub async fn init() -> Result> { debug!(?req, "created request"); - let (mut socket, _) = tokio_tungstenite::connect_async(req).await?; + let connect_result = timeout( + Duration::from_secs(10), + tokio_tungstenite::connect_async(req), + ) + .await; + + let (mut socket, _) = match connect_result { + Ok(Ok(res)) => res, + Ok(Err(e)) => return Err(Box::new(e)), + Err(_) => return Err("ws connect timed out".into()), + }; info!("connected"); @@ -113,7 +125,11 @@ async fn negotiate() -> Result> { ], )?; - let res = reqwest::get(url).await?; + let res = match timeout(Duration::from_secs(5), reqwest::get(url)).await { + Ok(Ok(r)) => r, + Ok(Err(e)) => return Err(Box::new(e)), + Err(_) => return Err("negotiation HTTP request timed out".into()), + }; // TODO refactor this let headers = res.headers().clone(); diff --git a/crates/client/src/manager.rs b/crates/client/src/manager.rs index 8c90f1f9..5ec45a06 100644 --- a/crates/client/src/manager.rs +++ b/crates/client/src/manager.rs @@ -1,6 +1,9 @@ use std::time::Duration; -use tokio::{sync::mpsc, time::sleep}; +use tokio::{ + sync::mpsc, + time::{sleep, timeout}, +}; use tokio_stream::{wrappers::ReceiverStream, StreamExt}; use tracing::error; @@ -23,12 +26,28 @@ pub fn manage() -> ReceiverStream { let mut parsed_stream = parse_stream(stream).await; - while let Some(message) = parsed_stream.next().await { - if check_restart(&message) { - continue 'manage; - } + loop { + let res = timeout(Duration::from_secs(30), parsed_stream.next()).await; - let _ = tx.send(message).await; + match res { + Ok(Some(message)) => { + if check_restart(&message) { + continue 'manage; + } + let _ = tx.send(message).await; + } + Ok(None) => { + error!("stream ended unexpectedly, restarting client"); + continue 'manage; + } + Err(err) => { + error!( + ?err, + "timeout while waiting for next message, restarting client" + ); + continue 'manage; + } + } } } }); From 887e45a44cf9015d312b33b823cd1396dc57dd69 Mon Sep 17 00:00:00 2001 From: Slowlydev Date: Sat, 14 Jun 2025 18:10:17 +0200 Subject: [PATCH 5/5] chore: bump version --- dash/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/package.json b/dash/package.json index fadb50c6..0912481d 100644 --- a/dash/package.json +++ b/dash/package.json @@ -1,6 +1,6 @@ { "name": "f1-dash", - "version": "3.1.1", + "version": "3.2.0", "private": true, "scripts": { "build": "next build",