A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol
C arduinobluetoothcan-busdebuggingeepromesp32flipperzerogpiohardware-hackingi2cjtagopenocdprotocolspwmradiorfidspisubghzuartwifi
add connection lost popup, improve command history for web cli
Geofd28ed20147b
diff --git a/src/Services/InfraredService.cpp b/src/Services/InfraredService.cppindex be8d680f..8a9200b9 100644--- a/src/Services/InfraredService.cpp+++ b/src/Services/InfraredService.cpp@@ -15,12 +15,10 @@ void InfraredService::stopReceiver() {}void InfraredService::sendInfraredCommand(InfraredCommand command) {- uint8_t subdevice;- uint16_t address;uint16_t vendorCode;std::string protocolString = InfraredProtocolMapper::toString(command.getProtocol());- uint8_t subdevice = command.getSubdevice() == -1 ? 0 : command.getSubdevice();uint8_t device = command.getDevice();+ uint8_t subdevice = command.getSubdevice() == -1 ? 0 : command.getSubdevice();// Combine device and subdevice into a 16-bit integeruint16_t address = (static_cast<uint16_t>(subdevice) << 8) | device;diff --git a/src/main.cpp b/src/main.cppindex 2fb596a8..94f28c64 100644--- a/src/main.cpp+++ b/src/main.cpp@@ -94,7 +94,7 @@ void setup() {WebTerminalView webView(wsServer);WebTerminalInput webInput(wsServer);deviceView.loading();- delay(3000); // let the server begin+ delay(5000); // let the server begin// Setup routes for index and wshttpServer.setupRoutes();diff --git a/webui/index.h b/webui/index.hindex 11a066ba..19fcc8e8 100644--- a/webui/index.h+++ b/webui/index.h@@ -19,6 +19,9 @@ inline const char* index_html = R"rawliteral(<h3 id="history-title" style="display: none;">Command History</h3><div id="history" class="history-area"></div></main>+ <div id="ws-lost-popup" class="popup" style="display: none;">+ Connection lost. <a href="#" onclick="location.reload()">Refresh</a>+ </div><script src="/scripts.js"></script></body></html>diff --git a/webui/scripts.h b/webui/scripts.hindex cda7b68b..167a8f5f 100644--- a/webui/scripts.h+++ b/webui/scripts.h@@ -5,18 +5,26 @@ inline const char* scripts_js = R"rawliteral(let socket = null;let pendingEchoLines = 0;let reconnectInterval = 1000; // ms+let responseTimeout = null;+let responseTimeoutDelay = 6000; // msfunction connectSocket() {socket = new WebSocket("ws://" + window.location.host + "/ws");socket.onopen = function () {+ hideWsLostPopup(); // Supprime le popupconsole.log("[WebSocket] Connected");};socket.onmessage = function (event) {+const output = document.getElementById("output");const lines = event.data.split("\n");+ // Clear response timeout+ clearTimeout(responseTimeout);+ hideWsLostPopup();+if (pendingEchoLines > 0) {pendingEchoLines -= 1;return;@@ -33,15 +41,37 @@ function connectSocket() {socket.onclose = function () {console.warn("[WebSocket] Disconnected. Retrying in 1s...");+ showWsLostPopup(); // Affiche le popupsetTimeout(connectSocket, reconnectInterval);};}+function showWsLostPopup() {+ const popup = document.getElementById("ws-lost-popup");+ if (popup) {+ popup.style.display = "block";+ }+}++function hideWsLostPopup() {+ const popup = document.getElementById("ws-lost-popup");+ if (popup) {+ popup.style.display = "none";+ }+}+function sendCommand() {const input = document.getElementById("command");const output = document.getElementById("output");const cmd = input.value.trim();+ // Timeout for response+ clearTimeout(responseTimeout);+ responseTimeout = setTimeout(() => {+ console.warn("[WebSocket] No response after command.");+ showWsLostPopup();+ }, responseTimeoutDelay);+if (socket.readyState !== WebSocket.OPEN) return;socket.send(cmd + "\n");@@ -92,7 +122,13 @@ function addToHistory(cmd) {if (last && last.textContent === cmd) return;const btn = document.createElement("button");- btn.textContent = cmd;++ // Limiter l'affichage du texte à 15 caractères+ const maxLength = 15;+ const displayText = cmd.length > maxLength ? cmd.slice(0, maxLength - 3) + "..." : cmd;++ btn.textContent = displayText;+ btn.title = cmd; // Tooltip complet au survolbtn.onclick = () => {document.getElementById("command").value = cmd;document.getElementById("command").focus();diff --git a/webui/style.h b/webui/style.hindex 624526ae..30580d77 100644--- a/webui/style.h+++ b/webui/style.h@@ -134,11 +134,23 @@ button:hover {min-width: 0;-webkit-overflow-scrolling: touch;}-.history-area::-webkit-scrollbar {width: 0;height: 0;}+.history-area button:hover {+ background: #2a2a2a;+}+.history-area::-webkit-scrollbar {+ height: 6px;+}+.history-area::-webkit-scrollbar-thumb {+ background-color: #444;+ border-radius: 4px;+}+.history-area::-webkit-scrollbar-track {+ background-color: #222;+}.history-area button {flex: 0 0 auto;@@ -150,20 +162,31 @@ button:hover {font-size: 0.85em;transition: background 0.2s ease;}-.history-area button:hover {- background: #2a2a2a;-}-.history-area::-webkit-scrollbar {- height: 6px;++.popup {+ position: fixed;+ top: 50%;+ left: 50%;+ transform: translate(-50%, -50%);+ background: #222;+ color: #ff5555;+ padding: 12px 18px;+ border: 1px solid #444;+ border-radius: 8px;+ box-shadow: 0 0 8px #000;+ z-index: 9999;+ font-size: 0.95rem;}-.history-area::-webkit-scrollbar-thumb {- background-color: #444;- border-radius: 4px;+.popup a {+ color: #00ffcc;;+ text-decoration: underline;+ margin-left: 10px;}-.history-area::-webkit-scrollbar-track {- background-color: #222;+.popup a:hover {+ color: #00ffff;}+/* Responsive */@media (max-width: 600px), (max-height: 600px) {main {