react-native-update 10.0.0-beta.1 → 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 +2 -2
- package/src/client.tsx +4 -4
- package/src/client.web.js +13 -0
- package/src/context.ts +2 -0
- package/src/provider.tsx +27 -15
- package/src/provider.web.js +2 -0
- package/src/type.ts +14 -24
- package/src/index.web.js +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-update",
|
|
3
|
-
"version": "10.0.0-beta.
|
|
3
|
+
"version": "10.0.0-beta.3",
|
|
4
4
|
"description": "react-native hot update",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": ">=16.8.0",
|
|
43
|
-
"react-native": ">=0.
|
|
43
|
+
"react-native": ">=0.59.0"
|
|
44
44
|
},
|
|
45
45
|
"homepage": "https://github.com/reactnativecn/react-native-pushy#readme",
|
|
46
46
|
"dependencies": {
|
package/src/client.tsx
CHANGED
|
@@ -154,7 +154,6 @@ export class Pushy {
|
|
|
154
154
|
if (resp.status !== 200) {
|
|
155
155
|
report({
|
|
156
156
|
type: 'errorChecking',
|
|
157
|
-
//@ts-ignore
|
|
158
157
|
message: result.message,
|
|
159
158
|
});
|
|
160
159
|
}
|
|
@@ -187,11 +186,11 @@ export class Pushy {
|
|
|
187
186
|
onDownloadProgress?: (data: ProgressData) => void,
|
|
188
187
|
) => {
|
|
189
188
|
assertRelease();
|
|
190
|
-
if (!('update' in info)) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
189
|
const { hash, diffUrl, pdiffUrl, updateUrl, name, description, metaInfo } =
|
|
194
190
|
info;
|
|
191
|
+
if (!info.update || !hash) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
195
194
|
if (rolledBackVersion === hash) {
|
|
196
195
|
log(`rolledback hash ${rolledBackVersion}, ignored`);
|
|
197
196
|
return;
|
|
@@ -262,6 +261,7 @@ export class Pushy {
|
|
|
262
261
|
data: { newVersion: hash },
|
|
263
262
|
});
|
|
264
263
|
}
|
|
264
|
+
log('downloaded hash:', hash);
|
|
265
265
|
setLocalHashInfo(hash, {
|
|
266
266
|
name,
|
|
267
267
|
description,
|
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,31 +38,31 @@ 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(() => {
|
|
48
|
-
if (updateInfo &&
|
|
49
|
+
if (updateInfo && updateInfo.hash) {
|
|
49
50
|
client.switchVersion(updateInfo.hash);
|
|
50
51
|
}
|
|
51
52
|
}, [client, updateInfo]);
|
|
52
53
|
|
|
53
54
|
const switchVersionLater = useCallback(() => {
|
|
54
|
-
if (updateInfo &&
|
|
55
|
+
if (updateInfo && updateInfo.hash) {
|
|
55
56
|
client.switchVersionLater(updateInfo.hash);
|
|
56
57
|
}
|
|
57
58
|
}, [client, updateInfo]);
|
|
58
59
|
|
|
59
60
|
const downloadUpdate = useCallback(async () => {
|
|
60
|
-
if (!updateInfo || !
|
|
61
|
+
if (!updateInfo || !updateInfo.update) {
|
|
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 {
|
|
@@ -98,7 +108,7 @@ export const PushyProvider = ({
|
|
|
98
108
|
return;
|
|
99
109
|
}
|
|
100
110
|
setUpdateInfo(info);
|
|
101
|
-
if (
|
|
111
|
+
if (info.expired) {
|
|
102
112
|
const { downloadUrl } = info;
|
|
103
113
|
showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
|
|
104
114
|
{
|
|
@@ -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
|
}
|
|
@@ -114,7 +124,7 @@ export const PushyProvider = ({
|
|
|
114
124
|
},
|
|
115
125
|
},
|
|
116
126
|
]);
|
|
117
|
-
} else if (
|
|
127
|
+
} else if (info.update) {
|
|
118
128
|
showAlert(
|
|
119
129
|
'提示',
|
|
120
130
|
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,
|
|
@@ -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}
|
package/src/type.ts
CHANGED
|
@@ -1,31 +1,19 @@
|
|
|
1
|
-
export interface
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export interface UpdateAvailableResult {
|
|
12
|
-
upToDate: false;
|
|
13
|
-
update: true;
|
|
14
|
-
name: string; // version name
|
|
15
|
-
hash: string;
|
|
16
|
-
description: string;
|
|
17
|
-
metaInfo: string;
|
|
18
|
-
pdiffUrl: string;
|
|
1
|
+
export interface CheckResult {
|
|
2
|
+
upToDate?: true;
|
|
3
|
+
expired?: true;
|
|
4
|
+
downloadUrl?: string;
|
|
5
|
+
update?: true;
|
|
6
|
+
name?: string; // version name
|
|
7
|
+
hash?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
metaInfo?: string;
|
|
10
|
+
pdiffUrl?: string;
|
|
19
11
|
diffUrl?: string;
|
|
20
12
|
updateUrl?: string;
|
|
13
|
+
paused?: 'app' | 'package';
|
|
14
|
+
message?: string;
|
|
21
15
|
}
|
|
22
16
|
|
|
23
|
-
export type CheckResult =
|
|
24
|
-
| ExpiredResult
|
|
25
|
-
| UpTodateResult
|
|
26
|
-
| UpdateAvailableResult
|
|
27
|
-
| {};
|
|
28
|
-
|
|
29
17
|
export interface ProgressData {
|
|
30
18
|
hash: string;
|
|
31
19
|
received: number;
|
|
@@ -59,6 +47,7 @@ export interface EventData {
|
|
|
59
47
|
newVersion?: string;
|
|
60
48
|
[key: string]: any;
|
|
61
49
|
}
|
|
50
|
+
|
|
62
51
|
export type UpdateEventsLogger = ({
|
|
63
52
|
type,
|
|
64
53
|
data,
|
|
@@ -72,6 +61,7 @@ export interface PushyServerConfig {
|
|
|
72
61
|
backups?: string[];
|
|
73
62
|
queryUrl?: string;
|
|
74
63
|
}
|
|
64
|
+
|
|
75
65
|
export interface PushyOptions {
|
|
76
66
|
appKey: string;
|
|
77
67
|
server?: PushyServerConfig;
|
package/src/index.web.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Fragment } from 'react';
|
|
2
|
-
|
|
3
|
-
const noop = () => {};
|
|
4
|
-
export class Pushy {
|
|
5
|
-
constructor() {
|
|
6
|
-
console.warn('react-native-update is not supported and will do nothing on web.');
|
|
7
|
-
return new Proxy(this, {
|
|
8
|
-
get() {
|
|
9
|
-
return noop;
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { PushyContext, usePushy } from './context';
|
|
16
|
-
|
|
17
|
-
export const PushyProvider = Fragment;
|