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("
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
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
|
-
}
|
|
199
|
-
promise.reject("执行报错:"+e.getMessage());
|
|
200
|
-
}
|
|
192
|
+
}
|
|
193
|
+
});
|
|
201
194
|
}
|
|
202
195
|
|
|
203
|
-
public static void markSuccess(UpdateContext updateContext,Promise promise) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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(
|
|
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("
|
|
247
|
+
promise.reject("getLocalHashInfo failed: invalid json string");
|
|
266
248
|
}
|
|
267
249
|
|
|
268
250
|
}
|
package/package.json
CHANGED
package/src/provider.tsx
CHANGED
|
@@ -325,11 +325,16 @@ export const UpdateProvider = ({
|
|
|
325
325
|
};
|
|
326
326
|
|
|
327
327
|
Linking.getInitialURL().then(parseLinking);
|
|
328
|
-
const
|
|
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
|
|