xugenyuan

ref |> 冷启动优化

1、lazy加载语音识别库
2、调整启动时加载占用时长较大的调用

Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
@@ -49,6 +49,7 @@ @@ -49,6 +49,7 @@
49 "signingConfig": "default", 49 "signingConfig": "default",
50 "compileSdkVersion": "5.0.0(12)", 50 "compileSdkVersion": "5.0.0(12)",
51 "compatibleSdkVersion": "5.0.0(12)", 51 "compatibleSdkVersion": "5.0.0(12)",
  52 + "compatibleSdkVersionStage": "beta3",
52 "runtimeOS": "HarmonyOS", 53 "runtimeOS": "HarmonyOS",
53 "buildOption": { 54 "buildOption": {
54 "arkOptions": { 55 "arkOptions": {
@@ -64,6 +65,7 @@ @@ -64,6 +65,7 @@
64 "signingConfig": "release", 65 "signingConfig": "release",
65 "compileSdkVersion": "5.0.0(12)", 66 "compileSdkVersion": "5.0.0(12)",
66 "compatibleSdkVersion": "5.0.0(12)", 67 "compatibleSdkVersion": "5.0.0(12)",
  68 + "compatibleSdkVersionStage": "beta3",
67 "runtimeOS": "HarmonyOS", 69 "runtimeOS": "HarmonyOS",
68 "buildOption": { 70 "buildOption": {
69 "arkOptions": { 71 "arkOptions": {
@@ -5,6 +5,7 @@ import { AccountManagerUtils } from '../utils/AccountManagerUtils'; @@ -5,6 +5,7 @@ import { AccountManagerUtils } from '../utils/AccountManagerUtils';
5 import { UserDataLocal } from '../utils/UserDataLocal'; 5 import { UserDataLocal } from '../utils/UserDataLocal';
6 import { EmitterUtils } from '../utils/EmitterUtils'; 6 import { EmitterUtils } from '../utils/EmitterUtils';
7 import { EmitterEventId } from '../utils/EmitterEventId'; 7 import { EmitterEventId } from '../utils/EmitterEventId';
  8 +import { Logger } from '../utils/Logger';
8 9
9 export class UmengStats { 10 export class UmengStats {
10 11
@@ -17,7 +18,7 @@ export class UmengStats { @@ -17,7 +18,7 @@ export class UmengStats {
17 preInit({ 18 preInit({
18 context: context.getApplicationContext(), 19 context: context.getApplicationContext(),
19 plugins: [new InternalPlugin()], 20 plugins: [new InternalPlugin()],
20 - enableLog: true 21 + enableLog: Logger.isDebug
21 22
22 }); 23 });
23 } 24 }
@@ -75,10 +75,19 @@ export class CacheData { @@ -75,10 +75,19 @@ export class CacheData {
75 }) 75 })
76 } 76 }
77 77
78 - static getNetworkData(data: CacheData): string { 78 + static getNetworkDataSync(data: CacheData): string {
79 if (data.networkData) { 79 if (data.networkData) {
80 return JSON.stringify(data.networkData); 80 return JSON.stringify(data.networkData);
81 } 81 }
82 return ""; 82 return "";
83 } 83 }
  84 + static getNetworkDataAsync(data: CacheData): Promise<string> {
  85 + return new Promise((resolve) => {
  86 + let string = ""
  87 + if (data.networkData) {
  88 + string = JSON.stringify(data.networkData);
  89 + }
  90 + resolve(string)
  91 + })
  92 + }
84 } 93 }
@@ -3,7 +3,7 @@ import { LottieView } from '../../lottie/LottieView' @@ -3,7 +3,7 @@ import { LottieView } from '../../lottie/LottieView'
3 import lottie from '@ohos/lottie'; 3 import lottie from '@ohos/lottie';
4 import { CommonConstants } from 'wdConstant'; 4 import { CommonConstants } from 'wdConstant';
5 import { common} from '@kit.AbilityKit'; 5 import { common} from '@kit.AbilityKit';
6 -import { VoiceRecoginizer } from 'wdHwAbility/src/main/ets/voiceRecognizer/VoiceRecoginizer'; 6 +import { VoiceRecoginizer } from 'wdHwAbility';
7 7
8 @Component 8 @Component
9 export struct VoiceInputView { 9 export struct VoiceInputView {
@@ -42,8 +42,10 @@ export class ChannelViewModel { @@ -42,8 +42,10 @@ export class ChannelViewModel {
42 CacheData.getLocalCacheData(CacheData.bottomCacheKey).then((data) => { 42 CacheData.getLocalCacheData(CacheData.bottomCacheKey).then((data) => {
43 // Logger.debug(TAG, 'getBottomNavCacheData 333 ' + JSON.stringify(data)); 43 // Logger.debug(TAG, 'getBottomNavCacheData 333 ' + JSON.stringify(data));
44 if (data) { 44 if (data) {
45 - let navBean = JSON.parse(CacheData.getNetworkData(data)) as NavigationBodyDTO  
46 - success(navBean) 45 + CacheData.getNetworkDataAsync(data).then((json) => {
  46 + let navBean = JSON.parse(json) as NavigationBodyDTO
  47 + success(navBean)
  48 + })
47 } else { 49 } else {
48 success(null) 50 success(null)
49 } 51 }
@@ -68,8 +70,10 @@ export class ChannelViewModel { @@ -68,8 +70,10 @@ export class ChannelViewModel {
68 return new Promise<NavigationDetailDTO | null>((success) => { 70 return new Promise<NavigationDetailDTO | null>((success) => {
69 CacheData.getLocalCacheData(CacheData.channelCacheDataKey + id).then((data) => { 71 CacheData.getLocalCacheData(CacheData.channelCacheDataKey + id).then((data) => {
70 if (data) { 72 if (data) {
71 - let navBean = JSON.parse(CacheData.getNetworkData(data)) as NavigationDetailDTO  
72 - success(navBean) 73 + CacheData.getNetworkDataAsync(data).then((json) => {
  74 + let navBean = JSON.parse(json) as NavigationDetailDTO
  75 + success(navBean)
  76 + })
73 } else { 77 } else {
74 success(null) 78 success(null)
75 } 79 }
@@ -367,8 +367,10 @@ export class PageViewModel extends BaseViewModel { @@ -367,8 +367,10 @@ export class PageViewModel extends BaseViewModel {
367 CacheData.getLocalCacheData(CacheData.comPageInfoCacheKey + pageId).then((data) => { 367 CacheData.getLocalCacheData(CacheData.comPageInfoCacheKey + pageId).then((data) => {
368 // Logger.debug(TAG, 'getPageInfoCache 333 ' + JSON.stringify(data)); 368 // Logger.debug(TAG, 'getPageInfoCache 333 ' + JSON.stringify(data));
369 if (data) { 369 if (data) {
370 - let navBean = JSON.parse(CacheData.getNetworkData(data)) as PageInfoDTO  
371 - success(navBean) 370 + CacheData.getNetworkDataAsync(data).then((json) => {
  371 + let navBean = JSON.parse(json) as PageInfoDTO
  372 + success(navBean)
  373 + })
372 } else { 374 } else {
373 success(null) 375 success(null)
374 } 376 }
@@ -391,8 +393,10 @@ export class PageViewModel extends BaseViewModel { @@ -391,8 +393,10 @@ export class PageViewModel extends BaseViewModel {
391 .then((data) => { 393 .then((data) => {
392 // Logger.debug(TAG, 'getPageGroupCacheData 333 ' + JSON.stringify(data)); 394 // Logger.debug(TAG, 'getPageGroupCacheData 333 ' + JSON.stringify(data));
393 if (data) { 395 if (data) {
394 - let navBean = JSON.parse(CacheData.getNetworkData(data)) as PageDTO  
395 - success(navBean) 396 + CacheData.getNetworkDataAsync(data).then((json) => {
  397 + let navBean = JSON.parse(json) as PageDTO
  398 + success(navBean)
  399 + })
396 } else { 400 } else {
397 success(null) 401 success(null)
398 } 402 }
1 import { audio } from '@kit.AudioKit' 1 import { audio } from '@kit.AudioKit'
2 import { ArkTSUtils } from '@kit.ArkTS' 2 import { ArkTSUtils } from '@kit.ArkTS'
3 -import {getVoicebufferDataLengthByte} from 'neonui' 3 +import lazy {getVoicebufferDataLengthByte} from 'neonui'
4 import process from '@ohos.process' 4 import process from '@ohos.process'
5 -import { NativeNui } from 'neonui' 5 +import lazy { NativeNui } from 'neonui'
6 6
7 let TAG:string = "AudioCapturer" 7 let TAG:string = "AudioCapturer"
8 //音频采集器类,主要用于采集音频,写入文件 8 //音频采集器类,主要用于采集音频,写入文件
1 1
2 -import {NativeNui,Constants,MapToJson,INativeNuiCallback, AsrResult, KwsResult} from 'neonui' 2 +import lazy {NativeNui,Constants,MapToJson,INativeNuiCallback, AsrResult, KwsResult} from 'neonui'
3 import { PermissionUtils,DeviceUtil, Logger, DateTimeUtils } from 'wdKit'; 3 import { PermissionUtils,DeviceUtil, Logger, DateTimeUtils } from 'wdKit';
4 import AudioCapturer from './AudioCapture'; 4 import AudioCapturer from './AudioCapture';
5 import { common, Permissions } from '@kit.AbilityKit'; 5 import { common, Permissions } from '@kit.AbilityKit';
@@ -71,14 +71,20 @@ export default class HuaweiAuth { @@ -71,14 +71,20 @@ export default class HuaweiAuth {
71 return; 71 return;
72 } 72 }
73 73
74 - Logger.info(TAG, 'get anonymousPhone is empty. ' + JSON.stringify(response)); 74 + Logger.infoOptimize(TAG, () => {
  75 + return 'get anonymousPhone is empty. ' + JSON.stringify(response)
  76 + });
75 fail("获取匿名手机号为空") 77 fail("获取匿名手机号为空")
76 }).catch((err: BusinessError) => { 78 }).catch((err: BusinessError) => {
77 - Logger.error(TAG, 'get anonymousPhone failed. ' + JSON.stringify(err)); 79 + Logger.errorOptimize(TAG, () => {
  80 + return 'get anonymousPhone failed. ' + JSON.stringify(err)
  81 + })
78 fail("获取匿名手机号失败") 82 fail("获取匿名手机号失败")
79 }) 83 })
80 } catch (err) { 84 } catch (err) {
81 - Logger.error(TAG, 'get anonymousPhone fail. ' + JSON.stringify(err)); 85 + Logger.errorOptimize(TAG, () => {
  86 + return 'get anonymousPhone fail. ' + JSON.stringify(err)
  87 + })
82 fail("获取匿名手机号失败") 88 fail("获取匿名手机号失败")
83 } 89 }
84 }) 90 })
@@ -63,15 +63,14 @@ struct MainPage { @@ -63,15 +63,14 @@ struct MainPage {
63 } 63 }
64 64
65 setTimeout(() => { 65 setTimeout(() => {
66 - // 这里延后,因为有可能是换端进入H5页面  
67 - setTimeout(() => {  
68 - StartupManager.sharedInstance().appReachMainPage()  
69 - }, 200)  
70 -  
71 webview.WebviewController.initializeWebEngine() 66 webview.WebviewController.initializeWebEngine()
72 ComponentModule.preInitArticleWebTemplate(this.getUIContext()) 67 ComponentModule.preInitArticleWebTemplate(this.getUIContext())
  68 + }, 1000)
  69 + // 这里延后,因为有可能是换端进入H5页面
  70 + setTimeout(() => {
  71 + StartupManager.sharedInstance().appReachMainPage()
  72 + }, 700)
73 73
74 - }, 500)  
75 } 74 }
76 75
77 pageTransition() { 76 pageTransition() {