react-native-update 10.42.3 → 10.42.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -7,7 +7,6 @@ import { bundleManager } from '@kit.AbilityKit';
|
|
|
7
7
|
import logger from './Logger';
|
|
8
8
|
import { UpdateContext } from './UpdateContext';
|
|
9
9
|
import { EventHub } from './EventHub';
|
|
10
|
-
import { util } from '@kit.ArkTS';
|
|
11
10
|
|
|
12
11
|
const TAG = 'PushyTurboModule';
|
|
13
12
|
|
|
@@ -47,33 +46,6 @@ export class PushyTurboModule extends UITurboModule {
|
|
|
47
46
|
return bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
|
48
47
|
}
|
|
49
48
|
|
|
50
|
-
private getPackageVersion(): string {
|
|
51
|
-
try {
|
|
52
|
-
const bundleInfo = bundleManager.getBundleInfoForSelfSync(
|
|
53
|
-
this.getBundleFlags(),
|
|
54
|
-
);
|
|
55
|
-
return bundleInfo?.versionName || 'Unknown';
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error('Failed to get bundle info:', error);
|
|
58
|
-
return '';
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
private getBuildTime(): string {
|
|
63
|
-
try {
|
|
64
|
-
const content = this.mUiCtx.resourceManager.getRawFileContentSync(
|
|
65
|
-
'meta.json',
|
|
66
|
-
);
|
|
67
|
-
const metaData = JSON.parse(
|
|
68
|
-
new util.TextDecoder().decodeToString(content),
|
|
69
|
-
) as Record<string, string | number | boolean | null | undefined>;
|
|
70
|
-
if (metaData.pushy_build_time) {
|
|
71
|
-
return String(metaData.pushy_build_time);
|
|
72
|
-
}
|
|
73
|
-
} catch {}
|
|
74
|
-
return '';
|
|
75
|
-
}
|
|
76
|
-
|
|
77
49
|
private requireHash(hash: string, methodName: string): string {
|
|
78
50
|
if (!hash) {
|
|
79
51
|
throw Error(`${methodName}: empty hash`);
|
|
@@ -95,8 +67,8 @@ export class PushyTurboModule extends UITurboModule {
|
|
|
95
67
|
|
|
96
68
|
getConstants(): Object {
|
|
97
69
|
logger.debug(TAG, ',call getConstants');
|
|
98
|
-
const packageVersion = this.getPackageVersion();
|
|
99
|
-
const buildTime = this.getBuildTime();
|
|
70
|
+
const packageVersion = this.context.getPackageVersion();
|
|
71
|
+
const buildTime = this.context.getBuildTime();
|
|
100
72
|
this.context.syncStateWithBinaryVersion(packageVersion, buildTime);
|
|
101
73
|
|
|
102
74
|
const currentVersion = this.context.getCurrentVersion();
|
|
@@ -3,6 +3,8 @@ import fileIo from '@ohos.file.fs';
|
|
|
3
3
|
import { DownloadTask } from './DownloadTask';
|
|
4
4
|
import common from '@ohos.app.ability.common';
|
|
5
5
|
import { DownloadTaskParams } from './DownloadTaskParams';
|
|
6
|
+
import { bundleManager } from '@kit.AbilityKit';
|
|
7
|
+
import { util } from '@kit.ArkTS';
|
|
6
8
|
import NativePatchCore, {
|
|
7
9
|
STATE_OP_CLEAR_FIRST_TIME,
|
|
8
10
|
STATE_OP_CLEAR_ROLLBACK_MARK,
|
|
@@ -13,6 +15,10 @@ import NativePatchCore, {
|
|
|
13
15
|
StateCoreResult,
|
|
14
16
|
} from './NativePatchCore';
|
|
15
17
|
|
|
18
|
+
type FlushablePreferences = preferences.Preferences & {
|
|
19
|
+
flushSync?: () => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
16
22
|
export class UpdateContext {
|
|
17
23
|
private context: common.UIAbilityContext;
|
|
18
24
|
private rootDir: string;
|
|
@@ -32,6 +38,10 @@ export class UpdateContext {
|
|
|
32
38
|
console.error('Failed to create root directory:', e);
|
|
33
39
|
}
|
|
34
40
|
this.initPreferences();
|
|
41
|
+
this.syncStateWithBinaryVersion(
|
|
42
|
+
this.getPackageVersion(),
|
|
43
|
+
this.getBuildTime(),
|
|
44
|
+
);
|
|
35
45
|
}
|
|
36
46
|
|
|
37
47
|
private initPreferences() {
|
|
@@ -44,6 +54,37 @@ export class UpdateContext {
|
|
|
44
54
|
}
|
|
45
55
|
}
|
|
46
56
|
|
|
57
|
+
private getBundleFlags(): bundleManager.BundleFlag {
|
|
58
|
+
return bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public getPackageVersion(): string {
|
|
62
|
+
try {
|
|
63
|
+
const bundleInfo = bundleManager.getBundleInfoForSelfSync(
|
|
64
|
+
this.getBundleFlags(),
|
|
65
|
+
);
|
|
66
|
+
return bundleInfo?.versionName || 'Unknown';
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Failed to get bundle info:', error);
|
|
69
|
+
return '';
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public getBuildTime(): string {
|
|
74
|
+
try {
|
|
75
|
+
const content = this.context.resourceManager.getRawFileContentSync(
|
|
76
|
+
'meta.json',
|
|
77
|
+
);
|
|
78
|
+
const metaData = JSON.parse(
|
|
79
|
+
new util.TextDecoder().decodeToString(content),
|
|
80
|
+
) as Record<string, string | number | boolean | null | undefined>;
|
|
81
|
+
if (metaData.pushy_build_time) {
|
|
82
|
+
return String(metaData.pushy_build_time);
|
|
83
|
+
}
|
|
84
|
+
} catch {}
|
|
85
|
+
return '';
|
|
86
|
+
}
|
|
87
|
+
|
|
47
88
|
private readString(key: string): string {
|
|
48
89
|
const value = this.preferences.getSync(key, '') as
|
|
49
90
|
| string
|
|
@@ -87,6 +128,20 @@ export class UpdateContext {
|
|
|
87
128
|
return defaultValue;
|
|
88
129
|
}
|
|
89
130
|
|
|
131
|
+
private flushPreferences(reason: string): void {
|
|
132
|
+
try {
|
|
133
|
+
const flushablePreferences = this.preferences as FlushablePreferences;
|
|
134
|
+
if (typeof flushablePreferences.flushSync === 'function') {
|
|
135
|
+
flushablePreferences.flushSync();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
throw Error('preferences.flushSync is not available');
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error(`Failed to flush preferences for ${reason}:`, error);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
90
145
|
private putNullableString(key: string, value?: string): void {
|
|
91
146
|
if (value) {
|
|
92
147
|
this.preferences.putSync(key, value);
|
|
@@ -136,7 +191,7 @@ export class UpdateContext {
|
|
|
136
191
|
if (options.removeStaleHash && state.staleVersionToDelete) {
|
|
137
192
|
this.preferences.deleteSync(`hash_${state.staleVersionToDelete}`);
|
|
138
193
|
}
|
|
139
|
-
this.
|
|
194
|
+
this.flushPreferences('persist state');
|
|
140
195
|
if (options.cleanUp) {
|
|
141
196
|
this.cleanUp();
|
|
142
197
|
}
|
|
@@ -196,7 +251,7 @@ export class UpdateContext {
|
|
|
196
251
|
|
|
197
252
|
public setKv(key: string, value: string): void {
|
|
198
253
|
this.preferences.putSync(key, value);
|
|
199
|
-
this.
|
|
254
|
+
this.flushPreferences(`set key ${key}`);
|
|
200
255
|
}
|
|
201
256
|
|
|
202
257
|
public getKv(key: string): string {
|
package/harmony/pushy.har
CHANGED
|
Binary file
|