Skip to content

Commit 54c2c7a

Browse files
committed
revert
1 parent d17c239 commit 54c2c7a

File tree

3 files changed

+144
-216
lines changed

3 files changed

+144
-216
lines changed

harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class PushyFileJSBundleProvider extends JSBundleProvider {
1313

1414
constructor(context: common.UIAbilityContext) {
1515
super();
16-
this.updateContext = UpdateContext.getInstance(context);
16+
this.updateContext = new UpdateContext(context);
1717
this.path = this.updateContext.getBundleUrl();
1818
}
1919

harmony/pushy/src/main/ets/PushyTurboModule.ts

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import {
33
TurboModuleContext,
44
} from '@rnoh/react-native-openharmony/ts';
55
import common from '@ohos.app.ability.common';
6+
import dataPreferences from '@ohos.data.preferences';
7+
import { bundleManager } from '@kit.AbilityKit';
68
import logger from './Logger';
79
import { UpdateModuleImpl } from './UpdateModuleImpl';
810
import { UpdateContext } from './UpdateContext';
911
import { EventHub } from './EventHub';
12+
import { util } from '@kit.ArkTS';
1013

1114
const TAG = 'PushyTurboModule';
1215

@@ -18,25 +21,86 @@ export class PushyTurboModule extends TurboModule {
1821
super(ctx);
1922
logger.debug(TAG, ',PushyTurboModule constructor');
2023
this.mUiCtx = ctx.uiAbilityContext;
21-
this.context = UpdateContext.getInstance(this.mUiCtx);
24+
this.context = new UpdateContext(this.mUiCtx);
2225
EventHub.getInstance().setRNInstance(ctx.rnInstance);
2326
}
2427

2528
getConstants(): Object {
2629
logger.debug(TAG, ',call getConstants');
27-
const { isFirstTime, rolledBackVersion } =
28-
this.context.consumeLaunchMarks();
29-
const uuid = this.context.getKv('uuid');
30-
const currentVersion = this.context.getCurrentVersion();
30+
const context = this.mUiCtx;
31+
const preferencesManager = dataPreferences.getPreferencesSync(context, {
32+
name: 'update',
33+
});
34+
const isFirstTime = preferencesManager.getSync(
35+
'isFirstTime',
36+
false,
37+
) as boolean;
38+
const rolledBackVersion = preferencesManager.getSync(
39+
'rolledBackVersion',
40+
'',
41+
) as string;
42+
const uuid = preferencesManager.getSync('uuid', '') as string;
43+
const currentVersion = preferencesManager.getSync(
44+
'currentVersion',
45+
'',
46+
) as string;
3147
const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
3248

49+
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
50+
let bundleFlags =
51+
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
52+
let packageVersion = '';
53+
try {
54+
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
55+
packageVersion = bundleInfo?.versionName || 'Unknown';
56+
} catch (error) {
57+
console.error('Failed to get bundle info:', error);
58+
}
59+
const storedPackageVersion = preferencesManager.getSync(
60+
'packageVersion',
61+
'',
62+
) as string;
63+
const storedBuildTime = preferencesManager.getSync(
64+
'buildTime',
65+
'',
66+
) as string;
67+
let buildTime = '';
68+
try {
69+
const resourceManager = this.mUiCtx.resourceManager;
70+
const content = resourceManager.getRawFileContentSync('meta.json');
71+
const metaData = JSON.parse(
72+
new util.TextDecoder().decodeToString(content),
73+
);
74+
if (metaData.pushy_build_time) {
75+
buildTime = String(metaData.pushy_build_time);
76+
}
77+
} catch {}
78+
79+
const packageVersionChanged =
80+
!storedPackageVersion || packageVersion !== storedPackageVersion;
81+
const buildTimeChanged = !storedBuildTime || buildTime !== storedBuildTime;
82+
83+
if (packageVersionChanged || buildTimeChanged) {
84+
this.context.cleanUp();
85+
preferencesManager.putSync('packageVersion', packageVersion);
86+
preferencesManager.putSync('buildTime', buildTime);
87+
}
88+
89+
if (isFirstTime) {
90+
preferencesManager.deleteSync('isFirstTime');
91+
}
92+
93+
if (rolledBackVersion) {
94+
preferencesManager.deleteSync('rolledBackVersion');
95+
}
96+
3397
return {
34-
downloadRootDir: this.context.getRootDir(),
98+
downloadRootDir: `${context.filesDir}/_update`,
3599
currentVersionInfo,
36-
packageVersion: this.context.getPackageVersion(),
100+
packageVersion,
37101
currentVersion,
38-
buildTime: this.context.getBuildTime(),
39-
isUsingBundleUrl: this.context.getIsUsingBundleUrl(),
102+
buildTime,
103+
isUsingBundleUrl,
40104
isFirstTime,
41105
rolledBackVersion,
42106
uuid,

0 commit comments

Comments
 (0)