diff --git a/js/common/web-file-transfer.js b/js/common/web-file-transfer.js index cfedb9d4..d918e57a 100644 --- a/js/common/web-file-transfer.js +++ b/js/common/web-file-transfer.js @@ -89,7 +89,7 @@ class FileTransferClient { }; if (fetchOptions.method && fetchOptions.method.toUpperCase() != 'OPTIONS') { - if (!this._isMethodAllowed(fetchOptions.method)) { + if (!await this._isMethodAllowed(fetchOptions.method)) { if (fetchOptions.method.toUpperCase() == "MOVE") { // This should only happen if rename is used and the user doesn't have latest version console.warn("Please upgrade to the latest version of CircuitPython. Allowing MOVE for now."); @@ -114,7 +114,7 @@ class FileTransferClient { async _isMethodAllowed(method) { if (this._allowedMethods) { - return this._allowedMethods.includes(method.toUpperCase); + return this._allowedMethods.includes(method.toUpperCase()); } return false; diff --git a/js/script.js b/js/script.js index 6b32d719..7ae4af0e 100644 --- a/js/script.js +++ b/js/script.js @@ -462,6 +462,8 @@ async function loadEditor() { var editor; var currentTimeout = null; +var saveRetryCount = 0; +const MAX_SAVE_RETRIES = 3; // Save the File Contents and update the UI async function saveFileContents(path) { @@ -482,8 +484,9 @@ async function saveFileContents(path) { if (await workflow.writeFile(path, contents, offset)) { setFilename(workflow.currentFilename); setSaved(true); + saveRetryCount = 0; } else { - await showMessage(`Saving file '${workflow.currentFilename} failed.`); + await showMessage(`Saving file '${workflow.currentFilename}' failed.`); } } catch (e) { console.error("write failed", e, e.stack); @@ -491,7 +494,14 @@ async function saveFileContents(path) { if (currentTimeout != null) { clearTimeout(currentTimeout); } - currentTimeout = setTimeout(saveFileContents, 2000); + saveRetryCount++; + if (saveRetryCount < MAX_SAVE_RETRIES) { + console.log(`Save retry ${saveRetryCount} of ${MAX_SAVE_RETRIES}...`); + currentTimeout = setTimeout(saveFileContents, 2000); + } else { + saveRetryCount = 0; + await showMessage(`Saving file '${workflow.currentFilename}' failed after multiple attempts. Check your connection and try again.`); + } } } @@ -535,6 +545,11 @@ async function onTextChange(update) { } function disconnectCallback() { + if (currentTimeout != null) { + clearTimeout(currentTimeout); + currentTimeout = null; + } + saveRetryCount = 0; updateUIConnected(false); }