fix: ESP32 Run button auto-compiles and recovers firmware after page refresh

- handleRun now auto-compiles for ESP32/QEMU boards when no firmware is
  available (same behavior as AVR/RP2040 boards)
- startBoard now reloads compiledProgram into the bridge if _pendingFirmware
  was lost (e.g. after a page refresh between compile and run)
- Adds Esp32Bridge.hasFirmware() helper used by the store check

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
pull/90/head^2
David Montero 2026-04-01 18:47:15 +02:00
parent ba8b56c647
commit f29e964e91
3 changed files with 26 additions and 1 deletions

View File

@ -164,8 +164,22 @@ export const EditorToolbar = ({ consoleOpen, setConsoleOpen, compileLogs: _compi
const board = boards.find((b) => b.id === activeBoardId);
const isQemuBoard = board?.boardKind === 'raspberry-pi-3' || board?.boardKind === 'esp32' || board?.boardKind === 'esp32-s3';
// QEMU boards don't need compilation
// QEMU boards: auto-compile if no firmware available yet
if (isQemuBoard) {
if (!board?.compiledProgram || codeChangedSinceLastCompile) {
autoRunAfterCompile.current = true;
await handleCompile();
const updatedBoard = useSimulatorStore.getState().boards.find((b) => b.id === activeBoardId);
if (autoRunAfterCompile.current && updatedBoard?.compiledProgram) {
autoRunAfterCompile.current = false;
trackRunSimulation(updatedBoard.boardKind);
startBoard(activeBoardId);
setMessage(null);
} else {
autoRunAfterCompile.current = false;
}
return;
}
trackRunSimulation(board?.boardKind);
startBoard(activeBoardId);
setMessage(null);

View File

@ -240,6 +240,11 @@ export class Esp32Bridge {
this._pendingSensors = sensors;
}
/** Returns true if a firmware has been loaded and is ready to send. */
hasFirmware(): boolean {
return this._pendingFirmware !== null && this._pendingFirmware !== '';
}
/**
* Load a compiled firmware (base64-encoded .bin) into the running ESP32.
* If not yet connected, the firmware will be sent on next connect().

View File

@ -669,6 +669,12 @@ export const useSimulatorStore = create<SimulatorState>((set, get) => {
);
esp32Bridge.wifiEnabled = hasWifi;
// Ensure firmware is loaded into the bridge (handles page-refresh case
// where _pendingFirmware is lost but compiledProgram is still in store).
if (!esp32Bridge.hasFirmware() && board.compiledProgram) {
esp32Bridge.loadFirmware(board.compiledProgram);
}
esp32Bridge.connect();
}
} else {