Skip to content

Commit e329e62

Browse files
committed
Report low disk space on Bangle.js, also retry on upload error and finally report it (rather than just hanging)
1 parent f83fa46 commit e329e62

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

js/comms.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,27 @@ const Comms = {
282282
// Only upload as a packet if it makes sense for the file, connection supports it, as does device firmware
283283
let uploadPacket = (!!f.canUploadPacket) && Comms.supportsPacketUpload();
284284

285-
console.log(`<COMMS> Upload ${f.name} => ${JSON.stringify(f.content.length>50 ? f.content.substr(0,50)+"..." : f.content)} (${f.content.length}b${uploadPacket?", binary":""})`);
286-
if (uploadPacket) {
287-
Comms.getConnection().espruinoSendFile(f.name, f.content, {
288-
fs: Const.FILES_IN_FS,
289-
chunkSize: Const.PACKET_UPLOAD_CHUNKSIZE,
290-
noACK: Const.PACKET_UPLOAD_NOACK
291-
}).then(doUploadFiles);
292-
} else {
293-
Comms.uploadCommandList(f.cmd, currentBytes, maxBytes).then(doUploadFiles);
285+
function startUpload() {
286+
console.log(`<COMMS> Upload ${f.name} => ${JSON.stringify(f.content.length>50 ? f.content.substr(0,50)+"..." : f.content)} (${f.content.length}b${uploadPacket?", binary":""})`);
287+
if (uploadPacket) {
288+
return Comms.getConnection().espruinoSendFile(f.name, f.content, {
289+
fs: Const.FILES_IN_FS,
290+
chunkSize: Const.PACKET_UPLOAD_CHUNKSIZE,
291+
noACK: Const.PACKET_UPLOAD_NOACK
292+
});
293+
} else {
294+
return Comms.uploadCommandList(f.cmd, currentBytes, maxBytes).then(doUploadFiles);
295+
}
294296
}
297+
298+
startUpload().then(doUploadFiles, function(err) {
299+
console.warn("First attempt failed:", err);
300+
startUpload().then(doUploadFiles, function(err) {
301+
console.warn("Second attempt failed - bailing.", err);
302+
reject(err)
303+
});
304+
});
305+
295306
currentBytes += f.cmd.length;
296307
}
297308

@@ -421,6 +432,12 @@ const Comms = {
421432
info.version = appList.pop();
422433
info.id = appList.pop();
423434
info.storageStats = appList.pop(); // how much storage has been used
435+
if (info.storageStats.totalBytes && (info.storageStats.freeBytes*10<info.storageStats.totalBytes)) {
436+
var suggest = "";
437+
if (info.id.startsWith("BANGLEJS") && info.storageStats.trashBytes*10>info.storageStats.totalBytes)
438+
suggest = "Try running 'Compact Storage' from Bangle.js 'Settings' -> 'Utils'.";
439+
showToast(`Low Disk Space: ${Math.round(info.storageStats.freeBytes/1000)}k of ${Math.round(info.storageStats.totalBytes/1000)}k remaining on this device.${suggest} See 'More...' -> 'Device Info' for more information.`,"warning");
440+
}
424441
// if we just have 'null' then it means we have no apps
425442
if (appList.length==1 && appList[0]==null)
426443
appList = [];

0 commit comments

Comments
 (0)