Fix agent/local mode state sync and process cleanup

Agent fixes:
- Fix stop not killing secondary processes (pager_rtl, aprs_rtl, rtlamr_tcp)
- Modes using piped processes now properly terminate all child processes

UI state sync fixes:
- Add syncLocalModeStates() to check local status when switching to local
- Fix switchMode() to re-sync with agent/local when changing mode tabs
- Only stop local modes when actually in local mode
- UI now correctly reflects running state when switching agents or modes
This commit is contained in:
cemaxecuter
2026-01-27 09:31:14 -05:00
parent afccb6fe0a
commit a5f574062d
3 changed files with 97 additions and 7 deletions

View File

@@ -329,6 +329,8 @@ function selectAgent(agentId) {
if (typeof refreshTscmDevices === 'function') {
refreshTscmDevices();
}
// Sync mode UI to local status (reset modes that aren't running locally)
syncLocalModeStates();
// Notify WiFi mode of agent change
if (typeof WiFiMode !== 'undefined' && WiFiMode.handleAgentChange) {
WiFiMode.handleAgentChange();
@@ -413,6 +415,45 @@ async function syncAgentModeStates(agentId) {
}
}
/**
* Sync UI state with local mode statuses.
* Called when switching back to local to ensure UI reflects local state.
*/
async function syncLocalModeStates() {
console.log('[AgentManager] Syncing local mode states...');
// Check each mode's local status endpoint
const modeChecks = [
{ mode: 'pager', endpoint: '/status', runningKey: 'running' },
{ mode: 'sensor', endpoint: '/sensor/status', runningKey: 'running' },
{ mode: 'adsb', endpoint: '/adsb/status', runningKey: 'running' },
{ mode: 'tscm', endpoint: '/tscm/status', runningKey: 'running' },
];
for (const check of modeChecks) {
try {
const response = await fetch(check.endpoint);
if (response.ok) {
const data = await response.json();
const isRunning = data[check.runningKey] || false;
syncModeUI(check.mode, isRunning, null);
} else {
// Endpoint not available or error - assume not running
syncModeUI(check.mode, false, null);
}
} catch (error) {
// Network error or endpoint doesn't exist - assume not running
syncModeUI(check.mode, false, null);
}
}
// Clear agent mode warnings when switching to local
const warning = document.getElementById('agentModeWarning');
if (warning) {
warning.style.display = 'none';
}
}
/**
* Show warnings about running modes that may cause conflicts.
* @param {string[]} runningModes - List of running mode names