Skip to content

Commit ba6d239

Browse files
committed
fix cleanup
1 parent acd1897 commit ba6d239

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

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

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,7 @@ export class PushyTurboModule extends TurboModule {
4545
'',
4646
) as string;
4747
const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
48-
let buildTime = preferencesManager.getSync('buildTime', '') as string;
49-
if (!buildTime) {
50-
try {
51-
const resourceManager = this.mUiCtx.resourceManager;
52-
const content = resourceManager.getRawFileContentSync('meta.json');
53-
const metaData = JSON.parse(
54-
new util.TextDecoder().decodeToString(content),
55-
);
56-
if (metaData.pushy_build_time) {
57-
buildTime = String(metaData.pushy_build_time);
58-
preferencesManager.putSync('buildTime', buildTime);
59-
}
60-
} catch {}
61-
}
48+
6249
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
6350
let bundleFlags =
6451
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
@@ -69,6 +56,35 @@ export class PushyTurboModule extends TurboModule {
6956
} catch (error) {
7057
console.error('Failed to get bundle info:', error);
7158
}
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+
}
7288

7389
if (isFirstTime) {
7490
preferencesManager.deleteSync('isFirstTime');

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,14 @@ export class UpdateContext {
246246
return lastVersion;
247247
}
248248

249-
private cleanUp(): void {
249+
public async cleanUp() {
250250
const params = new DownloadTaskParams();
251251
params.type = DownloadTaskParams.TASK_TYPE_CLEANUP;
252252
params.hash = this.preferences.getSync('currentVersion', '') as string;
253253
params.originHash = this.preferences.getSync('lastVersion', '') as string;
254254
params.unzipDirectory = this.rootDir;
255255
const downloadTask = new DownloadTask(this.context);
256-
downloadTask.execute(params);
256+
await downloadTask.execute(params);
257257
}
258258

259259
public getIsUsingBundleUrl(): boolean {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-update",
3-
"version": "10.37.11",
3+
"version": "10.37.12",
44
"description": "react-native hot update",
55
"main": "src/index",
66
"scripts": {

0 commit comments

Comments
 (0)