From 3934c819c5e35cac471317f1c5bd95088f6bdfd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=AB=8B=E5=B8=AE?= <3294713004@qq.com> Date: Sun, 27 Apr 2025 20:01:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(core):=20=E5=B0=86firmware=20layer?= =?UTF-8?q?=E4=BB=8Elayui=E8=B0=83=E6=95=B4=E4=B8=BAdialog-plus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mixly-modules/common/layer-firmware.js | 94 +++++++++++++++++++ .../mixly-modules/common/layer-progress.js | 3 +- common/modules/mixly-modules/deps.json | 14 +++ .../mixly-modules/electron/burn-upload.js | 78 ++++++--------- .../modules/mixly-modules/web/burn-upload.js | 73 +++++--------- common/templates/html/dialog/firmware.html | 32 +++++++ common/templates/html/dialog/progress.html | 2 +- common/templates/html/filmware-layer.html | 19 ---- 8 files changed, 194 insertions(+), 121 deletions(-) create mode 100644 common/modules/mixly-modules/common/layer-firmware.js create mode 100644 common/templates/html/dialog/firmware.html delete mode 100644 common/templates/html/filmware-layer.html diff --git a/common/modules/mixly-modules/common/layer-firmware.js b/common/modules/mixly-modules/common/layer-firmware.js new file mode 100644 index 00000000..a7905721 --- /dev/null +++ b/common/modules/mixly-modules/common/layer-firmware.js @@ -0,0 +1,94 @@ +goog.loadJs('common', () => { + +goog.require('Mixly.Env'); +goog.require('Mixly.Msg'); +goog.require('Mixly.Layer'); +goog.require('Mixly.HTMLTemplate'); +goog.provide('Mixly.LayerFirmware'); + +const { + Env, + Msg, + Layer, + HTMLTemplate +} = Mixly; + + +class LayerFirmware extends Layer { + static { + HTMLTemplate.add( + 'html/dialog/firmware.html', + new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/dialog/firmware.html'))) + ); + } + + #dialog_ = null; + #$dialogContent_ = null; + #$cancel_ = null; + #$burn_ = null; + #$select_ = null; + #map_ = {}; + + constructor(config = {}, shadowType = 'nav') { + const $dialogContent_ = $(HTMLTemplate.get('html/dialog/firmware.html').render({ + cancel: Msg.Lang['nav.btn.cancel'], + burn: Msg.Lang['nav.btn.burn'] + })); + config.content = $dialogContent_; + super(config, shadowType); + this.#$dialogContent_ = $dialogContent_; + this.#$cancel_ = $dialogContent_.find('.cancel'); + this.#$burn_ = $dialogContent_.find('.burn'); + this.#$select_ = $dialogContent_.find('.type'); + this.#$select_.select2({ + data: [], + minimumResultsForSearch: Infinity, + width: '380px', + dropdownCssClass: 'mixly-scrollbar' + }); + this.addEventsType(['burn']); + this.#addEventsListener_(); + } + + #addEventsListener_() { + this.#$cancel_.click(() => { + this.hide(); + }); + + this.#$burn_.click(() => { + this.hide(); + this.runEvent('burn', this.#map_[this.#$select_.val()]); + }); + } + + setMenu(items) { + this.#$select_.empty(); + for (let item of items) { + const newOption = new window.Option(item.text, item.id); + this.#$select_.append(newOption); + } + this.#$select_.trigger('change'); + } + + setMap(firmwareMap) { + this.#map_ = firmwareMap; + } + + dispose() { + this.#$select_.select2('destroy'); + this.#$select_.remove(); + this.#$select_ = null; + this.#$cancel_.remove(); + this.#$cancel_ = null; + this.#$burn_.remove(); + this.#$burn_ = null; + this.#$dialogContent_.remove(); + this.#$dialogContent_ = null; + this.#map_ = null; + super.dispose(); + } +} + +Mixly.LayerFirmware = LayerFirmware; + +}); \ No newline at end of file diff --git a/common/modules/mixly-modules/common/layer-progress.js b/common/modules/mixly-modules/common/layer-progress.js index a7358675..6f74c078 100644 --- a/common/modules/mixly-modules/common/layer-progress.js +++ b/common/modules/mixly-modules/common/layer-progress.js @@ -25,13 +25,14 @@ class LayerProgress extends Layer { constructor(config = {}, shadowType = 'nav') { const $dialogContent_ = $(HTMLTemplate.get('html/dialog/progress.html').render()); - config.content = $dialogContent_[0]; + config.content = $dialogContent_; super(config, shadowType); this.#$dialogContent_ = $dialogContent_; } dispose() { this.#$dialogContent_.remove(); + this.#$dialogContent_ = null; super.dispose(); } } diff --git a/common/modules/mixly-modules/deps.json b/common/modules/mixly-modules/deps.json index 963d5e38..cf209c1f 100644 --- a/common/modules/mixly-modules/deps.json +++ b/common/modules/mixly-modules/deps.json @@ -597,6 +597,18 @@ "Mixly.LayerExt" ] }, + { + "path": "/common/layer-firmware.js", + "require": [ + "Mixly.Env", + "Mixly.Msg", + "Mixly.Layer", + "Mixly.HTMLTemplate" + ], + "provide": [ + "Mixly.LayerFirmware" + ] + }, { "path": "/common/layer-progress.js", "require": [ @@ -1283,6 +1295,7 @@ "Mixly.Workspace", "Mixly.Debug", "Mixly.HTMLTemplate", + "Mixly.LayerFirmware", "Mixly.Electron.Serial" ], "provide": [ @@ -1560,6 +1573,7 @@ "Mixly.Debug", "Mixly.HTMLTemplate", "Mixly.MString", + "Mixly.LayerFirmware", "Mixly.Web.Serial", "Mixly.Web.Ampy" ], diff --git a/common/modules/mixly-modules/electron/burn-upload.js b/common/modules/mixly-modules/electron/burn-upload.js index 259d171d..d1810164 100644 --- a/common/modules/mixly-modules/electron/burn-upload.js +++ b/common/modules/mixly-modules/electron/burn-upload.js @@ -10,6 +10,7 @@ goog.require('Mixly.Msg'); goog.require('Mixly.Workspace'); goog.require('Mixly.Debug'); goog.require('Mixly.HTMLTemplate'); +goog.require('Mixly.LayerFirmware'); goog.require('Mixly.Electron.Serial'); goog.provide('Mixly.Electron.BU'); @@ -24,7 +25,8 @@ const { Workspace, Serial, Debug, - HTMLTemplate + HTMLTemplate, + LayerFirmware } = Mixly; const { BU } = Electron; @@ -43,16 +45,26 @@ const iconv_lite = Mixly.require('iconv-lite'); const os = Mixly.require('node:os'); BU.uploading = false; - BU.burning = false; - BU.shell = null; - -BU.FILMWARE_LAYER = new HTMLTemplate( - goog.readFileSync(path.join(Env.templatePath, 'html/filmware-layer.html')) -).render({ - cancel: Msg.Lang['nav.btn.cancel'], - burn: Msg.Lang['nav.btn.burn'] +BU.firmwareLayer = new LayerFirmware({ + width: 400, + title: Msg.Lang['nav.btn.burn'], + cancelValue: false, + skin: 'layui-anim layui-anim-scale', + cancel: false, + cancelDisplay: false +}); +BU.firmwareLayer.bind('burn', (info) => { + const { mainStatusBarTabs } = Mixly; + const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output'); + statusBarTerminal.setValue(''); + mainStatusBarTabs.changeTo('output'); + mainStatusBarTabs.show(); + BU.burning = true; + BU.uploading = false; + const port = Serial.getSelectedPortName(); + BU.burnWithPort(port, info); }); /** @@ -613,52 +625,18 @@ BU.burnWithSpecialBin = () => { const statusBarTerminal = mainStatusBarTabs.getStatusBarById('output'); const firmwares = SELECTED_BOARD.burn.special; let menu = []; + let commandMap = {}; for (let firmware of firmwares) { - if (!firmware?.name && !firmware?.command) return; + if (!firmware?.name && !firmware?.command) continue; menu.push({ - id: firmware.command, + id: firmware.name, text: firmware.name }); + commandMap[firmware.name] = firmware.command; } - LayerExt.open({ - title: [Msg.Lang['nav.btn.burn'], '36px'], - area: ['400px', '160px'], - max: false, - min: false, - content: BU.FILMWARE_LAYER, - shade: Mixly.LayerExt.SHADE_ALL, - resize: false, - success: function (layero, index) { - const $select = layero.find('select'); - $select.select2({ - data: menu, - minimumResultsForSearch: Infinity, - width: '360px', - dropdownCssClass: 'mixly-scrollbar' - }); - layero.find('button').click((event) => { - const $target = $(event.currentTarget); - const type = $target.attr('data-id'); - const command = $select.val(); - layer.close(index, () => { - if (type !== 'burn') { - return; - } - statusBarTerminal.setValue(''); - mainStatusBarTabs.changeTo('output'); - mainStatusBarTabs.show(); - BU.burning = true; - BU.uploading = false; - const port = Serial.getSelectedPortName(); - BU.burnWithPort(port, command); - }); - }); - }, - beforeEnd: function (layero) { - layero.find('select').select2('destroy'); - layero.find('button').off(); - } - }); + BU.firmwareLayer.setMap(commandMap); + BU.firmwareLayer.setMenu(menu); + BU.firmwareLayer.show(); } /** diff --git a/common/modules/mixly-modules/web/burn-upload.js b/common/modules/mixly-modules/web/burn-upload.js index a06b83ad..95d19873 100644 --- a/common/modules/mixly-modules/web/burn-upload.js +++ b/common/modules/mixly-modules/web/burn-upload.js @@ -19,6 +19,7 @@ goog.require('Mixly.Workspace'); goog.require('Mixly.Debug'); goog.require('Mixly.HTMLTemplate'); goog.require('Mixly.MString'); +goog.require('Mixly.LayerFirmware'); goog.require('Mixly.Web.Serial'); goog.require('Mixly.Web.Ampy'); goog.provide('Mixly.Web.BU'); @@ -34,7 +35,8 @@ const { Workspace, Debug, HTMLTemplate, - MString + MString, + LayerFirmware } = Mixly; const { @@ -52,12 +54,22 @@ const { BU.uploading = false; BU.burning = false; - -BU.FILMWARE_LAYER = new HTMLTemplate( - goog.readFileSync(path.join(Env.templatePath, 'html/filmware-layer.html')) -).render({ - cancel: Msg.Lang['nav.btn.cancel'], - burn: Msg.Lang['nav.btn.burn'] +BU.firmwareLayer = new LayerFirmware({ + width: 400, + title: Msg.Lang['nav.btn.burn'], + cancelValue: false, + skin: 'layui-anim layui-anim-scale', + cancel: false, + cancelDisplay: false +}); +BU.firmwareLayer.bind('burn', (info) => { + const boardKey = Boards.getSelectedBoardKey(); + const { web } = SELECTED_BOARD; + if (boardKey.indexOf('micropython:esp32s2') !== -1) { + BU.burnWithAdafruitEsptool(info, web.burn.erase); + } else { + BU.burnWithEsptool(info, web.burn.erase); + } }); const BAUD = goog.platform() === 'darwin' ? 460800 : 921600; @@ -863,55 +875,16 @@ BU.burnWithSpecialBin = () => { let menu = []; let firmwareMap = {}; for (let firmware of firmwares) { - if (!firmware?.name && !firmware?.binFile) return; + if (!firmware?.name && !firmware?.binFile) continue; menu.push({ id: firmware.name, text: firmware.name }); firmwareMap[firmware.name] = firmware.binFile; } - const layerNum = LayerExt.open({ - title: [Msg.Lang['nav.btn.burn'], '36px'], - area: ['400px', '160px'], - max: false, - min: false, - content: BU.FILMWARE_LAYER, - shade: LayerExt.SHADE_ALL, - resize: false, - success: function (layero, index) { - const $select = layero.find('select'); - $select.select2({ - data: menu, - minimumResultsForSearch: Infinity, - width: '360px', - dropdownCssClass: 'mixly-scrollbar' - }); - layero.find('button').click((event) => { - const $target = $(event.currentTarget); - const type = $target.attr('data-id'); - const binFile = firmwareMap[$select.val()]; - layer.close(index, () => { - if (type !== 'burn') { - return; - } - const boardKey = Boards.getSelectedBoardKey(); - const { web } = SELECTED_BOARD; - if (boardKey.indexOf('micropython:esp32s2') !== -1) { - BU.burnWithAdafruitEsptool(binFile, web.burn.erase); - } else { - BU.burnWithEsptool(binFile, web.burn.erase); - } - }); - }); - }, - beforeEnd: function (layero) { - layero.find('select').select2('destroy'); - layero.find('button').off(); - }, - end: function () { - $(`#layui-layer-shade${layerNum}`).remove(); - } - }); + BU.firmwareLayer.setMap(firmwareMap); + BU.firmwareLayer.setMenu(menu); + BU.firmwareLayer.show(); } }); \ No newline at end of file diff --git a/common/templates/html/dialog/firmware.html b/common/templates/html/dialog/firmware.html new file mode 100644 index 00000000..730a1ceb --- /dev/null +++ b/common/templates/html/dialog/firmware.html @@ -0,0 +1,32 @@ + +