From 205a9b481f2caad9e55262bd9078aa357c30af10 Mon Sep 17 00:00:00 2001 From: danghongquan Date: Mon, 14 Oct 2024 17:03:22 +0800 Subject: [PATCH 1/2] =?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 55b6e54d..31518cf7 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 0565d1c1..f8aa5243 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 From 4b263d2bf2fa13148944e116dfd25f39cad3e537 Mon Sep 17 00:00:00 2001 From: danghongquan Date: Sat, 19 Oct 2024 14:44:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:AI=E4=B8=93=E9=A1=B9=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: danghongquan --- ide/src/base-ui/menu/LitMainMenu.ts | 1 + ide/src/trace/SpApplication.ts | 15 ++++-- ide/src/trace/SpApplicationPublicFunc.ts | 5 +- .../trace/component/SpAiAnalysisPage.html.ts | 51 +++++++------------ ide/src/trace/component/SpAiAnalysisPage.ts | 13 ++--- 5 files changed, 36 insertions(+), 49 deletions(-) diff --git a/ide/src/base-ui/menu/LitMainMenu.ts b/ide/src/base-ui/menu/LitMainMenu.ts index e5465cc7..adbcba1e 100644 --- a/ide/src/base-ui/menu/LitMainMenu.ts +++ b/ide/src/base-ui/menu/LitMainMenu.ts @@ -299,6 +299,7 @@ export class LitMainMenu extends BaseElement {
+
`; diff --git a/ide/src/trace/SpApplication.ts b/ide/src/trace/SpApplication.ts index ed72661f..98fbf1ca 100644 --- a/ide/src/trace/SpApplication.ts +++ b/ide/src/trace/SpApplication.ts @@ -119,6 +119,7 @@ export class SpApplication extends BaseElement { | null; static skinChange: Function | null | undefined = null; static skinChange2: Function | null | undefined = null; + static isTraceLoaded: Boolean = false; skinChangeArray: Array = []; private rootEL: HTMLDivElement | undefined | null; private headerDiv: HTMLDivElement | undefined | null; @@ -605,6 +606,7 @@ export class SpApplication extends BaseElement { } private openTraceFile(ev: unknown, isClickHandle?: boolean): void { + SpApplication.isTraceLoaded = false; this.returnOriginalUrl(); this.removeAttribute('custom-color'); this.chartFilter!.setAttribute('hidden', ''); @@ -1230,6 +1232,7 @@ export class SpApplication extends BaseElement { (window as unknown).traceFileName = fileName; } this.showCurrentTraceMenu(fileSize, showFileName, fileName, isDistributed); + SpApplication.isTraceLoaded =true; if (!isDistributed) { this.importConfigDiv!.style.display = Utils.getInstance().getSchedSliceMap().size > 0 ? 'block' : 'none'; } @@ -1963,8 +1966,11 @@ export class SpApplication extends BaseElement { this.croppingFile(this.progressEL!, this.litSearch!); }); - this.aiAnalysis!.addEventListener('click', (ev) => { - if (this.spAiAnalysisPage!.style.visibility === 'hidden') { + let aiAnalysis = this.shadowRoot + ?.querySelector('lit-main-menu')! + .shadowRoot!.querySelector('.ai_analysis') as HTMLDivElement + aiAnalysis!.addEventListener('click', (ev) => { + if (this.spAiAnalysisPage!.style.visibility === 'hidden' || this.spAiAnalysisPage!.style.display === 'none') { this.spAiAnalysisPage!.style.display = 'block'; this.spAiAnalysisPage!.style.visibility = 'visible'; } else { @@ -2179,8 +2185,9 @@ export class SpApplication extends BaseElement { } if (node === showNode) { showNode.style.visibility = 'visible'; - let recordSetting = document.querySelector("body > sp-application")?.shadowRoot?.querySelector("#sp-record-trace")?.shadowRoot?.querySelector("#app-content > record-setting"); - shadowRootInput.preventBubbling(recordSetting!); + //@ts-ignore + } else if (node.id! === 'sp-ai-analysis' && node.style!.visibility! === 'visible') { + return; } else { (node! as HTMLElement).style.visibility = 'hidden'; } diff --git a/ide/src/trace/SpApplicationPublicFunc.ts b/ide/src/trace/SpApplicationPublicFunc.ts index 071c4934..5d05c614 100644 --- a/ide/src/trace/SpApplicationPublicFunc.ts +++ b/ide/src/trace/SpApplicationPublicFunc.ts @@ -327,7 +327,7 @@ export const applicationHtml: string = ` } #sp-ai-analysis { - top:0px; + top:75px; right:0px; position:absolute; z-index:9999; @@ -387,7 +387,6 @@ export const applicationHtml: string = `
- @@ -397,7 +396,6 @@ export const applicationHtml: string = `
- @@ -423,6 +421,7 @@ export const applicationHtml: string = `
+
`; diff --git a/ide/src/trace/component/SpAiAnalysisPage.html.ts b/ide/src/trace/component/SpAiAnalysisPage.html.ts index 94c5850d..1db54ff0 100644 --- a/ide/src/trace/component/SpAiAnalysisPage.html.ts +++ b/ide/src/trace/component/SpAiAnalysisPage.html.ts @@ -26,7 +26,6 @@ export const SpAiAnalysisPageHtml = `
有什么可以帮助您吗? -
@@ -58,7 +57,7 @@ export const SpAiAnalysisPageHtml = `
- 未连接 + 未连接,请启动本地扩展程序再试![指导]
@@ -119,7 +118,7 @@ export const SpAiAnalysisPageHtml = ` .usersay { max-width: 70%; - background: #4baf50; + background: rgb(229,246,255); border-radius: 4px; float: right; line-height: 20px; @@ -133,24 +132,16 @@ export const SpAiAnalysisPageHtml = ` margin-right: 10px; position: relative; text-align: justify; - color: #fff; - } - - .userTriangle { - width: 0px; - height: 0px; - border-left: solid 8px #4baf50; - border-top: solid 5px rgba(255, 255, 255, 0); - border-bottom: solid 5px rgba(255, 255, 255, 0); - position: absolute; - right: -8px; - top: 8px; + color: #000; + border: 1px solid #c4ebf5; + border-radius: 9px; + border-top-right-radius: 0px; } .systemSay { max-width: 70%; border-radius: 4px; - background-color: #fe7300; + background-color: rgb(249,250,252); float: left; line-height: 20px; text-overflow: ellipsis; @@ -162,18 +153,9 @@ export const SpAiAnalysisPageHtml = ` margin-top: 10px; position: relative; text-align: justify; - color: #fff; - } - - .aiTriangle { - width: 0px; - height: 0px; - border-right: solid 8px #fe7300; - border-top: solid 5px rgba(255, 255, 255, 0); - border-bottom: solid 5px rgba(255, 255, 255, 0); - position: absolute; - left: -7px; - top: 8px; + color: #000; + border: 0.5px solid #eaeaea; + border-radius: 0 10px 10px 10px; } .chatBox { @@ -310,7 +292,6 @@ export const SpAiAnalysisPageHtml = ` font-size: 12px; height: 30px; line-height: 20px; - cursor: pointer; } .rightTabBar img { @@ -466,15 +447,17 @@ export const SpAiAnalysisPageHtml = ` .loginTip { visibility: hidden; position: absolute; - top: 45%; - left: 38%; + top: 28%; + left: 15%; padding: 5px 15px; - background-color: rgba(0, 0, 0, .8); + background-color: rgb(236, 239, 247); border-radius: 2px; - color: #fff; + color: #000; display: flex; align-items: center; - font-size: 12px; + font-size: 14px; + height: 50px; + line-height: 50px; } .loadingItem { diff --git a/ide/src/trace/component/SpAiAnalysisPage.ts b/ide/src/trace/component/SpAiAnalysisPage.ts index 4cb9e287..53215972 100644 --- a/ide/src/trace/component/SpAiAnalysisPage.ts +++ b/ide/src/trace/component/SpAiAnalysisPage.ts @@ -22,6 +22,7 @@ import { WebSocketManager } from '../../webSocket/WebSocketManager'; import { TypeConstants } from '../../webSocket/Constants'; import { TraceRow } from './trace/base/TraceRow'; import { SpSystemTrace } from './SpSystemTrace'; +import { SpApplication } from '../SpApplication'; @element('sp-ai-analysis') export class SpAiAnalysisPage extends BaseElement { @@ -160,7 +161,7 @@ export class SpAiAnalysisPage extends BaseElement { this.loginTipEl!.style.visibility = 'visible'; setTimeout(() => { this.loginTipEl!.style.visibility = 'hidden'; - }, 1000); + }, 4000); return; } // 同一个trace非第一次诊断,无需再发db文件过去 @@ -193,6 +194,9 @@ export class SpAiAnalysisPage extends BaseElement { // 侧边栏诊断点击事件 *************优化,考虑多个按钮 this.reportBar!.addEventListener('click', () => { + if(!SpApplication.isTraceLoaded){ + return; + } this.reportImg!.src = 'img/report_active.png'; this.chatImg!.src = 'img/talk.png'; this.reportBar!.classList.add('active'); @@ -282,10 +286,6 @@ export class SpAiAnalysisPage extends BaseElement { newQuestion.className = "usersay"; // @ts-ignore newQuestion!.innerHTML = this.inputEl!.value; - // 生成聊天气泡三角 - let triangleDiv = document.createElement('div'); - newQuestion.appendChild(triangleDiv); - triangleDiv.className = 'userTriangle'; // 单条消息模块,最大的div,包含头像、消息、清除浮动元素 let newMessage = document.createElement('div'); newMessage.className = 'usermessage message'; @@ -309,9 +309,6 @@ export class SpAiAnalysisPage extends BaseElement { newQuestion.className = "systemSay"; // @ts-ignore newQuestion!.innerHTML = `
${aiText}
`; - let triangleDiv = document.createElement('div'); - newQuestion.appendChild(triangleDiv); - triangleDiv.className = 'aiTriangle'; let newMessage = document.createElement('div'); newMessage.className = 'aiMessage message'; newMessage.appendChild(headerDiv); -- Gitee