react-native-update 10.19.0 → 10.19.2

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.
@@ -0,0 +1,21 @@
1
+ name: Publish Package to npmjs
2
+ on:
3
+ release:
4
+ types: [published]
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ permissions:
9
+ contents: read
10
+ id-token: write
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ # Setup .npmrc file to publish to npm
14
+ - uses: actions/setup-node@v4
15
+ with:
16
+ node-version: '20.x'
17
+ registry-url: 'https://registry.npmjs.org'
18
+ - run: npm ci
19
+ - run: npm publish --provenance --access public
20
+ env:
21
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
@@ -1,7 +1,7 @@
1
1
  package cn.reactnative.modules.update;
2
2
 
3
3
  import android.app.Activity;
4
- import android.app.Application;
4
+ import android.content.Context;
5
5
  import android.util.Log;
6
6
  import com.facebook.react.ReactApplication;
7
7
  import com.facebook.react.ReactInstanceManager;
@@ -117,7 +117,7 @@ public class UpdateModuleImpl {
117
117
  public void run() {
118
118
  try {
119
119
  updateContext.switchVersion(hash);
120
- final Application application = (Application) getReactApplicationContext().getApplicationContext();
120
+ final Context application = mContext.getApplicationContext();
121
121
  ReactInstanceManager instanceManager = updateContext.getCustomReactInstanceManager();
122
122
 
123
123
  if (instanceManager == null) {
@@ -141,6 +141,7 @@ public class UpdateModuleImpl {
141
141
  promise.resolve(true);
142
142
  } catch (Throwable err) {
143
143
  promise.reject("pushy:"+err.getMessage());
144
+ final Activity activity = mContext.getCurrentActivity();
144
145
  if (activity != null) {
145
146
  activity.recreate();
146
147
  }
@@ -1,7 +1,7 @@
1
1
  package cn.reactnative.modules.update;
2
2
 
3
3
  import android.app.Activity;
4
- import android.app.Application;
4
+ import android.content.Context;
5
5
  import android.content.Intent;
6
6
  import android.net.Uri;
7
7
  import android.os.Build;
@@ -176,7 +176,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
176
176
  public void run() {
177
177
  try {
178
178
  updateContext.switchVersion(hash);
179
- final Application application = (Application) getReactApplicationContext().getApplicationContext();
179
+ final Context application = getReactApplicationContext().getApplicationContext();
180
180
  ReactInstanceManager instanceManager = updateContext.getCustomReactInstanceManager();
181
181
 
182
182
  if (instanceManager == null) {
@@ -199,6 +199,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
199
199
  instanceManager.recreateReactContextInBackground();
200
200
  promise.resolve(null);
201
201
  } catch (Throwable err) {
202
+ final Activity activity = getCurrentActivity();
202
203
  if (activity != null) {
203
204
  activity.recreate();
204
205
  }
@@ -315,17 +315,18 @@ RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options
315
315
  if (hash.length) {
316
316
  [self setNeedUpdate:options resolver:resolve rejecter:reject];
317
317
 
318
+ // reload in earlier version
319
+ dispatch_async(dispatch_get_main_queue(), ^{
320
+ [self.bridge setValue:[[self class] bundleURL] forKey:@"bundleURL"];
321
+ [self.bridge reload];
322
+ });
323
+
318
324
  #if __has_include("RCTReloadCommand.h")
319
325
  // reload 0.62+
320
326
  RCTReloadCommandSetBundleURL([[self class] bundleURL]);
321
327
  RCTTriggerReloadCommandListeners(@"pushy reload");
322
- #else
323
- // reload in earlier version
324
- dispatch_async(dispatch_get_main_queue(), ^{
325
- [self.bridge setValue:[[self class] bundleURL] forKey:@"bundleURL"];
326
- [self.bridge reload];
327
- });
328
328
  #endif
329
+
329
330
  resolve(@true);
330
331
  }else{
331
332
  reject(@"执行报错", nil, nil);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.19.0",
3
+ "version": "10.19.2",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index",
6
6
  "scripts": {
package/src/utils.ts CHANGED
@@ -37,15 +37,35 @@ export const emptyModule = new EmptyModule();
37
37
  const ping =
38
38
  Platform.OS === 'web'
39
39
  ? Promise.resolve
40
- : async (url: string) =>
41
- Promise.race([
40
+ : async (url: string) => {
41
+ let pingFinished = false;
42
+ return Promise.race([
42
43
  fetch(url, {
43
44
  method: 'HEAD',
44
45
  })
45
- .then(({ status }) => (status === 200 ? url : null))
46
- .catch(() => null),
47
- new Promise(r => setTimeout(() => r(null), 2000)),
46
+ .then(({ status, statusText }) => {
47
+ pingFinished = true;
48
+ if (status === 200) {
49
+ return url;
50
+ }
51
+ log('ping failed', url, status, statusText);
52
+ return null;
53
+ })
54
+ .catch(e => {
55
+ pingFinished = true;
56
+ log('ping error', url, e);
57
+ return null;
58
+ }),
59
+ new Promise(r =>
60
+ setTimeout(() => {
61
+ r(null);
62
+ if (!pingFinished) {
63
+ log('ping timeout', url);
64
+ }
65
+ }, 2000),
66
+ ),
48
67
  ]);
68
+ };
49
69
 
50
70
  export function joinUrls(paths: string[], fileName?: string) {
51
71
  if (fileName) {
@@ -57,5 +77,10 @@ export const testUrls = async (urls?: string[]) => {
57
77
  if (!urls?.length) {
58
78
  return null;
59
79
  }
60
- return promiseAny(urls.map(ping)).catch(() => null);
80
+ const ret = await promiseAny(urls.map(ping));
81
+ if (ret) {
82
+ return ret;
83
+ }
84
+ log('all ping failed, use first url:', urls[0]);
85
+ return urls[0];
61
86
  };