From 205a9b481f2caad9e55262bd9078aa357c30af10 Mon Sep 17 00:00:00 2001 From: danghongquan Date: Mon, 14 Oct 2024 17:03:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:SN=E5=8F=B7=E5=9B=9E=E6=98=BE=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: danghongquan --- ide/src/hdc/HdcDeviceManager.ts | 10 +- ide/src/trace/component/SpRecordTrace.ts | 119 ++++++++++++----------- 2 files changed, 71 insertions(+), 58 deletions(-) diff --git a/ide/src/hdc/HdcDeviceManager.ts b/ide/src/hdc/HdcDeviceManager.ts index 55b6e54d6..31518cf78 100644 --- a/ide/src/hdc/HdcDeviceManager.ts +++ b/ide/src/hdc/HdcDeviceManager.ts @@ -44,7 +44,7 @@ export class HdcDeviceManager { c: [3], }; private static clientList: Map = new Map(); - private static currentHdcClient: HdcClient; + public static currentHdcClient: HdcClient; private static FILE_RECV_PREFIX_STRING = 'hdc file recv -cwd C:\\ '; /** @@ -74,8 +74,14 @@ export class HdcDeviceManager { * @param serialNumber serialNumber */ public static async connect(serialNumber: string): Promise { + if (this.currentHdcClient && serialNumber !== this.currentHdcClient.usbDevice.serialNumber) { + this.clientList.delete(serialNumber); + HdcDeviceManager.disConnect(this.currentHdcClient.usbDevice.serialNumber).then((): void => { + window.publish(window.SmartEvent.UI.DeviceDisConnect, this.currentHdcClient.usbDevice.serialNumber); + }); + } const client = this.clientList.get(serialNumber); - if (client) { + if (client && serialNumber === this.currentHdcClient.usbDevice.serialNumber) { if (client.usbDevice!.opened) { log('device Usb is Open'); return true; diff --git a/ide/src/trace/component/SpRecordTrace.ts b/ide/src/trace/component/SpRecordTrace.ts index 0565d1c1c..f8aa52435 100644 --- a/ide/src/trace/component/SpRecordTrace.ts +++ b/ide/src/trace/component/SpRecordTrace.ts @@ -22,6 +22,7 @@ import { SpRecordSetting } from './setting/SpRecordSetting'; import { LitMainMenu, MenuGroup, MenuItem } from '../../base-ui/menu/LitMainMenu'; import { SpProbesConfig } from './setting/SpProbesConfig'; import { SpTraceCommand } from './setting/SpTraceCommand'; +import { HdcStream } from '../../hdc/hdcclient/HdcStream'; import { FlagsConfig } from './SpFlags'; import LitSwitch from '../../base-ui/switch/lit-switch'; import { LitSlider } from '../../base-ui/slider/LitSlider'; @@ -119,6 +120,7 @@ export class SpRecordTrace extends BaseElement { private MenuItemArktsHtml: LitMainMenuItem | undefined | null; private MenuItemEbpf: MenuItem | undefined | null; private MenuItemEbpfHtml: LitMainMenuItem | undefined | null; + private hdcList: Array = []; set record_template(re: boolean) { if (re) { @@ -167,7 +169,7 @@ export class SpRecordTrace extends BaseElement { return clearFlag; } - private async refreshDeviceList(): Promise { + private async refreshDeviceList(sn?: unknown): Promise { if (this.vs) { this.refreshDeviceListByVs(); } else { @@ -183,20 +185,18 @@ export class SpRecordTrace extends BaseElement { this.showHint = true; } } + this.hdcList = devs; let optionNum = 0; for (let len = 0; len < devs.length; len++) { let dev = devs[len]; let option = document.createElement('option'); option.className = 'select'; if (typeof dev.serialNumber === 'string') { - let res = await HdcDeviceManager.connect(dev.serialNumber); - if (res) { optionNum++; option.value = dev.serialNumber; option.textContent = dev!.serialNumber ? dev!.serialNumber!.toString() : 'hdc Device'; this.deviceSelect!.appendChild(option); - } - if (len === 0 && res) { + if (dev.serialNumber === sn) { option.selected = true; this.recordButton!.hidden = false; this.disconnectButton!.hidden = false; @@ -204,27 +204,6 @@ export class SpRecordTrace extends BaseElement { this.devicePrompt!.innerText = ''; this.hintEl!.textContent = ''; SpRecordTrace.serialNumber = option.value; - if (this.MenuItemArkts && this.MenuItemArktsHtml) {//连接成功后,arkts开关置灰不能点击 - this.MenuItemArktsHtml.style.color = 'gray'; - this.MenuItemArktsHtml.disabled = true; - if (this.MenuItemArkts.clickHandler) { - this.MenuItemArkts.clickHandler = undefined; - } - } - try { - let kernelInfo = await HdcDeviceManager.shellResultAsString(CmdConstant.CMD_UNAME, false); - if (kernelInfo.includes('HongMeng')) { - if (this.MenuItemEbpf && this.MenuItemEbpfHtml) {//如果为鸿蒙内核,ebpf开关置灰不能点击 - this.MenuItemEbpfHtml.style.color = 'gray'; - this.MenuItemEbpfHtml.disabled = true; - if (this.MenuItemEbpf.clickHandler) { - this.MenuItemEbpf.clickHandler = undefined; - } - } - } - } catch (error) { - console.error('Failed to get kernel info:', error); - } this.refreshDeviceVersion(option); } } @@ -246,8 +225,29 @@ export class SpRecordTrace extends BaseElement { } } private refreshDeviceVersion(option: HTMLOptionElement): void { - HdcDeviceManager.connect(option.value).then((result) => { + HdcDeviceManager.connect(option.value).then(async (result) => { if (result) { + if (this.MenuItemArkts && this.MenuItemArktsHtml) {//连接成功后,arkts开关置灰不能点击 + this.MenuItemArktsHtml.style.color = 'gray'; + this.MenuItemArktsHtml.disabled = true; + if (this.MenuItemArkts.clickHandler) { + this.MenuItemArkts.clickHandler = undefined; + } + } + try { + let kernelInfo = await HdcDeviceManager.shellResultAsString(CmdConstant.CMD_UNAME, false); + if (kernelInfo.includes('HongMeng')) { + if (this.MenuItemEbpf && this.MenuItemEbpfHtml) {//如果为鸿蒙内核,ebpf开关置灰不能点击 + this.MenuItemEbpfHtml.style.color = 'gray'; + this.MenuItemEbpfHtml.disabled = true; + if (this.MenuItemEbpf.clickHandler) { + this.MenuItemEbpf.clickHandler = undefined; + } + } + } + } catch (error) { + console.error('Failed to get kernel info:', error); + } HdcDeviceManager.shellResultAsString(CmdConstant.CMD_GET_VERSION, false).then((version) => { SpRecordTrace.selectVersion = this.getDeviceVersion(version); this.setDeviceVersionSelect(SpRecordTrace.selectVersion); @@ -497,7 +497,7 @@ export class SpRecordTrace extends BaseElement { // @ts-ignore HdcDeviceManager.findDevice().then((usbDevices): void => { log(usbDevices); - this.refreshDeviceList(); + this.refreshDeviceList(usbDevices.serialNumber); }); } }; @@ -572,26 +572,27 @@ export class SpRecordTrace extends BaseElement { }; disconnectButtonClickEvent = (): void => { + // --------------我修改的 let index = this.deviceSelect!.selectedIndex; - if (index !== -1) { - let selectOption = this.deviceSelect!.options[index]; - let value = selectOption.value; - HdcDeviceManager.disConnect(value).then((): void => { - this.deviceSelect!.removeChild(selectOption); - if (this.nowChildItem === this.spWebShell) { - window.publish(window.SmartEvent.UI.DeviceDisConnect, value); - } - if (this.deviceSelect!.selectedIndex !== -1) { - let item = this.deviceSelect!.options[this.deviceSelect!.selectedIndex]; - SpRecordTrace.serialNumber = item.value; - } else { - this.recordButton!.hidden = true; - this.disconnectButton!.hidden = true; - this.devicePrompt!.innerText = 'Device not connected'; - this.sp!.search = false; - SpRecordTrace.serialNumber = ''; - } - }); + if (index !== -1 && this.deviceSelect!.options.length > 0) { + for (let i = 0; i < this.deviceSelect!.options.length; i++) { + let selectOption = this.deviceSelect!.options[i]; + let value = selectOption.value; + HdcDeviceManager.disConnect(value).then((): void => { + this.deviceSelect!.removeChild(selectOption); + if (this.nowChildItem === this.spWebShell) { + window.publish(window.SmartEvent.UI.DeviceDisConnect, value); + } + let options = this.deviceSelect!.options; + if (options.length <= 0) { + this.recordButton!.hidden = true; + this.disconnectButton!.hidden = true; + this.devicePrompt!.innerText = 'Device not connected'; + this.sp!.search = false; + SpRecordTrace.serialNumber = ''; + } + }); + } } }; @@ -1454,15 +1455,21 @@ export class SpRecordTrace extends BaseElement { synchronizeDeviceList(): void { this.deviceSelect!.innerHTML = ''; if (SpRecordTrace.serialNumber !== '') { - let option = document.createElement('option'); - option.className = 'select'; - option.selected = true; - option.value = SpRecordTrace.serialNumber; - option.textContent = SpRecordTrace.serialNumber; - this.deviceSelect!.appendChild(option); - this.recordButton!.hidden = false; - this.disconnectButton!.hidden = false; - this.devicePrompt!.innerText = ''; + for (let i = 0; i < this.hdcList.length; i++) { + let dev = this.hdcList[i]; + let option = document.createElement('option'); + option.className = 'select'; + //@ts-ignore + option.selected = dev.serialNumber === SpRecordTrace.serialNumber; + //@ts-ignore + option.value = dev.serialNumber; + //@ts-ignore + option.textContent = dev.serialNumber; + this.deviceSelect!.appendChild(option); + this.recordButton!.hidden = false; + this.disconnectButton!.hidden = false; + this.devicePrompt!.innerText = ''; + } if (SpRecordTrace.selectVersion && SpRecordTrace.selectVersion !== '') { this.setDeviceVersionSelect(SpRecordTrace.selectVersion); } -- Gitee