react-native-update 10.2.5 → 10.2.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-update",
3
- "version": "10.2.5",
3
+ "version": "10.2.7",
4
4
  "description": "react-native hot update",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
@@ -48,13 +48,9 @@
48
48
  "nanoid": "^3.3.3"
49
49
  },
50
50
  "codegenConfig": {
51
- "libraries": [
52
- {
53
- "name": "RCTPushySpec",
54
- "type": "modules",
55
- "jsSrcsDir": "lib"
56
- }
57
- ]
51
+ "name": "RCTPushySpec",
52
+ "type": "modules",
53
+ "jsSrcsDir": "src"
58
54
  },
59
55
  "devDependencies": {
60
56
  "@babel/core": "^7.24.0",
@@ -1,5 +1,4 @@
1
- import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
2
- import { TurboModuleRegistry } from 'react-native';
1
+ import { TurboModule, TurboModuleRegistry } from 'react-native';
3
2
 
4
3
  export interface Spec extends TurboModule {
5
4
  getConstants: () => {
package/src/provider.tsx CHANGED
@@ -32,6 +32,7 @@ export const PushyProvider = ({
32
32
  const { options } = client;
33
33
  const stateListener = useRef<NativeEventSubscription>();
34
34
  const [updateInfo, setUpdateInfo] = useState<CheckResult>();
35
+ const updateInfoRef = useRef(updateInfo);
35
36
  const [progress, setProgress] = useState<ProgressData>();
36
37
  const [lastError, setLastError] = useState<Error>();
37
38
  const lastChecking = useRef(0);
@@ -61,37 +62,40 @@ export const PushyProvider = ({
61
62
  }
62
63
  }, [client, updateInfo]);
63
64
 
64
- const downloadUpdate = useCallback(async () => {
65
- if (!updateInfo || !updateInfo.update) {
66
- return;
67
- }
68
- try {
69
- const hash = await client.downloadUpdate(updateInfo, setProgress);
70
- if (!hash) {
65
+ const downloadUpdate = useCallback(
66
+ async (info: CheckResult | undefined = updateInfoRef.current) => {
67
+ if (!info || !info.update) {
71
68
  return;
72
69
  }
73
- stateListener.current && stateListener.current.remove();
74
- showAlert('提示', '下载完毕,是否立即更新?', [
75
- {
76
- text: '下次再说',
77
- style: 'cancel',
78
- onPress: () => {
79
- client.switchVersionLater(hash);
70
+ try {
71
+ const hash = await client.downloadUpdate(info, setProgress);
72
+ if (!hash) {
73
+ return;
74
+ }
75
+ stateListener.current && stateListener.current.remove();
76
+ showAlert('提示', '下载完毕,是否立即更新?', [
77
+ {
78
+ text: '下次再说',
79
+ style: 'cancel',
80
+ onPress: () => {
81
+ client.switchVersionLater(hash);
82
+ },
80
83
  },
81
- },
82
- {
83
- text: '立即更新',
84
- style: 'default',
85
- onPress: () => {
86
- client.switchVersion(hash);
84
+ {
85
+ text: '立即更新',
86
+ style: 'default',
87
+ onPress: () => {
88
+ client.switchVersion(hash);
89
+ },
87
90
  },
88
- },
89
- ]);
90
- } catch (e: any) {
91
- setLastError(e);
92
- showAlert('更新失败', e.message);
93
- }
94
- }, [client, showAlert, updateInfo]);
91
+ ]);
92
+ } catch (e: any) {
93
+ setLastError(e);
94
+ showAlert('更新失败', e.message);
95
+ }
96
+ },
97
+ [client, showAlert],
98
+ );
95
99
 
96
100
  const downloadAndInstallApk = useCallback(
97
101
  async (downloadUrl: string) => {
@@ -116,6 +120,7 @@ export const PushyProvider = ({
116
120
  showAlert('更新检查失败', e.message);
117
121
  return;
118
122
  }
123
+ updateInfoRef.current = info;
119
124
  setUpdateInfo(info);
120
125
  if (info.expired) {
121
126
  const { downloadUrl } = info;