feat: enhance update progress handling and add WebSocket closure notification
This commit is contained in:
parent
4135073623
commit
d2da501b94
@ -161,6 +161,7 @@
|
|||||||
try {
|
try {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
if (data.type === "updateProgress") {
|
if (data.type === "updateProgress") {
|
||||||
|
progressContainer.style.display = 'block';
|
||||||
progress.style.width = data.progress + '%';
|
progress.style.width = data.progress + '%';
|
||||||
progress.textContent = data.progress + '%';
|
progress.textContent = data.progress + '%';
|
||||||
}
|
}
|
||||||
@ -169,6 +170,15 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ws.onclose = function() {
|
||||||
|
// Wenn der WebSocket geschlossen wird während eines Updates, zeige eine Nachricht
|
||||||
|
if (progressContainer.style.display !== 'none' && progress.style.width !== '100%') {
|
||||||
|
status.textContent = "Connection lost. Update may still be in progress...";
|
||||||
|
status.classList.add('warning');
|
||||||
|
status.style.display = 'block';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function handleUpdate(e) {
|
function handleUpdate(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const form = e.target;
|
const form = e.target;
|
||||||
|
@ -27,6 +27,9 @@ uint8_t lastHasReadRfidTag = 0;
|
|||||||
String bambuCredentialsBackup;
|
String bambuCredentialsBackup;
|
||||||
String spoolmanUrlBackup;
|
String spoolmanUrlBackup;
|
||||||
|
|
||||||
|
// Globale Variable für den Update-Typ
|
||||||
|
static int currentUpdateCommand = 0;
|
||||||
|
|
||||||
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
void onWsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType type, void *arg, uint8_t *data, size_t len) {
|
||||||
if (type == WS_EVT_CONNECT) {
|
if (type == WS_EVT_CONNECT) {
|
||||||
Serial.println("Neuer Client verbunden!");
|
Serial.println("Neuer Client verbunden!");
|
||||||
@ -377,7 +380,7 @@ void setupWebserver(AsyncWebServer &server) {
|
|||||||
bool success = !Update.hasError();
|
bool success = !Update.hasError();
|
||||||
|
|
||||||
// Bei SPIFFS Update und Erfolg: Restore Configs vor dem Neustart
|
// Bei SPIFFS Update und Erfolg: Restore Configs vor dem Neustart
|
||||||
if (success && Update.command() == U_SPIFFS) {
|
if (success && currentUpdateCommand == U_SPIFFS) {
|
||||||
restoreJsonConfigs();
|
restoreJsonConfigs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,13 +404,12 @@ void setupWebserver(AsyncWebServer &server) {
|
|||||||
},
|
},
|
||||||
[](AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) {
|
[](AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) {
|
||||||
static size_t updateSize = 0;
|
static size_t updateSize = 0;
|
||||||
static int command = 0;
|
|
||||||
|
|
||||||
if (!index) {
|
if (!index) {
|
||||||
updateSize = request->contentLength();
|
updateSize = request->contentLength();
|
||||||
command = (filename.indexOf("website") > -1) ? U_SPIFFS : U_FLASH;
|
currentUpdateCommand = (filename.indexOf("website") > -1) ? U_SPIFFS : U_FLASH;
|
||||||
|
|
||||||
if (command == U_SPIFFS) {
|
if (currentUpdateCommand == U_SPIFFS) {
|
||||||
oledShowMessage("SPIFFS Update...");
|
oledShowMessage("SPIFFS Update...");
|
||||||
backupJsonConfigs();
|
backupJsonConfigs();
|
||||||
|
|
||||||
@ -419,14 +421,14 @@ void setupWebserver(AsyncWebServer &server) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Update.begin(partition->size, command)) {
|
if (!Update.begin(partition->size, currentUpdateCommand)) {
|
||||||
String errorMsg = String("Update begin failed: ") + Update.errorString();
|
String errorMsg = String("Update begin failed: ") + Update.errorString();
|
||||||
request->send(400, "application/json", "{\"success\":false,\"message\":\"" + errorMsg + "\"}");
|
request->send(400, "application/json", "{\"success\":false,\"message\":\"" + errorMsg + "\"}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
oledShowMessage("Firmware Update...");
|
oledShowMessage("Firmware Update...");
|
||||||
if (!Update.begin(updateSize, command)) {
|
if (!Update.begin(updateSize, currentUpdateCommand)) {
|
||||||
String errorMsg = String("Update begin failed: ") + Update.errorString();
|
String errorMsg = String("Update begin failed: ") + Update.errorString();
|
||||||
request->send(400, "application/json", "{\"success\":false,\"message\":\"" + errorMsg + "\"}");
|
request->send(400, "application/json", "{\"success\":false,\"message\":\"" + errorMsg + "\"}");
|
||||||
return;
|
return;
|
||||||
@ -461,6 +463,8 @@ void setupWebserver(AsyncWebServer &server) {
|
|||||||
request->send(400, "application/json", "{\"success\":false,\"message\":\"" + errorMsg + "\"}");
|
request->send(400, "application/json", "{\"success\":false,\"message\":\"" + errorMsg + "\"}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Sende finale Progress-Nachricht
|
||||||
|
ws.textAll("{\"type\":\"updateProgress\",\"progress\":100}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user