Преглед изворни кода

1、桌面卡片背景跟随封面;2、崩溃自定义页面

chendeben пре 1 година
родитељ
комит
7a893bd30e

+ 58 - 0
entry/src/main/ets/common/utils/CustomCrashHandler.ets

@@ -0,0 +1,58 @@
+import { hiAppEvent } from '@kit.PerformanceAnalysisKit';
+import { router } from '@kit.ArkUI';
+
+/**
+ * 自定义崩溃处理工具类
+ * 替代 spider-man 的默认崩溃页面,使用我们自定义的崩溃页面
+ */
+export class CustomCrashHandler {
+  
+  /**
+   * 初始化自定义崩溃处理,替代 spider-man 的默认行为
+   */
+  static init() {
+    // 添加自己的崩溃监听器
+    hiAppEvent.addWatcher({
+      name: 'CustomSpiderMan',
+      appEventFilters: [{
+        domain: hiAppEvent.domain.OS,
+        names: [hiAppEvent.event.APP_CRASH]
+      }],
+      onReceive: (domain: string, appEventGroups: Array<hiAppEvent.AppEventGroup>) => {
+        console.error('CustomCrashHandler onReceive -- ' + domain);
+
+        if (appEventGroups.length < 1) {
+          console.error('appEventGroups.length < 1');
+          return;
+        }
+
+        // 取第一个崩溃事件组
+        const appEventGroup = appEventGroups[0];
+        CustomCrashHandler.openCustomCrashPage(appEventGroup);
+      },
+    });
+  }
+
+  /**
+   * 打开自定义崩溃页面
+   */
+  static openCustomCrashPage(appEventGroup: hiAppEvent.AppEventGroup) {
+    setTimeout(() => {
+      router.pushNamedRoute({
+        name: 'CustomCrashPage',
+        params: appEventGroup
+      }).then(() => {
+        console.error('CustomCrashPage pushNamedRoute success');
+      }).catch(() => {
+        console.error('CustomCrashPage pushNamedRoute failed');
+        // 如果命名路由失败,尝试使用普通路由
+        router.pushUrl({
+          url: 'pages/CustomCrashPage',
+          params: appEventGroup
+        }).catch(() => {
+          console.error('CustomCrashPage pushUrl also failed');
+        });
+      });
+    }, 1000);
+  }
+}

+ 6 - 1
entry/src/main/ets/entryability/EntryAbility.ets

@@ -20,6 +20,7 @@ import { UnifiedPlayerService } from '../common/service/UnifiedPlayerService';
 import { WidgetRegistrationFix } from '../common/widget/WidgetRegistrationFix';
 import { systemShare } from '@kit.ShareKit';
 import { SpiderMan } from '@simplepeng/spider-man';
+import { CustomCrashHandler } from '../common/utils/CustomCrashHandler';
 import { smartMobilityCommon } from '@kit.CarKit';
 
 
@@ -264,7 +265,11 @@ export default class EntryAbility extends UIAbility {
     onWindowStageCreate(windowStage: window.WindowStage) {
         // Main window is created, set main page for this ability
         hilog.info(0x0000, 'Heanup2', '%{public}s', 'Ability onWindowStageCreate');
-        SpiderMan.init();
+        
+        // 使用自定义崩溃处理器替代 SpiderMan.init()
+        // SpiderMan.init();
+        CustomCrashHandler.init();
+        
         AppUtil.init(this.context);
 
         //1.获取应用主窗口。

+ 196 - 0
entry/src/main/ets/pages/CustomCrashPage.ets

@@ -0,0 +1,196 @@
+import { hiAppEvent } from '@kit.PerformanceAnalysisKit';
+import { ComposeTitleBar, router } from '@kit.ArkUI';
+import { bundleManager } from '@kit.AbilityKit';
+import { BusinessError, deviceInfo } from '@kit.BasicServicesKit';
+
+@Entry({ routeName: 'CustomCrashPage' })
+@Component
+export struct CustomCrashPage {
+  eventGroup?: hiAppEvent.AppEventGroup = router.getParams() as hiAppEvent.AppEventGroup
+  eventInfoList: Array<hiAppEvent.AppEventInfo> = this.eventGroup?.appEventInfos ?? []
+  @StorageProp('topRectHeight')topRectHeight: number =0;
+  build() {
+    Column() {
+      ComposeTitleBar({ title: 'Crash Info' })
+        .width('100%')
+        .padding({top:this.topRectHeight})
+      Swiper() {
+        ForEach(this.eventGroup?.appEventInfos, (eventInfo: hiAppEvent.AppEventInfo) => {
+          SwiperPage({
+            eventInfo: eventInfo
+          })
+        })
+      }
+      .width('100%')
+      .layoutWeight(1)
+      .indicator(this.eventInfoList.length > 1)
+      .effectMode(EdgeEffect.None)
+      .loop(false)
+    }
+    .width('100%')
+    .height('100%')
+  }
+}
+
+@Component
+export struct SwiperPage {
+  @Prop eventInfo: hiAppEvent.AppEventInfo
+  //
+  @State deviceType: string = ''
+  @State marketName: string = ''
+  @State displayVersion: string = ''
+  @State osFullName: string = ''
+  @State abiList: string = ''
+  @State ODID: string = ''
+  @State sdkApiVersion: string = ''
+  //
+  @State version: string = ''
+  @State versionCode: string = ''
+  @State releaseType: string = ''
+  @State appProvisionType: string = ''
+
+  build() {
+    Scroll() {
+      Column({ space: 10 }) {
+        Item({ type: '发生崩溃了', message: '请把该界面截图发送到开发者邮箱:app@97admin.com,以便开发者更快修复。谢谢!' })
+        Item({ type: 'marketName', message: this.marketName })
+        Item({ type: 'bundle_name', message: this.eventInfo.params['bundle_name'] })
+        // Item({ type: 'abiList', message: this.abiList })
+        // Item({ type: 'sdkApiVersion', message: this.sdkApiVersion })
+        // Item({ type: 'ODID', message: this.ODID })
+        Divider()
+        Item({ type: 'Error name', message: this.eventInfo.params['exception'].name })
+        Item({ type: 'Error message', message: this.eventInfo.params['exception'].message })
+        Item2({ type: 'Stacktrace', message: this.eventInfo.params['exception'].stack })
+        //
+        // Item({ type: 'version', message: this.version })
+        // Item({ type: 'versionCode', message: this.versionCode })
+        // Item({ type: 'releaseType', message: this.releaseType })
+        // Item({ type: 'appProvisionType', message: this.appProvisionType })
+        Divider()
+        //
+        // Item({ type: 'domain', message: this.eventInfo.domain })
+        Item({ type: 'name', message: this.eventInfo.name })
+        // Item({ type: 'event_type', message: this.eventInfo.eventType.toString() })
+        // Item({ type: 'time', message: this.eventInfo.params['time'] })
+        Item({ type: 'crash_type', message: this.eventInfo.params['crash_type'] })
+        // Item({ type: 'foreground', message: this.eventInfo.params['foreground'] })
+        Item({ type: 'bundle_version', message: this.eventInfo.params['bundle_version'] })
+        Item({ type: 'deviceType', message: this.deviceType })
+        // Item({ type: 'pid', message: this.eventInfo.params['pid'] })
+        // Item({ type: 'uid', message: this.eventInfo.params['uid'] })
+        // Item({ type: 'uuid', message: this.eventInfo.params['uuid'] })
+        // Item2({ type: 'exception', message: JSON.stringify(this.eventInfo.params['exception']) })
+        // Item({ type: 'external_log', message: this.eventInfo.params['external_log'] })
+
+      }
+      .alignItems(HorizontalAlign.Start)
+      .justifyContent(FlexAlign.Start)
+      .width('100%')
+      .height('100%')
+    }
+    .width('100%')
+    .height(1024)
+    .scrollable(ScrollDirection.Vertical)
+    .padding({ left: 10, right: 10 })
+  }
+
+  getDeviceInfo() {
+    this.deviceType = deviceInfo.deviceType
+    this.marketName = deviceInfo.marketName
+    this.displayVersion = deviceInfo.displayVersion
+    this.osFullName = deviceInfo.osFullName
+    this.abiList = deviceInfo.abiList
+    this.sdkApiVersion = deviceInfo.sdkApiVersion.toString()
+    this.ODID = deviceInfo.ODID
+  }
+
+  logDeviceInfo() {
+    console.error('deviceType is ' + deviceInfo.deviceType) //phone
+    console.error('manufacture is ' + deviceInfo.manufacture)
+    console.error('brand is ' + deviceInfo.brand)
+    console.error('marketName is ' + deviceInfo.marketName) //HUAWEI Mate 60 Pro
+    console.error('productSeries is ' + deviceInfo.productSeries)
+    console.error('productModel is ' + deviceInfo.productModel)
+    console.error('softwareModel is ' + deviceInfo.softwareModel)
+    console.error('hardwareModel is ' + deviceInfo.hardwareModel)
+    console.error('hardwareProfile is ' + deviceInfo.hardwareProfile)
+    console.error('serial is ' + deviceInfo.serial)
+    console.error('bootloaderVersion is ' + deviceInfo.bootloaderVersion)
+    console.error('abiList is ' + deviceInfo.abiList) //arm64-v8a
+    console.error('securityPatchTag is ' + deviceInfo.securityPatchTag)
+    console.error('displayVersion is ' + deviceInfo.displayVersion) //ALN-AL80 5.0.0.60(SP12DEVC00E61R4P9log)
+    console.error('incrementalVersion is ' + deviceInfo.incrementalVersion)
+    console.error('osReleaseType is ' + deviceInfo.osReleaseType) //Beta5
+    console.error('osFullName is ' + deviceInfo.osFullName) //OpenHarmony-5.0.0.60(Beta5)
+    console.error('versionId is ' + deviceInfo.versionId)
+    console.error('buildType is ' + deviceInfo.buildType)
+    console.error('buildUser is ' + deviceInfo.buildUser)
+    console.error('buildHost is ' + deviceInfo.buildHost)
+    console.error('buildTime is ' + deviceInfo.buildTime)
+    console.error('buildRootHash is ' + deviceInfo.buildRootHash)
+    console.error('udid is ' + deviceInfo.udid)
+    console.error('distributionOSName is ' + deviceInfo.distributionOSName)
+    console.error('distributionOSVersion is ' + deviceInfo.distributionOSVersion) //5.0.0
+    console.error('distributionOSReleaseType is ' + deviceInfo.distributionOSReleaseType) //Beta5
+    console.error('ODID is ' + deviceInfo.ODID) //e363fbb5-ab56-01ab-bee1-1b8c6f6a054c
+    console.error('majorVersion is ' + deviceInfo.majorVersion)
+    console.error('seniorVersion is ' + deviceInfo.seniorVersion)
+    console.error('featureVersion is ' + deviceInfo.featureVersion)
+    console.error('buildVersion is ' + deviceInfo.buildVersion)
+    console.error('sdkApiVersion is ' + deviceInfo.sdkApiVersion) //12
+    console.error('firstApiVersion is ' + deviceInfo.firstApiVersion)
+    console.error('distributionOSApiVersion is ' + deviceInfo.distributionOSApiVersion)
+  }
+
+  getBundleInfo() {
+    bundleManager.getBundleInfoForSelf(bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION).then((bundleInfo) => {
+      this.version = bundleInfo.versionName
+      this.versionCode = bundleInfo.versionCode.toString()
+      bundleInfo.minCompatibleVersionCode
+      bundleInfo.targetVersion
+      this.releaseType = bundleInfo.appInfo.releaseType
+      this.appProvisionType = bundleInfo.appInfo.appProvisionType // debug
+    }).catch((error: BusinessError) => {
+      console.error("get bundleInfo failed,error is " + error)
+    })
+  }
+
+  aboutToAppear(): void {
+    this.getDeviceInfo()
+    this.getBundleInfo()
+  }
+}
+
+@Component
+export struct Item {
+  @Prop type: string
+  @Prop message: string
+
+  build() {
+    Row() {
+      Text(`${this.type}: `)
+        .fontColor('#cbcbcb')
+      Text(this.message)
+        .fontColor('#e71e62')
+        .layoutWeight(1)
+    }
+    .alignItems(VerticalAlign.Top)
+  }
+}
+
+@Component
+export struct Item2 {
+  @Prop type: string
+  @Prop message: string
+
+  build() {
+    Column({ space: 5 }) {
+      Text(`${this.type}: `)
+        .fontColor('#cbcbcb')
+      Text(this.message)
+        .fontColor('#e71e62')
+    }
+    .alignItems(HorizontalAlign.Start)
+  }
+}

+ 3 - 5
entry/src/main/ets/widget/pages/PlayerWidgetMedium.ets

@@ -355,12 +355,10 @@ struct PlayerWidgetMedium {
     }
     .height('100%')
     .width('100%')
-    .linearGradient({
-      direction: GradientDirection.Bottom,
-      repeating: false,
-      colors: this.generateGradientColors()
-    })
     .padding(12)
+    .backgroundImage(this.getCoverImage())
+    .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
+    .backgroundImageSize(ImageSize.Cover)
     .onClick(() => {
       console.info('Heanup PlayerWidgetMedium: Container clicked, jumping to main app');
       postCardAction(this, {

+ 3 - 5
entry/src/main/ets/widget/pages/PlayerWidgetSquare.ets

@@ -153,12 +153,10 @@ struct PlayerWidgetSquare {
     }
     .height('100%')
     .width('100%')
-    .linearGradient({
-      direction: GradientDirection.Bottom,
-      repeating: false,
-      colors: [[`#ff${this.imageColorHex}`, 0.0], [`#ff${this.imageColorHex}`, 0.5], [`#ff${this.imageColorHex}`, 1.0]]
-    })
     .padding(12)
+    .backgroundImage(this.getCoverImage())
+    .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
+    .backgroundImageSize(ImageSize.Cover)
     .onClick(() => {
       console.info('Heanup PlayerWidgetSquare: Container clicked, jumping to main app');
       postCardAction(this, {

+ 2 - 1
entry/src/main/resources/base/profile/main_pages.json

@@ -6,6 +6,7 @@
     "pages/NewIndex",
     "pages/VerifyPage",
     "pages/VipPage",
-    "pages/Demo"
+    "pages/Demo",
+    "pages/CustomCrashPage"
   ]
 }