Skip to content

Commit cf80219

Browse files
microbit-sammicrobit-carlos
authored andcommitted
WebUSB: Additional errors are appended to an existing error modal (#237)
1 parent a7d102e commit cf80219

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

python-main.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,23 +1248,24 @@ function web_editor(config) {
12481248
}
12491249
}
12501250

1251-
// Show error message
1252-
$("#flashing-overlay-error").html(
1253-
'<div>' +
1254-
'<strong>' + ((err.message === undefined) ? "WebUSB Error" : err.message) + '</strong><br>' +
1255-
errorDescription +
1256-
'<div class="modal-msg-links">' +
1257-
(err.name === 'device-disconnected'
1251+
var errorHTML = '<div><strong>' + ((err.message === undefined) ? "WebUSB Error" : err.message) + '</strong><br >' +
1252+
errorDescription + '</div>' + '<div class="flashing-overlay-buttons"><hr />' +
1253+
((err.name === 'device-disconnected' && $("#flashing-overlay-error").html() === "")
12581254
? ""
1259-
: '<br ><a href="#" id="flashing-overlay-download">' +
1260-
config["translate"]["webusb"]["download"] +
1261-
'</a> | ') +
1255+
: '<a href="#" id="flashing-overlay-download">' +
1256+
config["translate"]["webusb"]["download"] +
1257+
'</a> | ') +
12621258
'<a href="#" onclick="flashErrorClose()">' +
12631259
config["translate"]["webusb"]["close"] +
1264-
'</a>' +
1265-
'</div>' +
1266-
'</div>'
1267-
);
1260+
'</a></div>';
1261+
1262+
// Show error message
1263+
if($("#flashing-overlay-error").html() == "") {
1264+
$("#flashing-overlay-error").html(errorHTML);
1265+
} else {
1266+
$(".flashing-overlay-buttons").hide(); // Hide previous buttons
1267+
$("#flashing-overlay-error").append("<hr />" + errorHTML);
1268+
}
12681269

12691270
// Attach download handler
12701271
$("#flashing-overlay-download").click(doDownload);
@@ -1275,6 +1276,10 @@ function web_editor(config) {
12751276
}
12761277

12771278
function doDisconnect() {
1279+
1280+
// Remove disconnect listenr
1281+
navigator.usb.removeEventListener('disconnect', showDisconnectError);
1282+
12781283
// Hide serial and disconnect if open
12791284
if ($("#repl").css('display') != 'none') {
12801285
$("#repl").hide();
@@ -1393,17 +1398,16 @@ function web_editor(config) {
13931398
var timeTaken = (new Date().getTime() - startTime);
13941399
var details = {"flash-type": (usePartialFlashing ? "partial-flash" : "full-flash"), "event-type": "flash-time", "message": timeTaken};
13951400
document.dispatchEvent(new CustomEvent('webusb', { detail: details }));
1396-
})
1397-
.catch(webusbErrorHandler)
1398-
.finally(function() {
1399-
// Remove event listener
1400-
window.removeEventListener("unhandledrejection", webusbErrorHandler);
14011401

14021402
// Close overview
14031403
setTimeout(function(){
14041404
$("#flashing-overlay-container").hide();
14051405
}, 500);
1406-
1406+
})
1407+
.catch(webusbErrorHandler)
1408+
.finally(function() {
1409+
// Remove event listener
1410+
window.removeEventListener("unhandledrejection", webusbErrorHandler);
14071411
});
14081412
}
14091413

0 commit comments

Comments
 (0)