react-native-update 10.0.2 → 10.1.0
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 +51 -13
- package/src/core.ts +0 -39
package/package.json
CHANGED
package/src/client.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CheckResult, PushyOptions, ProgressData } from './type';
|
|
1
|
+
import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
|
|
2
2
|
import { assertRelease, log } from './utils';
|
|
3
3
|
import {
|
|
4
4
|
EmitterSubscription,
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
pushyNativeEventEmitter,
|
|
13
13
|
currentVersion,
|
|
14
14
|
packageVersion,
|
|
15
|
-
report,
|
|
16
15
|
rolledBackVersion,
|
|
17
16
|
setLocalHashInfo,
|
|
17
|
+
isRolledBack,
|
|
18
18
|
} from './core';
|
|
19
19
|
|
|
20
20
|
const defaultServer = {
|
|
@@ -25,6 +25,8 @@ const defaultServer = {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
const empty = {};
|
|
28
|
+
const noop = () => {};
|
|
29
|
+
|
|
28
30
|
export class Pushy {
|
|
29
31
|
options: PushyOptions = {
|
|
30
32
|
appKey: '',
|
|
@@ -32,6 +34,7 @@ export class Pushy {
|
|
|
32
34
|
autoMarkSuccess: true,
|
|
33
35
|
useAlert: true,
|
|
34
36
|
strategy: 'both',
|
|
37
|
+
logger: noop,
|
|
35
38
|
};
|
|
36
39
|
|
|
37
40
|
lastChecking: number;
|
|
@@ -55,10 +58,45 @@ export class Pushy {
|
|
|
55
58
|
for (const [key, value] of Object.entries(options)) {
|
|
56
59
|
if (value !== undefined) {
|
|
57
60
|
this.options[key] = value;
|
|
61
|
+
if (key === 'logger') {
|
|
62
|
+
if (isRolledBack) {
|
|
63
|
+
this.report({
|
|
64
|
+
type: 'rollback',
|
|
65
|
+
data: {
|
|
66
|
+
rolledBackVersion,
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
58
71
|
}
|
|
59
72
|
}
|
|
60
73
|
};
|
|
61
74
|
|
|
75
|
+
report = ({
|
|
76
|
+
type,
|
|
77
|
+
message = '',
|
|
78
|
+
data = {},
|
|
79
|
+
}: {
|
|
80
|
+
type: EventType;
|
|
81
|
+
message?: string;
|
|
82
|
+
data?: Record<string, string | number>;
|
|
83
|
+
}) => {
|
|
84
|
+
log(type + ' ' + message);
|
|
85
|
+
const { logger = noop, appKey } = this.options;
|
|
86
|
+
logger({
|
|
87
|
+
type,
|
|
88
|
+
data: {
|
|
89
|
+
appKey,
|
|
90
|
+
currentVersion,
|
|
91
|
+
cInfo,
|
|
92
|
+
packageVersion,
|
|
93
|
+
buildTime,
|
|
94
|
+
message,
|
|
95
|
+
...data,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
62
100
|
getCheckUrl = (endpoint: string = this.options.server!.main) => {
|
|
63
101
|
return `${endpoint}/checkUpdate/${this.options.appKey}`;
|
|
64
102
|
};
|
|
@@ -79,7 +117,7 @@ export class Pushy {
|
|
|
79
117
|
}
|
|
80
118
|
this.marked = true;
|
|
81
119
|
PushyModule.markSuccess();
|
|
82
|
-
report({ type: 'markSuccess' });
|
|
120
|
+
this.report({ type: 'markSuccess' });
|
|
83
121
|
};
|
|
84
122
|
switchVersion = (hash: string) => {
|
|
85
123
|
assertRelease();
|
|
@@ -108,7 +146,7 @@ export class Pushy {
|
|
|
108
146
|
return this.lastResult;
|
|
109
147
|
}
|
|
110
148
|
this.lastChecking = now;
|
|
111
|
-
report({ type: 'checking' });
|
|
149
|
+
this.report({ type: 'checking' });
|
|
112
150
|
const fetchPayload = {
|
|
113
151
|
method: 'POST',
|
|
114
152
|
headers: {
|
|
@@ -126,7 +164,7 @@ export class Pushy {
|
|
|
126
164
|
try {
|
|
127
165
|
resp = await fetch(this.getCheckUrl(), fetchPayload);
|
|
128
166
|
} catch (e) {
|
|
129
|
-
report({
|
|
167
|
+
this.report({
|
|
130
168
|
type: 'errorChecking',
|
|
131
169
|
message: 'Can not connect to update server. Trying backup endpoints.',
|
|
132
170
|
});
|
|
@@ -142,7 +180,7 @@ export class Pushy {
|
|
|
142
180
|
}
|
|
143
181
|
}
|
|
144
182
|
if (!resp) {
|
|
145
|
-
report({
|
|
183
|
+
this.report({
|
|
146
184
|
type: 'errorChecking',
|
|
147
185
|
message: 'Can not connect to update server. Please check your network.',
|
|
148
186
|
});
|
|
@@ -153,7 +191,7 @@ export class Pushy {
|
|
|
153
191
|
this.lastResult = result;
|
|
154
192
|
|
|
155
193
|
if (resp.status !== 200) {
|
|
156
|
-
report({
|
|
194
|
+
this.report({
|
|
157
195
|
type: 'errorChecking',
|
|
158
196
|
message: result.message,
|
|
159
197
|
});
|
|
@@ -214,7 +252,7 @@ export class Pushy {
|
|
|
214
252
|
);
|
|
215
253
|
}
|
|
216
254
|
let succeeded = false;
|
|
217
|
-
report({ type: 'downloading' });
|
|
255
|
+
this.report({ type: 'downloading' });
|
|
218
256
|
if (diffUrl) {
|
|
219
257
|
log('downloading diff');
|
|
220
258
|
try {
|
|
@@ -257,7 +295,7 @@ export class Pushy {
|
|
|
257
295
|
delete this.progressHandlers[hash];
|
|
258
296
|
}
|
|
259
297
|
if (!succeeded) {
|
|
260
|
-
return report({
|
|
298
|
+
return this.report({
|
|
261
299
|
type: 'errorUpdate',
|
|
262
300
|
data: { newVersion: hash },
|
|
263
301
|
});
|
|
@@ -278,17 +316,17 @@ export class Pushy {
|
|
|
278
316
|
if (Platform.OS !== 'android') {
|
|
279
317
|
return;
|
|
280
318
|
}
|
|
281
|
-
report({ type: 'downloadingApk' });
|
|
319
|
+
this.report({ type: 'downloadingApk' });
|
|
282
320
|
if (Platform.Version <= 23) {
|
|
283
321
|
try {
|
|
284
322
|
const granted = await PermissionsAndroid.request(
|
|
285
323
|
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
|
|
286
324
|
);
|
|
287
325
|
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
|
|
288
|
-
return report({ type: 'rejectStoragePermission' });
|
|
326
|
+
return this.report({ type: 'rejectStoragePermission' });
|
|
289
327
|
}
|
|
290
328
|
} catch (err) {
|
|
291
|
-
return report({ type: 'errorStoragePermission' });
|
|
329
|
+
return this.report({ type: 'errorStoragePermission' });
|
|
292
330
|
}
|
|
293
331
|
}
|
|
294
332
|
const progressKey = 'downloadingApk';
|
|
@@ -307,7 +345,7 @@ export class Pushy {
|
|
|
307
345
|
target: 'update.apk',
|
|
308
346
|
hash: progressKey,
|
|
309
347
|
}).catch(() => {
|
|
310
|
-
report({ type: 'errowDownloadAndInstallApk' });
|
|
348
|
+
this.report({ type: 'errowDownloadAndInstallApk' });
|
|
311
349
|
});
|
|
312
350
|
if (this.progressHandlers[progressKey]) {
|
|
313
351
|
this.progressHandlers[progressKey].remove();
|
package/src/core.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
|
2
|
-
import { EventType, UpdateEventsLogger } from './type';
|
|
3
2
|
import { log } from './utils';
|
|
4
3
|
const {
|
|
5
4
|
version: v,
|
|
@@ -58,44 +57,6 @@ if (!uuid) {
|
|
|
58
57
|
PushyModule.setUuid(uuid);
|
|
59
58
|
}
|
|
60
59
|
|
|
61
|
-
const noop = () => {};
|
|
62
|
-
let reporter: UpdateEventsLogger = noop;
|
|
63
|
-
|
|
64
|
-
export function onPushyEvents(customReporter: UpdateEventsLogger) {
|
|
65
|
-
reporter = customReporter;
|
|
66
|
-
if (isRolledBack) {
|
|
67
|
-
report({
|
|
68
|
-
type: 'rollback',
|
|
69
|
-
data: {
|
|
70
|
-
rolledBackVersion,
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function report({
|
|
77
|
-
type,
|
|
78
|
-
message = '',
|
|
79
|
-
data = {},
|
|
80
|
-
}: {
|
|
81
|
-
type: EventType;
|
|
82
|
-
message?: string;
|
|
83
|
-
data?: Record<string, string | number>;
|
|
84
|
-
}) {
|
|
85
|
-
log(type + ' ' + message);
|
|
86
|
-
reporter({
|
|
87
|
-
type,
|
|
88
|
-
data: {
|
|
89
|
-
currentVersion,
|
|
90
|
-
cInfo,
|
|
91
|
-
packageVersion,
|
|
92
|
-
buildTime,
|
|
93
|
-
message,
|
|
94
|
-
...data,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
60
|
log('uuid: ' + uuid);
|
|
100
61
|
|
|
101
62
|
export const cInfo = {
|