react-native-update 10.24.3 → 10.25.1

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.
@@ -98,23 +98,20 @@ public class UpdateModuleImpl {
98
98
  }
99
99
  });
100
100
  }catch (Exception e){
101
- promise.reject("执行报错:" + e.getMessage());
101
+ promise.reject("downloadPatchFromPpk failed: "+e.getMessage());
102
102
  }
103
103
  }
104
104
 
105
105
  public static void reloadUpdate(UpdateContext updateContext, ReactApplicationContext mContext, ReadableMap options, Promise promise) {
106
106
  final String hash = options.getString("hash");
107
-
108
- if (hash == null || hash.isEmpty()) {
109
- promise.reject("hash不能为空");
110
- return;
111
- }
112
107
  UiThreadUtil.runOnUiThread(new Runnable() {
113
108
  @Override
114
109
  public void run() {
110
+
111
+ updateContext.switchVersion(hash);
112
+ final Context application = mContext.getApplicationContext();
113
+ JSBundleLoader loader = JSBundleLoader.createFileLoader(UpdateContext.getBundleUrl(application));
115
114
  try {
116
- updateContext.switchVersion(hash);
117
- final Context application = mContext.getApplicationContext();
118
115
  ReactInstanceManager instanceManager = updateContext.getCustomReactInstanceManager();
119
116
 
120
117
  if (instanceManager == null) {
@@ -122,12 +119,10 @@ public class UpdateModuleImpl {
122
119
  }
123
120
 
124
121
  try {
125
- JSBundleLoader loader = JSBundleLoader.createFileLoader(UpdateContext.getBundleUrl(application));
126
122
  Field loadField = instanceManager.getClass().getDeclaredField("mBundleLoader");
127
123
  loadField.setAccessible(true);
128
124
  loadField.set(instanceManager, loader);
129
125
  } catch (Throwable err) {
130
- promise.reject("pushy:"+err.getMessage());
131
126
  Field jsBundleField = instanceManager.getClass().getDeclaredField("mJSBundleFile");
132
127
  jsBundleField.setAccessible(true);
133
128
  jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application));
@@ -137,31 +132,36 @@ public class UpdateModuleImpl {
137
132
  promise.resolve(true);
138
133
 
139
134
  } catch (Throwable err) {
140
- promise.reject(err);
141
- Log.e("pushy", "switchVersion failed ", err);
142
135
  final Activity currentActivity = mContext.getCurrentActivity();
143
136
  if (currentActivity == null) {
144
137
  return;
145
138
  }
146
139
  try {
147
- // Try to get getReactDelegate method using reflection
148
140
  java.lang.reflect.Method getReactDelegateMethod =
149
141
  ReactActivity.class.getMethod("getReactDelegate");
150
- if (getReactDelegateMethod != null) {
151
- ReactDelegate reactDelegate = (ReactDelegate)
152
- getReactDelegateMethod.invoke(currentActivity);
153
-
154
- // Try to get reload method using reflection
155
- java.lang.reflect.Method reloadMethod =
156
- ReactDelegate.class.getMethod("reload");
157
- if (reloadMethod != null) {
158
- reloadMethod.invoke(reactDelegate);
159
- } else {
160
- throw new NoSuchMethodException();
161
- }
162
- } else {
163
- throw new NoSuchMethodException();
164
- }
142
+
143
+ ReactDelegate reactDelegate = (ReactDelegate)
144
+ getReactDelegateMethod.invoke(currentActivity);
145
+
146
+ Field reactHostField = ReactDelegate.class.getDeclaredField("mReactHost");
147
+ reactHostField.setAccessible(true);
148
+ Object reactHost = reactHostField.get(reactDelegate);
149
+
150
+ // Access the mReactHostDelegate field
151
+ Field reactHostDelegateField = reactHost.getClass().getDeclaredField("mReactHostDelegate");
152
+ reactHostDelegateField.setAccessible(true);
153
+ Object reactHostDelegate = reactHostDelegateField.get(reactHost);
154
+
155
+ // Modify the jsBundleLoader field
156
+ Field jsBundleLoaderField = reactHostDelegate.getClass().getDeclaredField("jsBundleLoader");
157
+ jsBundleLoaderField.setAccessible(true);
158
+ jsBundleLoaderField.set(reactHostDelegate, loader);
159
+
160
+ // Get the reload method with a String parameter
161
+ java.lang.reflect.Method reloadMethod = reactHost.getClass().getMethod("reload", String.class);
162
+
163
+ // Invoke the reload method with a reason
164
+ reloadMethod.invoke(reactHost, "react-native-update");
165
165
  } catch (Throwable e) {
166
166
  currentActivity.runOnUiThread(new Runnable() {
167
167
  @Override
@@ -171,72 +171,54 @@ public class UpdateModuleImpl {
171
171
  });
172
172
  }
173
173
  }
174
+ promise.resolve(true);
174
175
  }
175
176
  });
176
177
  }
177
178
 
178
179
 
179
- public static void setNeedUpdate(UpdateContext updateContext, ReadableMap options,Promise promise) {
180
- try {
181
- final String hash = options.getString("hash");
182
- if(hash==null || hash.isEmpty()){
183
- promise.reject("hash不能为空");
184
- return;
185
- }
186
- UiThreadUtil.runOnUiThread(new Runnable() {
187
- @Override
188
- public void run() {
189
- try {
190
- updateContext.switchVersion(hash);
191
- promise.resolve(true);
192
- } catch (Throwable err) {
193
- promise.reject("switchVersionLater failed:"+err.getMessage());
194
- Log.e("pushy", "switchVersionLater failed", err);
195
- }
180
+ public static void setNeedUpdate(UpdateContext updateContext, ReadableMap options, Promise promise) {
181
+ final String hash = options.getString("hash");
182
+ UiThreadUtil.runOnUiThread(new Runnable() {
183
+ @Override
184
+ public void run() {
185
+ try {
186
+ updateContext.switchVersion(hash);
187
+ promise.resolve(true);
188
+ } catch (Throwable err) {
189
+ promise.reject("switchVersionLater failed: "+err.getMessage());
190
+ Log.e("pushy", "switchVersionLater failed", err);
196
191
  }
197
- });
198
- } catch (Exception e){
199
- promise.reject("执行报错:"+e.getMessage());
200
- }
192
+ }
193
+ });
201
194
  }
202
195
 
203
- public static void markSuccess(UpdateContext updateContext,Promise promise) {
204
- try {
205
- UiThreadUtil.runOnUiThread(new Runnable() {
206
- @Override
207
- public void run() {
208
- updateContext.markSuccess();
209
- promise.resolve(true);
210
- }
211
- });
212
- } catch (Exception e){
213
- promise.reject("执行报错:"+e.getMessage());
214
- }
196
+ public static void markSuccess(UpdateContext updateContext, Promise promise) {
197
+ UiThreadUtil.runOnUiThread(new Runnable() {
198
+ @Override
199
+ public void run() {
200
+ updateContext.markSuccess();
201
+ promise.resolve(true);
202
+ }
203
+ });
215
204
  }
216
205
 
217
206
  public static void setUuid(UpdateContext updateContext, String uuid, Promise promise) {
218
- try {
219
- UiThreadUtil.runOnUiThread(new Runnable() {
220
- @Override
221
- public void run() {
222
- updateContext.setKv("uuid", uuid);
223
- promise.resolve(true);
224
- }
225
- });
226
- } catch (Exception e){
227
- promise.reject("执行报错:"+e.getMessage());
228
- }
229
-
207
+ UiThreadUtil.runOnUiThread(new Runnable() {
208
+ @Override
209
+ public void run() {
210
+ updateContext.setKv("uuid", uuid);
211
+ promise.resolve(true);
212
+ }
213
+ });
230
214
  }
231
215
 
232
216
  public static boolean check(String json) {
233
217
  ObjectMapper mapper = new ObjectMapper();
234
218
  try {
235
219
  mapper.readValue(json, Map.class);
236
- System.out.println("String can be converted to Map");
237
220
  return true;
238
221
  } catch (IOException e) {
239
- System.out.println("String cannot be converted to Map");
240
222
  return false;
241
223
  }
242
224
  }
@@ -246,12 +228,12 @@ public class UpdateModuleImpl {
246
228
  UiThreadUtil.runOnUiThread(new Runnable() {
247
229
  @Override
248
230
  public void run() {
249
- if(!check(info)){
250
- updateContext.setKv("hash_" + hash, info);
251
- promise.reject("校验报错:json字符串格式错误");
252
- }else {
231
+ if (check(info)) {
253
232
  updateContext.setKv("hash_" + hash, info);
254
233
  promise.resolve(true);
234
+ } else {
235
+ updateContext.setKv("hash_" + hash, info);
236
+ promise.reject("setLocalHashInfo failed: invalid json string");
255
237
  }
256
238
  }
257
239
  });
@@ -262,7 +244,7 @@ public class UpdateModuleImpl {
262
244
  if (check(value)) {
263
245
  promise.resolve(value);
264
246
  } else {
265
- promise.reject("校验报错:json字符串格式错误");
247
+ promise.reject("getLocalHashInfo failed: invalid json string");
266
248
  }
267
249
 
268
250
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.24.3",
3
+ "version": "10.25.1",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/provider.tsx CHANGED
@@ -325,11 +325,16 @@ export const UpdateProvider = ({
325
325
  };
326
326
 
327
327
  Linking.getInitialURL().then(parseLinking);
328
- const linkingListener = Linking.addEventListener('url', ({ url }) =>
329
- parseLinking(url),
330
- );
328
+ const linkingHandler = ({ url }: { url: string }) => {
329
+ parseLinking(url);
330
+ };
331
+ const linkingListener = Linking.addEventListener('url', linkingHandler);
331
332
  return () => {
332
- linkingListener.remove();
333
+ if (typeof linkingListener.remove === 'function') {
334
+ linkingListener.remove();
335
+ } else if ('removeEventListener' in Linking) {
336
+ (Linking as any).removeEventListener('url', linkingHandler);
337
+ }
333
338
  };
334
339
  }, [parseTestPayload]);
335
340