(scanId)
| 19239 | try { |
| 19240 | let data; |
| 19241 | if (action === 'start') { |
| 19242 | data = await startOrchestrator(); |
| 19243 | } else { |
| 19244 | data = await stopOrchestrator(); |
| 19245 | } |
| 19246 | |
| 19247 | // Use the actual server-reported state instead of assuming success |
| 19248 | const actualEnabled = data && data.success ? Boolean(data.automation_enabled) : !targetStateEnabled; |
| 19249 | updateAutomationToggleButton(actualEnabled, { force: true }); |
| 19250 | |
| 19251 | refreshDashboard().catch(() => {/* best effort */}); |
| 19252 | } catch (error) { |
| 19253 | console.error('Automation toggle failed:', error); |
| 19254 | addConsoleMessage('Failed to toggle automation', 'error'); |
| 19255 | updateAutomationToggleButton(!targetStateEnabled, { force: true }); |
| 19256 | } finally { |
| 19257 | button.dataset.busy = 'false'; |
| 19258 | button.disabled = false; |
| 19259 | button.classList.remove('opacity-70'); |
| 19260 | |
| 19261 | if (button.dataset.pendingState) { |
| 19262 | const pendingEnabled = button.dataset.pendingState === 'enabled'; |
| 19263 | delete button.dataset.pendingState; |
| 19264 | updateAutomationToggleButton(pendingEnabled, { force: true }); |
| 19265 | } |
| 19266 | } |
| 19267 | } |
| 19268 | |
| 19269 | function updateElement(id, value) { |
no test coverage detected