arm powered steam link ??

This commit is contained in:
legop3
2026-08-11 20:50:15 -04:00
parent dfd674a447
commit e5830533ba
10 changed files with 59 additions and 18 deletions
@@ -1,10 +1,13 @@
// Undocked Page Exit Guard
// Purpose: Asks the browser to confirm document-level navigation while the current driver's rover is undocked.
// Scope: Owns only the native beforeunload lifecycle; it does not render UI or attempt to replace browser safety dialogs.
// Scope: Owns the native beforeunload lifecycle and queues the matching AlertFeed explanation when leaving is attempted.
import { useEffect } from 'react';
import { useControlSelector } from '../../controls/index.js';
import { useSessionActions } from '../../context/SessionContext.jsx';
import { useTelemetrySelector } from '../../context/TelemetryContext.jsx';
const UNDOCKED_EXIT_ALERT_LIFETIME_MS = 15 * 1000;
function selectHomeBaseState(frame) {
const homeBase = frame?.sensors?.chargingSources?.homeBase;
@@ -19,6 +22,7 @@ function selectHomeBaseState(frame) {
export default function UndockedPageExitGuard() {
const roverId = useControlSelector((control) => control.state.roverId);
const homeBaseState = useTelemetrySelector(roverId, selectHomeBaseState);
const { pushAlert } = useSessionActions();
const shouldConfirmExit = Boolean(roverId) && homeBaseState === false;
useEffect(() => {
@@ -33,6 +37,18 @@ export default function UndockedPageExitGuard() {
*/
event.preventDefault();
event.returnValue = true;
/*
If the driver cancels the browser-owned confirmation, React remains
mounted and AlertFeed presents the actionable reason for the warning.
A stable id refreshes this one warning lane on another exit attempt
instead of stacking duplicate cards over the driving interface.
*/
pushAlert({
id: 'undocked-page-exit-warning',
kind: 'undocked-exit-warning',
lifetimeMs: UNDOCKED_EXIT_ALERT_LIFETIME_MS,
});
}
window.addEventListener('beforeunload', handleBeforeUnload);
@@ -44,7 +60,7 @@ export default function UndockedPageExitGuard() {
*/
window.removeEventListener('beforeunload', handleBeforeUnload);
};
}, [shouldConfirmExit]);
}, [pushAlert, shouldConfirmExit]);
return null;
}