Skip to content

Commit f7309f6

Browse files
committed
update version to 10.30.0, enhance version and build time tracking in UpdateContext and RCTPushy, and add new entry to .gitignore
1 parent a224113 commit f7309f6

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ android/bin
5151
Example/testHotUpdate/harmony
5252
Example/testHotUpdate/android/app/.cxx
5353
Example/harmony_use_pushy/libs
54+
.cursor/mcp.json

android/src/main/java/cn/reactnative/modules/update/UpdateContext.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,18 @@ public UpdateContext(Context context) {
3636
this.sp = context.getSharedPreferences("update", Context.MODE_PRIVATE);
3737

3838
String packageVersion = getPackageVersion();
39-
if (!packageVersion.equals(this.sp.getString("packageVersion", null))) {
39+
String buildTime = getBuildTime();
40+
String storedPackageVersion = this.sp.getString("packageVersion", null);
41+
String storedBuildTime = this.sp.getString("buildTime", null);
42+
43+
boolean packageVersionChanged = !packageVersion.equals(storedPackageVersion);
44+
boolean buildTimeChanged = !buildTime.equals(storedBuildTime);
45+
46+
if (packageVersionChanged || buildTimeChanged) {
4047
SharedPreferences.Editor editor = sp.edit();
4148
editor.clear();
4249
editor.putString("packageVersion", packageVersion);
50+
editor.putString("buildTime", buildTime);
4351
editor.apply();
4452

4553
this.cleanUp();

ios/RCTPushy/RCTPushy.mm

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
static NSString *const keyPushyInfo = @"REACTNATIVECN_PUSHY_INFO_KEY";
1818
static NSString *const paramPackageVersion = @"packageVersion";
19+
static NSString *const paramBuildTime = @"buildTime";
1920
static NSString *const paramLastVersion = @"lastVersion";
2021
static NSString *const paramCurrentVersion = @"currentVersion";
2122
static NSString *const paramIsFirstTime = @"isFirstTime";
@@ -70,20 +71,28 @@ + (NSURL *)bundleURL
7071
{
7172
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
7273

74+
// Check for version changes first
75+
NSString *curPackageVersion = [RCTPushy packageVersion];
76+
NSString *curBuildTime = [RCTPushy buildTime];
77+
NSString *storedPackageVersion = [defaults stringForKey:paramPackageVersion];
78+
NSString *storedBuildTime = [defaults stringForKey:paramBuildTime];
79+
80+
BOOL packageVersionChanged = ![curPackageVersion isEqualToString:storedPackageVersion];
81+
BOOL buildTimeChanged = ![curBuildTime isEqualToString:storedBuildTime];
82+
83+
if (packageVersionChanged || buildTimeChanged) {
84+
// Clear all update data and store new versions
85+
[defaults setObject:nil forKey:keyPushyInfo];
86+
[defaults setObject:nil forKey:keyHashInfo];
87+
[defaults setObject:@(YES) forKey:KeyPackageUpdatedMarked];
88+
[defaults setObject:curPackageVersion forKey:paramPackageVersion];
89+
[defaults setObject:curBuildTime forKey:paramBuildTime];
90+
91+
// ...need clear files later
92+
}
93+
7394
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
7495
if (pushyInfo) {
75-
NSString *curPackageVersion = [RCTPushy packageVersion];
76-
NSString *packageVersion = [pushyInfo objectForKey:paramPackageVersion];
77-
78-
BOOL needClearPushyInfo = ![curPackageVersion isEqualToString:packageVersion];
79-
if (needClearPushyInfo) {
80-
[defaults setObject:nil forKey:keyPushyInfo];
81-
[defaults setObject:nil forKey:keyHashInfo];
82-
[defaults setObject:@(YES) forKey:KeyPackageUpdatedMarked];
83-
84-
// ...need clear files later
85-
}
86-
else {
8796
NSString *curVersion = pushyInfo[paramCurrentVersion];
8897

8998
BOOL isFirstTime = [pushyInfo[paramIsFirstTime] boolValue];
@@ -127,13 +136,11 @@ + (NSString *) rollback {
127136
NSDictionary *pushyInfo = [defaults dictionaryForKey:keyPushyInfo];
128137
NSString *lastVersion = pushyInfo[paramLastVersion];
129138
NSString *curVersion = pushyInfo[paramCurrentVersion];
130-
NSString *curPackageVersion = [RCTPushy packageVersion];
131139
if (lastVersion.length) {
132140
// roll back to last version
133141
[defaults setObject:@{paramCurrentVersion:lastVersion,
134142
paramIsFirstTime:@(NO),
135-
paramIsFirstLoadOk:@(YES),
136-
paramPackageVersion:curPackageVersion}
143+
paramIsFirstLoadOk:@(YES)}
137144
forKey:keyPushyInfo];
138145
}
139146
else {
@@ -296,7 +303,6 @@ - (instancetype)init
296303
newInfo[paramLastVersion] = lastVersion;
297304
newInfo[paramIsFirstTime] = @(YES);
298305
newInfo[paramIsFirstLoadOk] = @(NO);
299-
newInfo[paramPackageVersion] = [RCTPushy packageVersion];
300306
[defaults setObject:newInfo forKey:keyPushyInfo];
301307

302308

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.29.9",
3+
"version": "10.30.0",
44
"description": "react-native hot update",
55
"main": "src/index",
66
"scripts": {

0 commit comments

Comments
 (0)