react-native-update 10.0.0-beta.2 → 10.0.0-beta.3
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 +1 -1
- package/src/client.tsx +1 -0
- package/src/context.ts +2 -0
- package/src/provider.tsx +22 -10
package/package.json
CHANGED
package/src/client.tsx
CHANGED
package/src/context.ts
CHANGED
|
@@ -12,6 +12,7 @@ export const defaultContext = {
|
|
|
12
12
|
markSuccess: noop,
|
|
13
13
|
dismissError: noop,
|
|
14
14
|
downloadUpdate: noop,
|
|
15
|
+
downloadAndInstallApk: noop,
|
|
15
16
|
currentHash: '',
|
|
16
17
|
packageVersion: '',
|
|
17
18
|
};
|
|
@@ -23,6 +24,7 @@ export const PushyContext = createContext<{
|
|
|
23
24
|
markSuccess: () => void;
|
|
24
25
|
dismissError: () => void;
|
|
25
26
|
downloadUpdate: () => void;
|
|
27
|
+
downloadAndInstallApk: (url: string) => void;
|
|
26
28
|
currentHash: string;
|
|
27
29
|
packageVersion: string;
|
|
28
30
|
client?: Pushy;
|
package/src/provider.tsx
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
} from 'react-native';
|
|
15
15
|
import { Pushy } from './client';
|
|
16
16
|
import { currentVersion, isFirstTime, packageVersion } from './core';
|
|
17
|
-
import { CheckResult } from './type';
|
|
17
|
+
import { CheckResult, ProgressData } from './type';
|
|
18
18
|
import { PushyContext } from './context';
|
|
19
19
|
|
|
20
20
|
export const PushyProvider = ({
|
|
@@ -24,9 +24,10 @@ export const PushyProvider = ({
|
|
|
24
24
|
client: Pushy;
|
|
25
25
|
children: ReactNode;
|
|
26
26
|
}) => {
|
|
27
|
-
const {
|
|
27
|
+
const { options } = client;
|
|
28
28
|
const stateListener = useRef<NativeEventSubscription>();
|
|
29
29
|
const [updateInfo, setUpdateInfo] = useState<CheckResult>();
|
|
30
|
+
const [progress, setProgress] = useState<ProgressData>();
|
|
30
31
|
const [lastError, setLastError] = useState<Error>();
|
|
31
32
|
|
|
32
33
|
const dismissError = useCallback(() => {
|
|
@@ -37,11 +38,11 @@ export const PushyProvider = ({
|
|
|
37
38
|
|
|
38
39
|
const showAlert = useCallback(
|
|
39
40
|
(...args: Parameters<typeof Alert.alert>) => {
|
|
40
|
-
if (useAlert) {
|
|
41
|
+
if (options.useAlert) {
|
|
41
42
|
Alert.alert(...args);
|
|
42
43
|
}
|
|
43
44
|
},
|
|
44
|
-
[
|
|
45
|
+
[options],
|
|
45
46
|
);
|
|
46
47
|
|
|
47
48
|
const switchVersion = useCallback(() => {
|
|
@@ -61,7 +62,7 @@ export const PushyProvider = ({
|
|
|
61
62
|
return;
|
|
62
63
|
}
|
|
63
64
|
try {
|
|
64
|
-
const hash = await client.downloadUpdate(updateInfo);
|
|
65
|
+
const hash = await client.downloadUpdate(updateInfo, setProgress);
|
|
65
66
|
if (!hash) {
|
|
66
67
|
return;
|
|
67
68
|
}
|
|
@@ -88,6 +89,15 @@ export const PushyProvider = ({
|
|
|
88
89
|
}
|
|
89
90
|
}, [client, showAlert, updateInfo]);
|
|
90
91
|
|
|
92
|
+
const downloadAndInstallApk = useCallback(
|
|
93
|
+
(downloadUrl: string) => {
|
|
94
|
+
if (Platform.OS === 'android' && downloadUrl) {
|
|
95
|
+
client.downloadAndInstallApk(downloadUrl, setProgress);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
[client],
|
|
99
|
+
);
|
|
100
|
+
|
|
91
101
|
const checkUpdate = useCallback(async () => {
|
|
92
102
|
let info: CheckResult;
|
|
93
103
|
try {
|
|
@@ -106,7 +116,7 @@ export const PushyProvider = ({
|
|
|
106
116
|
onPress: () => {
|
|
107
117
|
if (downloadUrl) {
|
|
108
118
|
if (Platform.OS === 'android' && downloadUrl.endsWith('.apk')) {
|
|
109
|
-
|
|
119
|
+
downloadAndInstallApk(downloadUrl);
|
|
110
120
|
} else {
|
|
111
121
|
Linking.openURL(downloadUrl);
|
|
112
122
|
}
|
|
@@ -130,12 +140,13 @@ export const PushyProvider = ({
|
|
|
130
140
|
],
|
|
131
141
|
);
|
|
132
142
|
}
|
|
133
|
-
}, [client, downloadUpdate, showAlert]);
|
|
143
|
+
}, [client, downloadAndInstallApk, downloadUpdate, showAlert]);
|
|
134
144
|
|
|
135
145
|
const markSuccess = client.markSuccess;
|
|
136
146
|
|
|
137
147
|
useEffect(() => {
|
|
138
|
-
|
|
148
|
+
const { strategy, dismissErrorAfter, autoMarkSuccess } = options;
|
|
149
|
+
if (isFirstTime && autoMarkSuccess) {
|
|
139
150
|
markSuccess();
|
|
140
151
|
}
|
|
141
152
|
if (strategy === 'both' || strategy === 'onAppResume') {
|
|
@@ -152,7 +163,6 @@ export const PushyProvider = ({
|
|
|
152
163
|
checkUpdate();
|
|
153
164
|
}
|
|
154
165
|
let dismissErrorTimer: ReturnType<typeof setTimeout>;
|
|
155
|
-
const { dismissErrorAfter } = client.options;
|
|
156
166
|
if (typeof dismissErrorAfter === 'number' && dismissErrorAfter > 0) {
|
|
157
167
|
dismissErrorTimer = setTimeout(() => {
|
|
158
168
|
dismissError();
|
|
@@ -162,7 +172,7 @@ export const PushyProvider = ({
|
|
|
162
172
|
stateListener.current && stateListener.current.remove();
|
|
163
173
|
clearTimeout(dismissErrorTimer);
|
|
164
174
|
};
|
|
165
|
-
}, [checkUpdate,
|
|
175
|
+
}, [checkUpdate, options, dismissError, markSuccess]);
|
|
166
176
|
|
|
167
177
|
return (
|
|
168
178
|
<PushyContext.Provider
|
|
@@ -178,6 +188,8 @@ export const PushyProvider = ({
|
|
|
178
188
|
downloadUpdate,
|
|
179
189
|
packageVersion,
|
|
180
190
|
currentHash: currentVersion,
|
|
191
|
+
progress,
|
|
192
|
+
downloadAndInstallApk,
|
|
181
193
|
}}
|
|
182
194
|
>
|
|
183
195
|
{children}
|