diff --git a/common/modules/mixly-modules/web/burn-upload.js b/common/modules/mixly-modules/web/burn-upload.js index 7c41eaff..3c6d860e 100644 --- a/common/modules/mixly-modules/web/burn-upload.js +++ b/common/modules/mixly-modules/web/burn-upload.js @@ -59,11 +59,11 @@ BU.FILMWARE_LAYER = new HTMLTemplate( const BAUD = goog.platform() === 'darwin' ? 460800 : 921600; -BU.requestPort = () => { +BU.requestPort = async () => { if (SELECTED_BOARD.web.com === 'usb') { - USB.requestPort(); + await USB.requestPort(); } else { - Serial.requestPort(); + await Serial.requestPort(); } } @@ -225,13 +225,18 @@ BU.burnByUSB = () => { BU.burnWithEsptool = async (binFile) => { const { mainStatusBarTabs } = Mixly; - const portName = Serial.getSelectedPortName(); + let portName = Serial.getSelectedPortName(); if (!portName) { - /*layer.msg(Msg.Lang['statusbar.serial.noDevice'], { - time: 1000 - });*/ - BU.requestPort(); - return; + try { + await BU.requestPort(); + portName = Serial.getSelectedPortName(); + if (!portName) { + return; + } + } catch (error) { + Debug.error(error); + return; + } } const statusBarSerial = mainStatusBarTabs.getStatusBarById(portName); if (statusBarSerial) { @@ -337,13 +342,18 @@ BU.burnWithEsptool = async (binFile) => { BU.burnWithAdafruitEsptool = async (binFile) => { const { mainStatusBarTabs } = Mixly; - const portName = Serial.getSelectedPortName(); + let portName = Serial.getSelectedPortName(); if (!portName) { - /*layer.msg(Msg.Lang['statusbar.serial.noDevice'], { - time: 1000 - });*/ - BU.requestPort(); - return; + try { + await BU.requestPort(); + portName = Serial.getSelectedPortName(); + if (!portName) { + return; + } + } catch (error) { + Debug.error(error); + return; + } } const statusBarSerial = mainStatusBarTabs.getStatusBarById(portName); if (statusBarSerial) { @@ -504,14 +514,19 @@ BU.searchLibs = (moduleList, libList = []) => { return libList; } -BU.initUpload = () => { - const portName = Serial.getSelectedPortName(); +BU.initUpload = async () => { + let portName = Serial.getSelectedPortName(); if (!portName) { - /*layer.msg(Msg.Lang['statusbar.serial.noDevice'], { - time: 1000 - });*/ - BU.requestPort(); - return; + try { + await BU.requestPort(); + portName = Serial.getSelectedPortName(); + if (!portName) { + return; + } + } catch (error) { + Debug.error(error); + return; + } } BU.uploadWithAmpy(portName); } diff --git a/common/modules/mixly-modules/web/serial.js b/common/modules/mixly-modules/web/serial.js index e5e2bf35..4a1acb10 100644 --- a/common/modules/mixly-modules/web/serial.js +++ b/common/modules/mixly-modules/web/serial.js @@ -45,13 +45,10 @@ class WebSerial extends Serial { Serial.renderSelectBox(portsName); } - this.requestPort = function () { - navigator.serial.requestPort() - .then((serialport) => { - this.addPort(serialport); - this.refreshPorts(); - }) - .catch(Debug.error); + this.requestPort = async function () { + const serialport = await navigator.serial.requestPort(); + this.addPort(serialport); + this.refreshPorts(); } this.getPort = function (name) { diff --git a/common/modules/mixly-modules/web/usb.js b/common/modules/mixly-modules/web/usb.js index d410cf0e..5fdd0f66 100644 --- a/common/modules/mixly-modules/web/usb.js +++ b/common/modules/mixly-modules/web/usb.js @@ -46,13 +46,14 @@ class USB extends Serial { Serial.renderSelectBox(portsName); } - this.requestPort = function () { - navigator.usb.requestDevice({ filters: [{ vendorId: 0xD28 }] }) - .then((device) => { - this.addPort(device); - this.refreshPorts(); - }) - .catch(Debug.error); + this.requestPort = async function () { + const device = await navigator.usb.requestDevice({ + filters: [{ + vendorId: 0xD28 + }] + }); + this.addPort(device); + this.refreshPorts(); } this.getPort = function (name) {