| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  | import UIAbility from '@ohos.app.ability.UIAbility'; | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  | import hilog from '@ohos.hilog'; | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  | import window from '@ohos.window'; | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  | import { GlobalConfig } from '../config/global'; | 
					
						
							|  |  |  | import Want from '@ohos.app.ability.Want'; | 
					
						
							|  |  |  | import AbilityConstant from '@ohos.app.ability.AbilityConstant'; | 
					
						
							|  |  |  | import { BaseInfoType, CarInfoType, EnvironmentConfigurationType, ExaminerInfoType } from '../model'; | 
					
						
							|  |  |  | import DB from '../utils/DbSql'; | 
					
						
							|  |  |  | import { DrivingDataStorage } from '../utils/business/DrivingDataStorage'; | 
					
						
							|  |  |  | import { InitTable } from '../utils/table/Operation'; | 
					
						
							|  |  |  | import FileUtils from '../utils/FileUtils'; | 
					
						
							| 
									
										
										
										
											2025-04-28 15:51:50 +08:00
										 |  |  | import { EntryTag } from '../config'; | 
					
						
							| 
									
										
										
										
											2025-06-23 17:08:25 +08:00
										 |  |  | import { dConsole } from '../utils/LogWorker'; | 
					
						
							| 
									
										
										
										
											2025-06-25 10:35:33 +08:00
										 |  |  | import { UseAuth } from '../utils/Common'; | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | export default class EntryAbility extends UIAbility { | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |   async onCreate(want: Want, launchParam: AbilityConstant.LaunchParam) { | 
					
						
							| 
									
										
										
										
											2025-04-28 15:51:50 +08:00
										 |  |  |     console.log(EntryTag, "多伦鸿蒙车载程序启动") | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |     try { | 
					
						
							|  |  |  |       await DB.init(this.context) | 
					
						
							|  |  |  |       await InitTable() | 
					
						
							|  |  |  |       let fileUtil = new FileUtils(this.context) | 
					
						
							| 
									
										
										
										
											2025-04-14 14:35:18 +08:00
										 |  |  |       // 一些地址配置 | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |       const data = await fileUtil.readFile(GlobalConfig.commonFileWriteAddress + '/config/ipConfig.txt'); | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |       if (data !== '' && data !== undefined) { | 
					
						
							|  |  |  |         const result: EnvironmentConfigurationType = JSON.parse(data) | 
					
						
							|  |  |  |         AppStorage.setOrCreate<EnvironmentConfigurationType>("EnvironmentConfiguration", result) | 
					
						
							| 
									
										
										
										
											2025-06-25 10:35:33 +08:00
										 |  |  |         if (result.isOpenLog) { | 
					
						
							| 
									
										
										
										
											2025-06-23 17:08:25 +08:00
										 |  |  |           dConsole.init(result.isOpenLog) | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-04-14 14:35:18 +08:00
										 |  |  |         const host = `http://${result.centerIp}:${result.centerPort}` | 
					
						
							|  |  |  |         AppStorage.setOrCreate<string>("host", host) | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } catch (e) { | 
					
						
							| 
									
										
										
										
											2025-04-28 15:51:50 +08:00
										 |  |  |       console.error(EntryTag, 'sql first error', e) | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-04-28 15:51:50 +08:00
										 |  |  |     console.log(EntryTag, "onCreate", "加载完成") | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |   onDestroy() { | 
					
						
							|  |  |  |     const arrClose = [0x55, 0xaa, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00] | 
					
						
							|  |  |  |     // TODO UDP缺失 | 
					
						
							|  |  |  |     // lightUDPClient.sendMsg(new Uint8Array(arrClose).buffer) | 
					
						
							|  |  |  |     DrivingDataStorage.close() | 
					
						
							| 
									
										
										
										
											2025-04-28 15:51:50 +08:00
										 |  |  |     console.log(EntryTag, "onDestroy", "销毁完成") | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |   async onWindowStageCreate(windowStage: window.WindowStage) { | 
					
						
							| 
									
										
										
										
											2025-04-28 15:51:50 +08:00
										 |  |  |     console.log(EntryTag, "onWindowStageCreate", "窗口创建完成") | 
					
						
							| 
									
										
										
										
											2025-06-25 10:35:33 +08:00
										 |  |  |     await UseAuth(this.context) | 
					
						
							| 
									
										
										
										
											2025-04-10 15:10:31 +08:00
										 |  |  |     const windowClass = await windowStage.getMainWindow(); | 
					
						
							|  |  |  |     let rect = windowClass.getWindowProperties().windowRect | 
					
						
							|  |  |  |     let width = rect.width | 
					
						
							|  |  |  |     let height = rect.height | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |     AppStorage.setOrCreate<CarInfoType>('carInfo', {}) | 
					
						
							|  |  |  |     AppStorage.setOrCreate<ExaminerInfoType>('examinerInfo', {}) | 
					
						
							|  |  |  |     AppStorage.setOrCreate<string>('lsh', '0000000000000') | 
					
						
							|  |  |  |     AppStorage.setOrCreate<string>('statue', "1") //考试状态 | 
					
						
							|  |  |  |     AppStorage.setOrCreate<number>('signNum', 0) //心跳指令编号 | 
					
						
							|  |  |  |     AppStorage.setOrCreate<string>('deviceNo', "") //设备号 | 
					
						
							|  |  |  |     AppStorage.setOrCreate<BaseInfoType>('baseInfo', { | 
					
						
							|  |  |  |       hasAuth: false, | 
					
						
							| 
									
										
										
										
											2025-04-15 10:16:33 +08:00
										 |  |  |       version: GlobalConfig.version.sz.km2[0] || "", | 
					
						
							|  |  |  |       judgeVersion: GlobalConfig.version.sz.km2[1] || "", | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |       tcpSendNum: 0, | 
					
						
							|  |  |  |       videoVersion: '1.0', | 
					
						
							| 
									
										
										
										
											2025-04-10 15:10:31 +08:00
										 |  |  |       ratio: width / height, //适配比例 | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |       pathDir: this.context.filesDir, | 
					
						
							|  |  |  |       context: this.context, | 
					
						
							|  |  |  |       isJudgeInitBool: false, | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AppStorage.setOrCreate('windowClass', windowClass) | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |     await windowClass.setWindowLayoutFullScreen(true) | 
					
						
							| 
									
										
										
										
											2025-04-15 10:16:33 +08:00
										 |  |  |     // await windowClass.setWindowSystemBarEnable([]) //全屏 | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |     windowStage.loadContent('pages/Index', (err, data) => { | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |       if (err.code) { | 
					
						
							|  |  |  |         hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |       hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? ''); | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |     this.createFiles(); | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |   onWindowStageDestroy() { | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |     // Main window is destroyed, release UI related resources | 
					
						
							| 
									
										
										
										
											2025-04-28 15:51:50 +08:00
										 |  |  |     console.log(EntryTag, "onWindowStageDestroy", "窗口销毁完成") | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |   onForeground() { | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |     // Ability has brought to foreground | 
					
						
							| 
									
										
										
										
											2025-04-28 15:51:50 +08:00
										 |  |  |     console.log(EntryTag, "onForeground", "当应用从后台转到前台时触发") | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |   onBackground() { | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |     // Ability has back to background | 
					
						
							| 
									
										
										
										
											2025-04-28 15:51:50 +08:00
										 |  |  |     console.log(EntryTag, "onBackground", "当应用从前台转到后台时触发") | 
					
						
							| 
									
										
										
										
											2025-04-10 09:30:47 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-11 15:48:18 +08:00
										 |  |  |   createFiles() { | 
					
						
							| 
									
										
										
										
											2025-04-28 15:51:50 +08:00
										 |  |  |     console.log(EntryTag, "createFiles", "创建文件") | 
					
						
							| 
									
										
										
										
											2025-04-10 10:27:28 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } |