react-native-update 10.0.0-beta.0 → 10.0.0-beta.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.
- package/package.json +2 -2
- package/src/client.tsx +3 -4
- package/src/client.web.js +13 -0
- package/src/context.ts +8 -4
- package/src/provider.tsx +8 -6
- 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.2",
|
|
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;
|
package/src/context.ts
CHANGED
|
@@ -12,19 +12,23 @@ export const defaultContext = {
|
|
|
12
12
|
markSuccess: noop,
|
|
13
13
|
dismissError: noop,
|
|
14
14
|
downloadUpdate: noop,
|
|
15
|
+
currentHash: '',
|
|
16
|
+
packageVersion: '',
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
export const PushyContext = createContext<{
|
|
18
20
|
checkUpdate: () => void;
|
|
19
21
|
switchVersion: () => void;
|
|
20
22
|
switchVersionLater: () => void;
|
|
21
|
-
progress?: ProgressData;
|
|
22
23
|
markSuccess: () => void;
|
|
23
|
-
updateInfo?: CheckResult;
|
|
24
|
-
lastError?: Error;
|
|
25
24
|
dismissError: () => void;
|
|
26
|
-
client?: Pushy;
|
|
27
25
|
downloadUpdate: () => void;
|
|
26
|
+
currentHash: string;
|
|
27
|
+
packageVersion: string;
|
|
28
|
+
client?: Pushy;
|
|
29
|
+
progress?: ProgressData;
|
|
30
|
+
updateInfo?: CheckResult;
|
|
31
|
+
lastError?: Error;
|
|
28
32
|
}>(defaultContext);
|
|
29
33
|
|
|
30
34
|
export const usePushy = () => useContext(PushyContext);
|
package/src/provider.tsx
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
Linking,
|
|
14
14
|
} from 'react-native';
|
|
15
15
|
import { Pushy } from './client';
|
|
16
|
-
import { isFirstTime } from './core';
|
|
16
|
+
import { currentVersion, isFirstTime, packageVersion } from './core';
|
|
17
17
|
import { CheckResult } from './type';
|
|
18
18
|
import { PushyContext } from './context';
|
|
19
19
|
|
|
@@ -45,19 +45,19 @@ export const PushyProvider = ({
|
|
|
45
45
|
);
|
|
46
46
|
|
|
47
47
|
const switchVersion = useCallback(() => {
|
|
48
|
-
if (updateInfo &&
|
|
48
|
+
if (updateInfo && updateInfo.hash) {
|
|
49
49
|
client.switchVersion(updateInfo.hash);
|
|
50
50
|
}
|
|
51
51
|
}, [client, updateInfo]);
|
|
52
52
|
|
|
53
53
|
const switchVersionLater = useCallback(() => {
|
|
54
|
-
if (updateInfo &&
|
|
54
|
+
if (updateInfo && updateInfo.hash) {
|
|
55
55
|
client.switchVersionLater(updateInfo.hash);
|
|
56
56
|
}
|
|
57
57
|
}, [client, updateInfo]);
|
|
58
58
|
|
|
59
59
|
const downloadUpdate = useCallback(async () => {
|
|
60
|
-
if (!updateInfo || !
|
|
60
|
+
if (!updateInfo || !updateInfo.update) {
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
try {
|
|
@@ -98,7 +98,7 @@ export const PushyProvider = ({
|
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
setUpdateInfo(info);
|
|
101
|
-
if (
|
|
101
|
+
if (info.expired) {
|
|
102
102
|
const { downloadUrl } = info;
|
|
103
103
|
showAlert('提示', '您的应用版本已更新,点击更新下载安装新版本', [
|
|
104
104
|
{
|
|
@@ -114,7 +114,7 @@ export const PushyProvider = ({
|
|
|
114
114
|
},
|
|
115
115
|
},
|
|
116
116
|
]);
|
|
117
|
-
} else if (
|
|
117
|
+
} else if (info.update) {
|
|
118
118
|
showAlert(
|
|
119
119
|
'提示',
|
|
120
120
|
'检查到新的版本' + info.name + ',是否下载?\n' + info.description,
|
|
@@ -176,6 +176,8 @@ export const PushyProvider = ({
|
|
|
176
176
|
markSuccess,
|
|
177
177
|
client,
|
|
178
178
|
downloadUpdate,
|
|
179
|
+
packageVersion,
|
|
180
|
+
currentHash: currentVersion,
|
|
179
181
|
}}
|
|
180
182
|
>
|
|
181
183
|
{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;
|