react-native-update 10.3.1 → 10.4.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 +42 -16
- package/src/type.ts +1 -1
- package/src/utils.ts +0 -6
package/package.json
CHANGED
package/src/client.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
|
|
2
|
-
import {
|
|
2
|
+
import { log, testUrls } from './utils';
|
|
3
3
|
import {
|
|
4
4
|
EmitterSubscription,
|
|
5
5
|
PermissionsAndroid,
|
|
@@ -112,8 +112,7 @@ export class Pushy {
|
|
|
112
112
|
return true;
|
|
113
113
|
};
|
|
114
114
|
markSuccess = () => {
|
|
115
|
-
|
|
116
|
-
if (this.marked) {
|
|
115
|
+
if (this.marked || __DEV__) {
|
|
117
116
|
return;
|
|
118
117
|
}
|
|
119
118
|
this.marked = true;
|
|
@@ -121,7 +120,12 @@ export class Pushy {
|
|
|
121
120
|
this.report({ type: 'markSuccess' });
|
|
122
121
|
};
|
|
123
122
|
switchVersion = (hash: string) => {
|
|
124
|
-
|
|
123
|
+
if (__DEV__) {
|
|
124
|
+
console.warn(
|
|
125
|
+
'您调用了switchVersion方法,但是当前是开发环境,不会进行任何操作。',
|
|
126
|
+
);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
125
129
|
if (this.assertHash(hash) && !this.applyingUpdate) {
|
|
126
130
|
log('switchVersion: ' + hash);
|
|
127
131
|
this.applyingUpdate = true;
|
|
@@ -130,14 +134,18 @@ export class Pushy {
|
|
|
130
134
|
};
|
|
131
135
|
|
|
132
136
|
switchVersionLater = (hash: string) => {
|
|
133
|
-
|
|
137
|
+
if (__DEV__) {
|
|
138
|
+
console.warn(
|
|
139
|
+
'您调用了switchVersionLater方法,但是当前是开发环境,不会进行任何操作。',
|
|
140
|
+
);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
134
143
|
if (this.assertHash(hash)) {
|
|
135
144
|
log('switchVersionLater: ' + hash);
|
|
136
145
|
PushyModule.setNeedUpdate({ hash });
|
|
137
146
|
}
|
|
138
147
|
};
|
|
139
148
|
checkUpdate = async () => {
|
|
140
|
-
assertRelease();
|
|
141
149
|
const now = Date.now();
|
|
142
150
|
if (
|
|
143
151
|
this.lastRespJson &&
|
|
@@ -148,18 +156,22 @@ export class Pushy {
|
|
|
148
156
|
}
|
|
149
157
|
this.lastChecking = now;
|
|
150
158
|
this.report({ type: 'checking' });
|
|
159
|
+
const fetchBody = {
|
|
160
|
+
packageVersion,
|
|
161
|
+
hash: currentVersion,
|
|
162
|
+
buildTime,
|
|
163
|
+
cInfo,
|
|
164
|
+
};
|
|
165
|
+
if (__DEV__) {
|
|
166
|
+
delete fetchBody.buildTime;
|
|
167
|
+
}
|
|
151
168
|
const fetchPayload = {
|
|
152
169
|
method: 'POST',
|
|
153
170
|
headers: {
|
|
154
171
|
Accept: 'application/json',
|
|
155
172
|
'Content-Type': 'application/json',
|
|
156
173
|
},
|
|
157
|
-
body: JSON.stringify(
|
|
158
|
-
packageVersion,
|
|
159
|
-
hash: currentVersion,
|
|
160
|
-
buildTime,
|
|
161
|
-
cInfo,
|
|
162
|
-
}),
|
|
174
|
+
body: JSON.stringify(fetchBody),
|
|
163
175
|
};
|
|
164
176
|
let resp;
|
|
165
177
|
try {
|
|
@@ -225,7 +237,6 @@ export class Pushy {
|
|
|
225
237
|
info: CheckResult,
|
|
226
238
|
onDownloadProgress?: (data: ProgressData) => void,
|
|
227
239
|
) => {
|
|
228
|
-
assertRelease();
|
|
229
240
|
const {
|
|
230
241
|
hash,
|
|
231
242
|
diffUrl: _diffUrl,
|
|
@@ -275,7 +286,11 @@ export class Pushy {
|
|
|
275
286
|
});
|
|
276
287
|
succeeded = true;
|
|
277
288
|
} catch (e: any) {
|
|
278
|
-
|
|
289
|
+
if (__DEV__) {
|
|
290
|
+
succeeded = true;
|
|
291
|
+
} else {
|
|
292
|
+
log(`diff error: ${e.message}, try pdiff`);
|
|
293
|
+
}
|
|
279
294
|
}
|
|
280
295
|
}
|
|
281
296
|
const pdiffUrl = (await testUrls(pdiffUrls)) || _pdiffUrl;
|
|
@@ -288,7 +303,11 @@ export class Pushy {
|
|
|
288
303
|
});
|
|
289
304
|
succeeded = true;
|
|
290
305
|
} catch (e: any) {
|
|
291
|
-
|
|
306
|
+
if (__DEV__) {
|
|
307
|
+
succeeded = true;
|
|
308
|
+
} else {
|
|
309
|
+
log(`pdiff error: ${e.message}, try full patch`);
|
|
310
|
+
}
|
|
292
311
|
}
|
|
293
312
|
}
|
|
294
313
|
const updateUrl = (await testUrls(updateUrls)) || _updateUrl;
|
|
@@ -301,13 +320,20 @@ export class Pushy {
|
|
|
301
320
|
});
|
|
302
321
|
succeeded = true;
|
|
303
322
|
} catch (e: any) {
|
|
304
|
-
|
|
323
|
+
if (__DEV__) {
|
|
324
|
+
succeeded = true;
|
|
325
|
+
} else {
|
|
326
|
+
log(`full patch error: ${e.message}`);
|
|
327
|
+
}
|
|
305
328
|
}
|
|
306
329
|
}
|
|
307
330
|
if (this.progressHandlers[hash]) {
|
|
308
331
|
this.progressHandlers[hash].remove();
|
|
309
332
|
delete this.progressHandlers[hash];
|
|
310
333
|
}
|
|
334
|
+
if (__DEV__) {
|
|
335
|
+
return hash;
|
|
336
|
+
}
|
|
311
337
|
if (!succeeded) {
|
|
312
338
|
return this.report({
|
|
313
339
|
type: 'errorUpdate',
|
package/src/type.ts
CHANGED
|
@@ -70,7 +70,7 @@ export interface PushyOptions {
|
|
|
70
70
|
server?: PushyServerConfig;
|
|
71
71
|
logger?: UpdateEventsLogger;
|
|
72
72
|
useAlert?: boolean;
|
|
73
|
-
strategy?: 'onAppStart' | 'onAppResume' | 'both';
|
|
73
|
+
strategy?: 'onAppStart' | 'onAppResume' | 'both' | null;
|
|
74
74
|
autoMarkSuccess?: boolean;
|
|
75
75
|
dismissErrorAfter?: number;
|
|
76
76
|
}
|
package/src/utils.ts
CHANGED
|
@@ -2,12 +2,6 @@ export function log(...args: any[]) {
|
|
|
2
2
|
console.log('pushy: ', ...args);
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export function assertRelease() {
|
|
6
|
-
if (__DEV__) {
|
|
7
|
-
throw new Error('react-native-update 只能在 RELEASE 版本中运行.');
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
5
|
const ping = async (url: string) =>
|
|
12
6
|
Promise.race([
|
|
13
7
|
fetch(url, {
|