1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import { TIndexInfo } from '../common/entity/DatabaseEntity' 16import { showFloatWindow, hideFloatWindow } from '../common/ui/floatwindow/utils/FloatWindowUtils' 17import { getCpuCoreInfo} from '../common/utils/SystemUtils'; 18import FloatWindowConstant from '../common/ui/floatwindow/FloatWindowConstant' 19import CommonEvent from '@ohos.commonEvent' 20 21 22@Component 23export struct ItemContent { 24 private icon 25 private tittle: string 26 @State value: string = "-1" 27 private onClickCallBack: () => void 28 29 build() { 30 Row() { 31 Image(this.icon).width(16).height(16).margin({ right: '2%' }) 32 Flex({ justifyContent: FlexAlign.SpaceBetween, alignItems: ItemAlign.Center }) { 33 Text(this.tittle).fontSize(10).fontColor(Color.White) 34 Text(this.value).fontSize(10).fontColor(Color.White) 35 }.width('88%').height(20) 36 } 37 .height(22) 38 .width('88%') 39 .onClick(() => { 40 this.onClickCallBack() 41 }) 42 } 43} 44 45@Entry 46@Component 47struct TitleWindowPage { 48 private data: boolean[]= [false, false, false, false, false, false, false, false] 49 @State tIndexInfo: TIndexInfo = new TIndexInfo() 50 offsetX: number = -1 51 offsetY: number = -1 52 cpuCoreArr: Array<Number> 53 aboutToAppear() { 54 55 this.cpuCoreArr = getCpuCoreInfo().map(Number).sort() 56 57 let that = this 58 var subscriber 59 //订阅者信息 60 var subscribeInfo = { 61 events: ["event"] 62 }; 63 //订阅公共事件回调 64 function SubscribeCallBack(err, data) { 65 if (data.data == "") { 66 } else { 67 console.error("subscriberCurData:" + data.data); 68 that.tIndexInfo = JSON.parse(data.data) 69 globalThis.cpu0Frequency = that.tIndexInfo.cpu0Frequency 70 globalThis.cpu1Frequency = that.tIndexInfo.cpu1Frequency 71 globalThis.cpu2Frequency = that.tIndexInfo.cpu2Frequency 72 73 if (that.tIndexInfo.cpu4Frequency != undefined && that.tIndexInfo.cpu7Frequency != undefined) { 74 globalThis.cpu1Frequency = that.tIndexInfo.cpu4Frequency 75 globalThis.cpu2Frequency = that.tIndexInfo.cpu7Frequency 76 that.tIndexInfo.cpu1Frequency = that.tIndexInfo.cpu4Frequency 77 that.tIndexInfo.cpu2Frequency = that.tIndexInfo.cpu7Frequency 78 that.tIndexInfo.cpu1Load = that.tIndexInfo.cpu1Load 79 that.tIndexInfo.cpu2Load = that.tIndexInfo.cpu2Load 80 } 81 82 globalThis.currentNow = that.tIndexInfo.currentNow 83 globalThis.ddrFrequency = that.tIndexInfo.ddrFrequency 84 globalThis.lineFps = that.tIndexInfo.fps 85 globalThis.gpuFrequency = that.tIndexInfo.gpuFrequency 86 globalThis.pss = that.tIndexInfo.pss 87 globalThis.shellBackTemp = that.tIndexInfo.shellFrameTemp 88 89 } 90 } 91 //创建订阅者回调 92 function CreateSubscriberCallBack(err, data) { 93 subscriber = data; 94 //订阅公共事件 95 CommonEvent.subscribe(subscriber, SubscribeCallBack); 96 } 97 //创建订阅者 98 CommonEvent.createSubscriber(subscribeInfo, CreateSubscriberCallBack); 99 } 100 101 MoveWindow(offsetX: number, offsetY: number) { 102 globalThis.MoveTitleWindow(offsetX, offsetY) 103 } 104 105 SetWindowPosition(offsetX: number, offsetY: number) { 106 globalThis.SetTitleWindowPosition(offsetX, offsetY) 107 } 108 109 floatWindowEvent(floatName: string, flag: number) { 110 if (this.data[flag]) { 111 hideFloatWindow(floatName) 112 this.data[flag] = false 113 } else { 114 showFloatWindow(floatName) 115 this.data[flag] = true 116 } 117 } 118 119 build() { 120 Stack({ alignContent: Alignment.Center }) { 121 Rect({ width: '100%', height: '100%' }).radius(20).opacity(0.4) 122 Column({ space: 2 }) { 123 124 Row() { 125 Image($r("app.media.logo")).width(10).height(10).margin({ left: '2%' }) 126 Text("SmartPerf") 127 .fontSize(12) 128 .fontColor($r("app.color.color_fff")).margin({ left: '2%' }) 129 Image($r("app.media.icon_close_small")).height(15).width(15).margin({ left: '45%' }).onClick(() => { 130 //关闭实时悬浮框 131 globalThis.HideTitleWindow() 132 }) 133 }.height(20) 134 .width('90%') 135 136 137 if (this.tIndexInfo.fps != undefined) { 138 ItemContent({ 139 icon: $r("app.media.icon_average_frame_b"), 140 value: (this.tIndexInfo.fps.toString()) + "FPS", 141 tittle: "帧率", 142 onClickCallBack: () => { 143 this.floatWindowEvent("sp_FPS", FloatWindowConstant.FPS) 144 } 145 }) 146 } 147 148 if (this.tIndexInfo.currentNow != undefined) { 149 ItemContent({ 150 icon: $r("app.media.icon_normalized_current"), 151 value: (0 - Number(this.tIndexInfo.currentNow)).toString() + "mA", 152 tittle: "电流", 153 onClickCallBack: () => { 154 this.floatWindowEvent("sp_currentNow", FloatWindowConstant.CURRENT_NOW) 155 } 156 }) 157 } 158 if (this.tIndexInfo.ddrFrequency != undefined) { 159 ItemContent({ 160 icon: $r("app.media.icon_counter"), 161 value: (parseInt(this.tIndexInfo.ddrFrequency.toString()) / 1e6).toString() + "MHz", 162 tittle: "DDR频率", 163 onClickCallBack: () => { 164 this.floatWindowEvent("sp_ddrFrequency", FloatWindowConstant.DDR_FREQUENCY) 165 } 166 }) 167 } 168 169 if (this.tIndexInfo["cpu"+ this.cpuCoreArr[0] +"Frequency"] != undefined) { 170 ItemContent({ 171 icon: $r("app.media.icon_counter"), 172 value: (parseInt(this.tIndexInfo["cpu"+ this.cpuCoreArr[0] +"Frequency"].toString()) / 1e3).toString() + "MHz " + this.tIndexInfo.cpu0Load + "%", 173 tittle: "CPU-A频率", 174 onClickCallBack: () => { 175 this.floatWindowEvent("sp_cpu0Frequency", FloatWindowConstant.CPU0_FREQUENCY) 176 } 177 }) 178 } 179 180 if (this.tIndexInfo["cpu"+ this.cpuCoreArr[1] +"Frequency"] != undefined) { 181 ItemContent({ 182 icon: $r("app.media.icon_counter"), 183 value: (parseInt(this.tIndexInfo["cpu"+ this.cpuCoreArr[1] +"Frequency"].toString()) / 1e3).toString() + "MHz " + this.tIndexInfo.cpu1Load + "%", 184 tittle: "CPU-B频率", 185 onClickCallBack: () => { 186 this.floatWindowEvent("sp_cpu1Frequency", FloatWindowConstant.CPU1_FREQUENCY) 187 } 188 }) 189 } 190 if (this.tIndexInfo["cpu"+ this.cpuCoreArr[2] +"Frequency"] != undefined) { 191 192 ItemContent({ 193 icon: $r("app.media.icon_counter"), 194 value: (parseInt(this.tIndexInfo["cpu"+ this.cpuCoreArr[2] +"Frequency"].toString()) / 1e3).toString() + "MHz " + this.tIndexInfo.cpu2Load + "%", 195 tittle: "CPU-C频率", 196 onClickCallBack: () => { 197 this.floatWindowEvent("sp_cpu2Frequency", FloatWindowConstant.CPU2_FREQUENCY) 198 } 199 }) 200 } 201 202 if (this.tIndexInfo.gpuFrequency != undefined) { 203 ItemContent({ 204 icon: $r("app.media.icon_frame_score"), 205 value: (parseInt(this.tIndexInfo.gpuFrequency.toString()) / 1e6).toString() + "MHz " + this.tIndexInfo.gpuLoad + "%", 206 tittle: "GPU频点", 207 onClickCallBack: () => { 208 this.floatWindowEvent("sp_gpuFrequency", FloatWindowConstant.GPU_FREQUENCY) 209 } 210 }) 211 } 212 if (this.tIndexInfo.pss != undefined) { 213 ItemContent({ 214 icon: $r("app.media.icon_jank_each_hour"), 215 value: this.tIndexInfo.pss + "KB", 216 tittle: "RAM", 217 onClickCallBack: () => { 218 this.floatWindowEvent("sp_RAM", FloatWindowConstant.RAM) 219 } 220 }) 221 } 222 if (this.tIndexInfo.socThermalTemp != undefined) { 223 ItemContent({ 224 icon: $r("app.media.icon_max_temperature"), 225 value: (parseInt(this.tIndexInfo.socThermalTemp.toString()) / 1e3).toString() + "℃", 226 tittle: "SOC温度", 227 onClickCallBack: () => { 228 this.floatWindowEvent("sp_shellBackTemp", FloatWindowConstant.SHELL_BACK_TEMP) 229 } 230 }) 231 } 232 233 if (this.tIndexInfo.shellFrameTemp != undefined) { 234 ItemContent({ 235 icon: $r("app.media.icon_max_temperature"), 236 value: (parseInt(this.tIndexInfo.shellFrameTemp.toString()) / 1e3).toString() + "℃", 237 tittle: "壳温", 238 onClickCallBack: () => { 239 this.floatWindowEvent("sp_shellBackTemp", FloatWindowConstant.SHELL_BACK_TEMP) 240 } 241 }) 242 } 243 244 }.width('100%') 245 .gesture( 246 GestureGroup(GestureMode.Exclusive, 247 PanGesture({}) 248 .onActionStart((event: GestureEvent) => { 249 }) 250 .onActionUpdate((event: GestureEvent) => { 251 this.offsetX = event.offsetX 252 this.offsetY = event.offsetY 253 }) 254 .onActionEnd(() => { 255 this.MoveWindow(this.offsetX, this.offsetY) 256 this.SetWindowPosition(this.offsetX, this.offsetY) 257 }) 258 )) 259 } 260 } 261}