Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/common/web-file-transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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;
Expand Down
19 changes: 17 additions & 2 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -482,16 +484,24 @@ 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);
unchanged = Math.min(oldUnchanged, unchanged);
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.`);
}
}
}

Expand Down Expand Up @@ -535,6 +545,11 @@ async function onTextChange(update) {
}

function disconnectCallback() {
if (currentTimeout != null) {
clearTimeout(currentTimeout);
currentTimeout = null;
}
saveRetryCount = 0;
updateUIConnected(false);
}

Expand Down