@@ -11,6 +11,24 @@ import { util } from '@kit.ArkTS';
1111
1212const TAG = 'PushyTurboModule' ;
1313
14+ export function getErrorMessage ( error : any ) : string {
15+ if ( error && typeof error === 'object' && 'message' in error ) {
16+ return String ( error . message ) ;
17+ }
18+ return String ( error ) ;
19+ }
20+
21+ export function validateHashInfo ( info : string ) : void {
22+ try {
23+ const parsed = JSON . parse ( info ) ;
24+ if ( ! parsed || typeof parsed !== 'object' || Array . isArray ( parsed ) ) {
25+ throw Error ( 'invalid json string' ) ;
26+ }
27+ } catch {
28+ throw Error ( 'invalid json string' ) ;
29+ }
30+ }
31+
1432export class PushyTurboModule extends UITurboModule {
1533 public static readonly NAME = 'Pushy' ;
1634
@@ -29,13 +47,6 @@ export class PushyTurboModule extends UITurboModule {
2947 return bundleManager . BundleFlag . GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION ;
3048 }
3149
32- private getErrorMessage ( error : any ) : string {
33- if ( error && typeof error === 'object' && 'message' in error ) {
34- return String ( error . message ) ;
35- }
36- return String ( error ) ;
37- }
38-
3950 private getPackageVersion ( ) : string {
4051 try {
4152 const bundleInfo = bundleManager . getBundleInfoForSelfSync (
@@ -70,17 +81,6 @@ export class PushyTurboModule extends UITurboModule {
7081 return hash ;
7182 }
7283
73- private validateHashInfo ( info : string ) : void {
74- try {
75- const parsed = JSON . parse ( info ) ;
76- if ( ! parsed || typeof parsed !== 'object' || Array . isArray ( parsed ) ) {
77- throw Error ( 'invalid json string' ) ;
78- }
79- } catch {
80- throw Error ( 'invalid json string' ) ;
81- }
82- }
83-
8484 private async restartAbility ( ) : Promise < void > {
8585 const bundleInfo = await bundleManager . getBundleInfoForSelf (
8686 this . getBundleFlags ( ) ,
@@ -127,14 +127,14 @@ export class PushyTurboModule extends UITurboModule {
127127
128128 setLocalHashInfo ( hash : string , info : string ) : boolean {
129129 logger . debug ( TAG , ',call setLocalHashInfo' ) ;
130- this . validateHashInfo ( info ) ;
130+ validateHashInfo ( info ) ;
131131 this . context . setKv ( `hash_${ hash } ` , info ) ;
132132 return true ;
133133 }
134134
135135 getLocalHashInfo ( hash : string ) : string {
136136 const value = this . context . getKv ( `hash_${ hash } ` ) ;
137- this . validateHashInfo ( value ) ;
137+ validateHashInfo ( value ) ;
138138 return value ;
139139 }
140140
@@ -151,8 +151,8 @@ export class PushyTurboModule extends UITurboModule {
151151 this . context . switchVersion ( hash ) ;
152152 await this . restartAbility ( ) ;
153153 } catch ( error ) {
154- logger . error ( TAG , `reloadUpdate failed: ${ this . getErrorMessage ( error ) } ` ) ;
155- throw Error ( `switchVersion failed ${ this . getErrorMessage ( error ) } ` ) ;
154+ logger . error ( TAG , `reloadUpdate failed: ${ getErrorMessage ( error ) } ` ) ;
155+ throw Error ( `switchVersion failed ${ getErrorMessage ( error ) } ` ) ;
156156 }
157157 }
158158
@@ -161,8 +161,8 @@ export class PushyTurboModule extends UITurboModule {
161161 try {
162162 await this . restartAbility ( ) ;
163163 } catch ( error ) {
164- logger . error ( TAG , `restartApp failed: ${ this . getErrorMessage ( error ) } ` ) ;
165- throw Error ( `restartApp failed ${ this . getErrorMessage ( error ) } ` ) ;
164+ logger . error ( TAG , `restartApp failed: ${ getErrorMessage ( error ) } ` ) ;
165+ throw Error ( `restartApp failed ${ getErrorMessage ( error ) } ` ) ;
166166 }
167167 }
168168
0 commit comments