Skip to content

Commit 1c82caa

Browse files
committed
Fix merge conflict
2 parents 1bb27a4 + 2db1006 commit 1c82caa

4 files changed

Lines changed: 618 additions & 1072 deletions

File tree

js/common/web-file-transfer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class FileTransferClient {
8989
};
9090

9191
if (fetchOptions.method && fetchOptions.method.toUpperCase() != 'OPTIONS') {
92-
if (!this._isMethodAllowed(fetchOptions.method)) {
92+
if (!await this._isMethodAllowed(fetchOptions.method)) {
9393
if (fetchOptions.method.toUpperCase() == "MOVE") {
9494
// This should only happen if rename is used and the user doesn't have latest version
9595
console.warn("Please upgrade to the latest version of CircuitPython. Allowing MOVE for now.");
@@ -114,7 +114,7 @@ class FileTransferClient {
114114

115115
async _isMethodAllowed(method) {
116116
if (this._allowedMethods) {
117-
return this._allowedMethods.includes(method.toUpperCase);
117+
return this._allowedMethods.includes(method.toUpperCase());
118118
}
119119

120120
return false;

js/script.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,8 @@ async function loadEditor() {
477477

478478
var editor;
479479
var currentTimeout = null;
480+
var saveRetryCount = 0;
481+
const MAX_SAVE_RETRIES = 3;
480482

481483
// Save the File Contents and update the UI
482484
async function saveFileContents(path) {
@@ -497,16 +499,24 @@ async function saveFileContents(path) {
497499
if (await workflow.writeFile(path, contents, offset)) {
498500
setFilename(workflow.currentFilename);
499501
setSaved(true);
502+
saveRetryCount = 0;
500503
} else {
501-
await showMessage(`Saving file '${workflow.currentFilename} failed.`);
504+
await showMessage(`Saving file '${workflow.currentFilename}' failed.`);
502505
}
503506
} catch (e) {
504507
console.error("write failed", e, e.stack);
505508
unchanged = Math.min(oldUnchanged, unchanged);
506509
if (currentTimeout != null) {
507510
clearTimeout(currentTimeout);
508511
}
509-
currentTimeout = setTimeout(await saveFileContents(path), 2000);
512+
saveRetryCount++;
513+
if (saveRetryCount < MAX_SAVE_RETRIES) {
514+
console.log(`Save retry ${saveRetryCount} of ${MAX_SAVE_RETRIES}...`);
515+
currentTimeout = setTimeout(await saveFileContents(path), 2000);
516+
} else {
517+
saveRetryCount = 0;
518+
await showMessage(`Saving file '${workflow.currentFilename}' failed after multiple attempts. Check your connection and try again.`);
519+
}
510520
}
511521
}
512522

@@ -550,6 +560,11 @@ async function onTextChange(update) {
550560
}
551561

552562
function disconnectCallback() {
563+
if (currentTimeout != null) {
564+
clearTimeout(currentTimeout);
565+
currentTimeout = null;
566+
}
567+
saveRetryCount = 0;
553568
updateUIConnected(false);
554569
}
555570

0 commit comments

Comments
 (0)