1- import { TurboModule , TurboModuleContext } from '@rnoh/react-native-openharmony/ts' ;
1+ import {
2+ TurboModule ,
3+ TurboModuleContext ,
4+ } from '@rnoh/react-native-openharmony/ts' ;
25import common from '@ohos.app.ability.common' ;
36import dataPreferences from '@ohos.data.preferences' ;
47import { bundleManager } from '@kit.AbilityKit' ;
5- import abilityAccessCtrl , { Permissions } from '@ohos.abilityAccessCtrl' ;
6- import { BusinessError } from '@ohos.base' ;
78import logger from './Logger' ;
89import { UpdateModuleImpl } from './UpdateModuleImpl' ;
910import { UpdateContext } from './UpdateContext' ;
@@ -23,50 +24,60 @@ export class PushyTurboModule extends TurboModule {
2324 EventHub . getInstance ( ) . setRNInstance ( ctx . rnInstance ) ;
2425 }
2526
26-
27- getConstants ( ) : Object {
28- logger . debug ( TAG , ',call getConstants' ) ;
29- const context = this . mUiCtx ;
30- const preferencesManager = dataPreferences . getPreferencesSync ( context , { name : 'update' } ) ;
31- const isFirstTime = preferencesManager . getSync ( 'isFirstTime' , false ) as boolean ;
32- const rolledBackVersion = preferencesManager . getSync ( 'rolledBackVersion' , '' ) as string ;
33- const uuid = preferencesManager . getSync ( 'uuid' , '' ) as string ;
34- const currentVersion = preferencesManager . getSync ( 'currentVersion' , '' ) as string ;
35- const currentVersionInfo = this . context . getKv ( `hash_${ currentVersion } ` ) ;
36- const buildTime = preferencesManager . getSync ( 'buildTime' , '' ) as string ;
37- const isUsingBundleUrl = this . context . getIsUsingBundleUrl ( ) ;
38- let bundleFlags = bundleManager . BundleFlag . GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION ;
39- let packageVersion = '' ;
40- try {
41- const bundleInfo = bundleManager . getBundleInfoForSelfSync ( bundleFlags ) ;
42- packageVersion = bundleInfo ?. versionName || 'Unknown' ;
43- } catch ( error ) {
44- console . error ( 'Failed to get bundle info:' , error ) ;
45- }
46-
47- if ( isFirstTime ) {
48- preferencesManager . deleteSync ( 'isFirstTime' ) ;
49- }
50-
51- if ( rolledBackVersion ) {
52- preferencesManager . deleteSync ( 'rolledBackVersion' ) ;
53- }
54-
55- return {
56- downloadRootDir : `${ context . filesDir } /_update` ,
57- currentVersionInfo,
58- packageVersion,
59- currentVersion,
60- buildTime,
61- isUsingBundleUrl,
62- isFirstTime,
63- rolledBackVersion,
64- uuid,
65- } ;
66- }
67-
68-
69- setLocalHashInfo ( hash : string , info : string ) : boolean {
27+ getConstants ( ) : Object {
28+ logger . debug ( TAG , ',call getConstants' ) ;
29+ const context = this . mUiCtx ;
30+ const preferencesManager = dataPreferences . getPreferencesSync ( context , {
31+ name : 'update' ,
32+ } ) ;
33+ const isFirstTime = preferencesManager . getSync (
34+ 'isFirstTime' ,
35+ false ,
36+ ) as boolean ;
37+ const rolledBackVersion = preferencesManager . getSync (
38+ 'rolledBackVersion' ,
39+ '' ,
40+ ) as string ;
41+ const uuid = preferencesManager . getSync ( 'uuid' , '' ) as string ;
42+ const currentVersion = preferencesManager . getSync (
43+ 'currentVersion' ,
44+ '' ,
45+ ) as string ;
46+ const currentVersionInfo = this . context . getKv ( `hash_${ currentVersion } ` ) ;
47+ const buildTime = preferencesManager . getSync ( 'buildTime' , '' ) as string ;
48+ const isUsingBundleUrl = this . context . getIsUsingBundleUrl ( ) ;
49+ let bundleFlags =
50+ bundleManager . BundleFlag . GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION ;
51+ let packageVersion = '' ;
52+ try {
53+ const bundleInfo = bundleManager . getBundleInfoForSelfSync ( bundleFlags ) ;
54+ packageVersion = bundleInfo ?. versionName || 'Unknown' ;
55+ } catch ( error ) {
56+ console . error ( 'Failed to get bundle info:' , error ) ;
57+ }
58+
59+ if ( isFirstTime ) {
60+ preferencesManager . deleteSync ( 'isFirstTime' ) ;
61+ }
62+
63+ if ( rolledBackVersion ) {
64+ preferencesManager . deleteSync ( 'rolledBackVersion' ) ;
65+ }
66+
67+ return {
68+ downloadRootDir : `${ context . filesDir } /_update` ,
69+ currentVersionInfo,
70+ packageVersion,
71+ currentVersion,
72+ buildTime,
73+ isUsingBundleUrl,
74+ isFirstTime,
75+ rolledBackVersion,
76+ uuid,
77+ } ;
78+ }
79+
80+ setLocalHashInfo ( hash : string , info : string ) : boolean {
7081 logger . debug ( TAG , ',call setLocalHashInfo' ) ;
7182 return UpdateModuleImpl . setLocalHashInfo ( this . context , hash , info ) ;
7283 }
@@ -75,9 +86,9 @@ getConstants(): Object {
7586 return UpdateModuleImpl . getLocalHashInfo ( this . context , hash ) ;
7687 }
7788
78- async setUuid ( uuid : string ) : Promise < boolean > {
89+ async setUuid ( uuid : string ) : Promise < boolean > {
7990 logger . debug ( TAG , ',call setUuid' ) ;
80- return UpdateModuleImpl . setUuid ( this . context , uuid ) ;
91+ return UpdateModuleImpl . setUuid ( this . context , uuid ) ;
8192 }
8293
8394 async reloadUpdate ( options : { hash : string } ) : Promise < void > {
@@ -95,31 +106,45 @@ getConstants(): Object {
95106 return UpdateModuleImpl . markSuccess ( this . context ) ;
96107 }
97108
98- async downloadPatchFromPpk ( options : { updateUrl : string ; hash : string ; originHash : string } ) : Promise < void > {
109+ async downloadPatchFromPpk ( options : {
110+ updateUrl : string ;
111+ hash : string ;
112+ originHash : string ;
113+ } ) : Promise < void > {
99114 logger . debug ( TAG , ',call downloadPatchFromPpk' ) ;
100115 return UpdateModuleImpl . downloadPatchFromPpk ( this . context , options ) ;
101116 }
102117
103- async downloadPatchFromPackage ( options : { updateUrl : string ; hash : string } ) : Promise < void > {
118+ async downloadPatchFromPackage ( options : {
119+ updateUrl : string ;
120+ hash : string ;
121+ } ) : Promise < void > {
104122 logger . debug ( TAG , ',call downloadPatchFromPackage' ) ;
105123 return UpdateModuleImpl . downloadPatchFromPackage ( this . context , options ) ;
106124 }
107125
108- async downloadFullUpdate ( options : { updateUrl : string ; hash : string } ) : Promise < void > {
126+ async downloadFullUpdate ( options : {
127+ updateUrl : string ;
128+ hash : string ;
129+ } ) : Promise < void > {
109130 logger . debug ( TAG , ',call downloadFullUpdate' ) ;
110131 return UpdateModuleImpl . downloadFullUpdate ( this . context , options ) ;
111132 }
112133
113- async downloadAndInstallApk ( options : { url : string ; target : string ; hash : string } ) : Promise < void > {
134+ async downloadAndInstallApk ( options : {
135+ url : string ;
136+ target : string ;
137+ hash : string ;
138+ } ) : Promise < void > {
114139 logger . debug ( TAG , ',call downloadAndInstallApk' ) ;
115140 return UpdateModuleImpl . downloadAndInstallApk ( this . mUiCtx , options ) ;
116141 }
117142
118- addListener ( eventName : string ) : void {
143+ addListener ( _eventName : string ) : void {
119144 logger . debug ( TAG , ',call addListener' ) ;
120145 }
121146
122- removeListeners ( count : number ) : void {
147+ removeListeners ( _count : number ) : void {
123148 logger . debug ( TAG , ',call removeListeners' ) ;
124149 }
125150}
0 commit comments