@@ -1243,14 +1243,12 @@ function web_editor(config) {
12431243
12441244 return p . then ( function ( ) {
12451245 // Change button to disconnect
1246- $ ( "#command-connect" ) . attr ( "id" , "command-disconnect" ) ;
1247- $ ( "#command-disconnect > .roundlabel" ) . text ( config [ "translate" ] [ "static-strings" ] [ "buttons" ] [ "command-disconnect" ] [ "label" ] ) ;
1248- $ ( "#command-disconnect" ) . attr ( "title" , config [ "translate" ] [ "static-strings" ] [ "buttons" ] [ "command-disconnect" ] [ "title" ] ) ;
1246+ $ ( "#command-connect" ) . hide ( ) ;
1247+ $ ( "#command-disconnect" ) . show ( ) ;
12491248
12501249 // Change download to flash
1251- $ ( "#command-download" ) . attr ( "id" , "command-flash" ) ;
1252- $ ( "#command-flash > .roundlabel" ) . text ( config [ "translate" ] [ "static-strings" ] [ "buttons" ] [ "command-flash" ] [ "label" ] ) ;
1253- $ ( "#command-flash" ) . attr ( "title" , config [ "translate" ] [ "static-strings" ] [ "buttons" ] [ "command-flash" ] [ "title" ] ) ;
1250+ $ ( "#command-download" ) . hide ( ) ;
1251+ $ ( "#command-flash" ) . show ( ) ;
12541252
12551253 if ( serial ) {
12561254 doSerial ( ) ;
@@ -1307,10 +1305,10 @@ function web_editor(config) {
13071305 errorDescription + '</div>' + '<div class="flashing-overlay-buttons"><hr />' +
13081306 ( ( err . name === 'device-disconnected' && $ ( "#flashing-overlay-error" ) . html ( ) === "" )
13091307 ? ""
1310- : '<a href="#" id="flashing-overlay-download">' +
1308+ : '<a href="#" id="flashing-overlay-download" class="action" onclick="actionClickListener(event)" >' +
13111309 config [ "translate" ] [ "webusb" ] [ "download" ] +
13121310 '</a> | ' +
1313- '<a href="https://support.microbit.org/a/solutions/articles/19000105428-webusb-troubleshooting/en" id="flashing-overlay-troubleshoot">' +
1311+ '<a href="https://support.microbit.org/a/solutions/articles/19000105428-webusb-troubleshooting/en" id="flashing-overlay-troubleshoot" class="action" onclick="actionClickListener(event)" >' +
13141312 config [ "translate" ] [ "webusb" ] [ "troubleshoot" ] +
13151313 '</a> | ' ) +
13161314 '<a href="#" onclick="flashErrorClose()">' +
@@ -1329,7 +1327,13 @@ function web_editor(config) {
13291327 $ ( "#flashing-overlay-download" ) . click ( doDownload ) ;
13301328
13311329 // Send event
1332- var details = { "flash-type" : ( usePartialFlashing ? "partial-flash" : "full-flash" ) , "event-type" : "error" , "message" : errorType } ;
1330+ // Append error message, replace all special chars with '-', if last char is '-' remove it
1331+ var details = {
1332+ "flash-type" : ( usePartialFlashing ? "partial-flash" : "full-flash" ) ,
1333+ "event-type" : ( ( err . name == "device-disconnected" ) ? "info" : "error" ) ,
1334+ "message" : errorType + "/" + err . message . replace ( / \W + / g, '-' ) . replace ( / \W $ / , '' ) . toLowerCase ( )
1335+ } ;
1336+
13331337 document . dispatchEvent ( new CustomEvent ( 'webusb' , { detail : details } ) ) ;
13341338 }
13351339
@@ -1352,14 +1356,12 @@ function web_editor(config) {
13521356 REPL = null ;
13531357
13541358 // Change button to connect
1355- $ ( "#command-disconnect" ) . attr ( "id" , "command-connect" ) ;
1356- $ ( "#command-connect > .roundlabel" ) . text ( config [ "translate" ] [ "static-strings" ] [ "buttons" ] [ "command-connect" ] [ "label" ] ) ;
1357- $ ( "#command-connect" ) . attr ( "title" , config [ "translate" ] [ "static-strings" ] [ "buttons" ] [ "command-connect" ] [ "title" ] ) ;
1359+ $ ( "#command-disconnect" ) . hide ( ) ;
1360+ $ ( "#command-connect" ) . show ( ) ;
13581361
13591362 // Change flash to download
1360- $ ( "#command-flash" ) . attr ( "id" , "command-download" ) ;
1361- $ ( "#command-download > .roundlabel" ) . text ( config [ "translate" ] [ "static-strings" ] [ "buttons" ] [ "command-download" ] [ "label" ] ) ;
1362- $ ( "#command-download" ) . attr ( "title" , config [ "translate" ] [ "static-strings" ] [ "buttons" ] [ "command-download" ] [ "title" ] ) ;
1363+ $ ( "#command-flash" ) . hide ( ) ;
1364+ $ ( "#command-download" ) . show ( ) ;
13631365
13641366 var p = Promise . resolve ( ) ;
13651367
@@ -1388,9 +1390,6 @@ function web_editor(config) {
13881390 function doFlash ( ) {
13891391 var startTime = new Date ( ) . getTime ( ) ;
13901392
1391- // Listen for unhandled rejections in DAPjs
1392- window . addEventListener ( "unhandledrejection" , webusbErrorHandler ) ;
1393-
13941393 // Hide serial and disconnect if open
13951394 if ( $ ( "#repl" ) . css ( 'display' ) != 'none' ) {
13961395 $ ( "#repl" ) . hide ( ) ;
@@ -1508,7 +1507,7 @@ function web_editor(config) {
15081507 }
15091508
15101509 // Check if we need to connect
1511- if ( $ ( "#command-connect" ) . length ) {
1510+ if ( $ ( "#command-connect" ) . is ( ":visible" ) ) {
15121511 doConnect ( true ) ;
15131512 } else {
15141513 // Change Serial button to close
@@ -1614,11 +1613,10 @@ function web_editor(config) {
16141613 // handling what to do when they're clicked.
16151614 function setupButtons ( ) {
16161615 $ ( "#command-download" ) . click ( function ( ) {
1617- if ( $ ( "#command-download" ) . length ) {
1618- doDownload ( ) ;
1619- } else {
1620- doFlash ( ) ;
1621- }
1616+ doDownload ( ) ;
1617+ } ) ;
1618+ $ ( "#command-flash" ) . click ( function ( ) {
1619+ doFlash ( ) ;
16221620 } ) ;
16231621 $ ( "#command-files" ) . click ( function ( ) {
16241622 doFiles ( ) ;
@@ -1634,11 +1632,10 @@ function web_editor(config) {
16341632 } ) ;
16351633 if ( navigator . usb ) {
16361634 $ ( "#command-connect" ) . click ( function ( ) {
1637- if ( $ ( "#command-connect" ) . length ) {
1638- doConnect ( ) ;
1639- } else {
1640- doDisconnect ( ) ;
1641- }
1635+ doConnect ( ) ;
1636+ } ) ;
1637+ $ ( "#command-disconnect" ) . click ( function ( ) {
1638+ doDisconnect ( ) ;
16421639 } ) ;
16431640 $ ( "#command-serial" ) . click ( function ( ) {
16441641 doSerial ( ) ;
0 commit comments