Do not allow application updates to be cancelled.

This commit is contained in:
Robert Strouse 2024-02-02 15:35:14 -08:00
parent 8bdfd214b5
commit 234f9d9eb5
8 changed files with 21 additions and 13 deletions

View file

@ -259,9 +259,11 @@ void GitUpdater::loop() {
} }
else if(this->status == GIT_UPDATE_CANCELLING) { else if(this->status == GIT_UPDATE_CANCELLING) {
Serial.println("Cancelling update process.........."); Serial.println("Cancelling update process..........");
this->status = GIT_UPDATE_CANCELLED; if(!this->lockFS) {
this->emitUpdateCheck(); this->status = GIT_UPDATE_CANCELLED;
this->cancelled = true; this->cancelled = true;
this->emitUpdateCheck();
}
} }
} }
void GitUpdater::checkForUpdate() { void GitUpdater::checkForUpdate() {
@ -382,7 +384,7 @@ bool GitUpdater::beginUpdate(const char *version) {
this->emitUpdateCheck(); this->emitUpdateCheck();
this->setFirmwareFile(); this->setFirmwareFile();
this->partition = U_FLASH; this->partition = U_FLASH;
this->cancelled = false; this->lockFS = this->cancelled = false;
this->error = 0; this->error = 0;
this->error = this->downloadFile(); this->error = this->downloadFile();
if(this->error == 0 && !this->cancelled) { if(this->error == 0 && !this->cancelled) {
@ -457,7 +459,7 @@ int8_t GitUpdater::downloadFile() {
while(https.connected() && (len > 0 || len == -1) && total < len) { while(https.connected() && (len > 0 || len == -1) && total < len) {
size_t size = stream->available(); size_t size = stream->available();
if(size) { if(size) {
if(this->cancelled) { if(this->cancelled && !this->lockFS) {
Update.abort(); Update.abort();
https.end(); https.end();
free(buff); free(buff);

View file

@ -39,6 +39,7 @@ class GitRepo {
class GitUpdater { class GitUpdater {
public: public:
bool lockFS = false; bool lockFS = false;
bool canCancel = true;
uint8_t status = 0; uint8_t status = 0;
uint32_t lastCheck = 0; uint32_t lastCheck = 0;
bool updateAvailable = false; bool updateAvailable = false;

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1090,9 +1090,11 @@ void Web::begin() {
if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; } if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; }
DynamicJsonDocument sdoc(512); DynamicJsonDocument sdoc(512);
JsonObject sobj = sdoc.to<JsonObject>(); JsonObject sobj = sdoc.to<JsonObject>();
git.status = GIT_UPDATE_CANCELLING; if(!git.lockFS) {
git.toJSON(sobj); git.status = GIT_UPDATE_CANCELLING;
git.cancelled = true; git.toJSON(sobj);
git.cancelled = true;
}
serializeJson(sdoc, g_content); serializeJson(sdoc, g_content);
server.send(200, _encoding_json, g_content); server.send(200, _encoding_json, g_content);
}); });

View file

@ -3,11 +3,11 @@
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8"> <meta charset="UTF-8">
<link rel="stylesheet" href="main.css?v=2.3.2b" type="text/css" /> <link rel="stylesheet" href="main.css?v=2.3.2c" type="text/css" />
<link rel="stylesheet" href="widgets.css?v=2.3.2b" type="text/css" /> <link rel="stylesheet" href="widgets.css?v=2.3.2c" type="text/css" />
<link rel="stylesheet" href="icons.css?v=2.3.2b" type="text/css" /> <link rel="stylesheet" href="icons.css?v=2.3.2c" type="text/css" />
<link rel="icon" type="image/png" href="favicon.png" /> <link rel="icon" type="image/png" href="favicon.png" />
<script type="text/javascript" src="index.js?v=2.3.2b"></script> <script type="text/javascript" src="index.js?v=2.3.2c"></script>
</head> </head>
<body> <body>
<div id="divContainer" class="container main" data-auth="false"> <div id="divContainer" class="container main" data-auth="false">

View file

@ -4277,6 +4277,9 @@ class Firmware {
// Update the status on the client that started the install. // Update the status on the client that started the install.
if (pct >= 100 && prog.part === 100) git.remove(); if (pct >= 100 && prog.part === 100) git.remove();
else { else {
if (prog.part === 100) {
document.getElementById('btnCancelUpdate').style.display = 'none';
}
let p = prog.part === 100 ? document.getElementById('progApplicationDownload') : document.getElementById('progFirmwareDownload'); let p = prog.part === 100 ? document.getElementById('progApplicationDownload') : document.getElementById('progFirmwareDownload');
if (p) { if (p) {
p.style.setProperty('--progress', `${pct}%`); p.style.setProperty('--progress', `${pct}%`);
@ -4306,7 +4309,7 @@ class Firmware {
else { else {
general.reloadApp = true; general.reloadApp = true;
// Change the display and allow the percentage to be shown when the socket emits the progress. // Change the display and allow the percentage to be shown when the socket emits the progress.
let html = `<div>Installing ${ver.name}</div><div style="font-size:.7em;margin-top:4px;">Please wait as the files are downloaded and installed.</div>`; let html = `<div>Installing ${ver.name}</div><div style="font-size:.7em;margin-top:4px;">Please wait as the files are downloaded and installed. Once the application update process starts you may no longer cancel the update as this will corrupt the downloaded files.</div>`;
html += `<div class="progress-bar" id="progFirmwareDownload" style="--progress:0%;margin-top:10px;text-align:center;"></div>`; html += `<div class="progress-bar" id="progFirmwareDownload" style="--progress:0%;margin-top:10px;text-align:center;"></div>`;
html += `<label for="progFirmwareDownload" style="font-size:10pt;">Firmware Install Progress</label>`; html += `<label for="progFirmwareDownload" style="font-size:10pt;">Firmware Install Progress</label>`;
html += `<div class="progress-bar" id="progApplicationDownload" style="--progress:0%;margin-top:10px;text-align:center;"></div>`; html += `<div class="progress-bar" id="progApplicationDownload" style="--progress:0%;margin-top:10px;text-align:center;"></div>`;