1
0
mirror of https://gitcode.com/gh_mirrors/re/react-native-pushy.git synced 2025-09-17 15:16:10 +08:00
Code Issues Packages Projects Releases Wiki Activity GitHub Gitee

Compare commits

..

1 Commits

Author SHA1 Message Date
sunnylqm
f59be2749e v10.11.2 2024-07-29 00:56:57 +08:00
13 changed files with 77 additions and 227 deletions

View File

@@ -94,7 +94,7 @@ apply from: "../../node_modules/react-native/react.gradle"
* Upload all the APKs to the Play Store and people will download
* the correct one based on the CPU architecture of their device.
*/
def enableSeparateBuildPerCPUArchitecture = true
def enableSeparateBuildPerCPUArchitecture = false
/**
* Run Proguard to shrink the Java bytecode in release builds.

View File

@@ -20,7 +20,7 @@
"react-native-camera-kit": "^14.0.0-beta15",
"react-native-paper": "^5.12.1",
"react-native-safe-area-context": "^4.8.2",
"react-native-update": "^10.11.3",
"react-native-update": "^10.11.0",
"react-native-vector-icons": "^10.0.3"
},
"devDependencies": {

View File

@@ -1,6 +1,6 @@
/* eslint-disable react/no-unstable-nested-components */
/* eslint-disable react-native/no-inline-styles */
import React, {useRef, useState} from 'react';
import React, {useState} from 'react';
import {
StyleSheet,
Platform,
@@ -47,7 +47,6 @@ function App() {
const snackbarVisible =
!useDefaultAlert && showUpdateSnackbar && updateInfo?.update;
const [showCamera, setShowCamera] = useState(false);
const lastParsedCode = useRef('');
return (
<View style={styles.container}>
@@ -74,16 +73,9 @@ function App() {
style={{minHeight: 320}}
scanBarcode={true}
onReadCode={({nativeEvent: {codeStringValue}}) => {
// 防止重复扫码
if (lastParsedCode.current === codeStringValue) {
return;
}
lastParsedCode.current = codeStringValue;
setTimeout(() => {
lastParsedCode.current = '';
}, 1000);
setShowCamera(false);
console.log(codeStringValue);
parseTestQrCode(codeStringValue);
setShowCamera(false);
}} // optional
showFrame={true} // (default false) optional, show frame with transparent layer (qr code or barcode will be read on this area ONLY), start animation for scanner, that stops when a code has been found. Frame always at center of the screen
laserColor="red" // (default red) optional, color of laser in scanner frame

View File

@@ -2123,7 +2123,7 @@ buffer-from@^1.0.0:
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==
buffer@^5.4.3, buffer@^5.5.0:
buffer@^5.5.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
@@ -6159,7 +6159,7 @@ pump@^3.0.0:
end-of-stream "^1.1.0"
once "^1.3.1"
punycode@^2.1.0, punycode@^2.1.1:
punycode@^2.1.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.1.tgz#027422e2faec0b25e1549c3e1bd8309b9133b6e5"
integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==
@@ -6236,20 +6236,12 @@ react-native-safe-area-context@^4.8.2:
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-4.8.2.tgz#e6b3d8acf3c6afcb4b5db03a97f9c37df7668f65"
integrity sha512-ffUOv8BJQ6RqO3nLml5gxJ6ab3EestPiyWekxdzO/1MQ7NF8fW1Mzh1C5QE9yq573Xefnc7FuzGXjtesZGv7cQ==
react-native-update@^10.11.3:
version "10.11.3"
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.11.3.tgz#5fa44fdd12514eb5e7901a5d664f00fd082d6774"
integrity sha512-adI3sly0yFt1DfaPqICJ9VwzUoa/XAngv/N7SnICkLxO3jgccBgy0OrXDBxRn43Zeumdq40Z+ADTE5qrY4BWAw==
react-native-update@^10.11.0:
version "10.11.0"
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.11.0.tgz#29f7a4dd847d2b9b7dbc720ccfaa1eabae82616d"
integrity sha512-YPnJPGN38LqZvNgDEeqyjJqHs6sRGL2vxUt9pW0jRUx8wrTjBSf29bGQ55EonKa2Dsl8cqikr/zefImWqTLoMg==
dependencies:
nanoid "^3.3.3"
react-native-url-polyfill "^2.0.0"
react-native-url-polyfill@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/react-native-url-polyfill/-/react-native-url-polyfill-2.0.0.tgz#db714520a2985cff1d50ab2e66279b9f91ffd589"
integrity sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA==
dependencies:
whatwg-url-without-unicode "8.0.0-3"
react-native-vector-icons@^10.0.3:
version "10.0.3"
@@ -7498,25 +7490,11 @@ webidl-conversions@^3.0.0:
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==
webidl-conversions@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-5.0.0.tgz#ae59c8a00b121543a2acc65c0434f57b0fc11aff"
integrity sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==
whatwg-fetch@^3.0.0:
version "3.6.20"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz#580ce6d791facec91d37c72890995a0b48d31c70"
integrity sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==
whatwg-url-without-unicode@8.0.0-3:
version "8.0.0-3"
resolved "https://registry.yarnpkg.com/whatwg-url-without-unicode/-/whatwg-url-without-unicode-8.0.0-3.tgz#ab6df4bf6caaa6c85a59f6e82c026151d4bb376b"
integrity sha512-HoKuzZrUlgpz35YO27XgD28uh/WJH4B0+3ttFqRo//lmq+9T/mIOJ6kqmINI9HpUpz1imRC/nR/lxKpJiv0uig==
dependencies:
buffer "^5.4.3"
punycode "^2.1.1"
webidl-conversions "^5.0.0"
whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"

View File

@@ -75,7 +75,7 @@ RCT_EXPORT_MODULE(RCTPushy);
if (needClearPushyInfo) {
[defaults setObject:nil forKey:keyPushyInfo];
[defaults setObject:@(YES) forKey:KeyPackageUpdatedMarked];
[defaults synchronize];
// ...need clear files later
}
else {
@@ -97,7 +97,7 @@ RCT_EXPORT_MODULE(RCTPushy);
newInfo[paramIsFirstTime] = @(NO);
[defaults setObject:newInfo forKey:keyPushyInfo];
[defaults setObject:@(YES) forKey:keyFirstLoadMarked];
[defaults synchronize];
}
NSString *downloadDir = [RCTPushy downloadDir];
@@ -137,7 +137,7 @@ RCT_EXPORT_MODULE(RCTPushy);
[defaults setObject:nil forKey:keyPushyInfo];
}
[defaults setObject:curVersion forKey:keyRolledBackMarked];
[defaults synchronize];
return lastVersion;
}
@@ -176,7 +176,7 @@ RCT_EXPORT_MODULE(RCTPushy);
[defaults setObject:nil forKey:KeyPackageUpdatedMarked];
[self clearInvalidFiles];
}
[defaults synchronize];
return ret;
}
@@ -196,7 +196,7 @@ RCT_EXPORT_METHOD(setUuid:(NSString *)uuid resolver:(RCTPromiseResolveBlock)res
@try {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:uuid forKey:keyUuid];
[defaults synchronize];
resolve(@true);
}
@catch (NSException *exception) {
@@ -214,7 +214,7 @@ RCT_EXPORT_METHOD(setLocalHashInfo:(NSString *)hash
if (object && [object isKindOfClass:[NSDictionary class]]) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:value forKey:[keyHashInfo stringByAppendingString:hash]];
[defaults synchronize];
resolve(@true);
} else {
reject(@"json格式校验报错", nil, nil);
@@ -295,7 +295,7 @@ RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options
newInfo[paramPackageVersion] = [RCTPushy packageVersion];
[defaults setObject:newInfo forKey:keyPushyInfo];
[defaults synchronize];
resolve(@true);
}else{
reject(@"执行报错", nil, nil);
@@ -329,7 +329,8 @@ RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options
}
}
RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
RCT_EXPORT_METHOD(markSuccess:
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
{
@@ -346,7 +347,7 @@ RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
[pushyInfo removeObjectForKey:[keyHashInfo stringByAppendingString:lastVersion]];
}
[defaults setObject:pushyInfo forKey:keyPushyInfo];
[defaults synchronize];
// clear other package dir
[self clearInvalidFiles];
@@ -609,7 +610,7 @@ RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared<facebook::react::NativePushySpecJSI>(params);
return std::make_shared<facebook::react::NativeUpdateSpecJSI>(params);
}
#endif

View File

@@ -1,6 +1,6 @@
{
"name": "react-native-update",
"version": "10.14.0",
"version": "10.11.2",
"description": "react-native hot update",
"main": "src/index",
"scripts": {

View File

@@ -1,5 +1,5 @@
import { CheckResult, PushyOptions, ProgressData, EventType } from './type';
import { joinUrls, log, testUrls } from './utils';
import { log, testUrls } from './utils';
import { EmitterSubscription, Platform } from 'react-native';
import { PermissionsAndroid } from './permissions';
import {
@@ -64,7 +64,8 @@ export class Pushy {
setOptions = (options: Partial<PushyOptions>) => {
for (const [key, value] of Object.entries(options)) {
if (value !== undefined) {
(this.options as any)[key] = value;
// @ts-expect-error
this.options[key] = value;
if (key === 'logger') {
if (isRolledBack) {
this.report({
@@ -125,7 +126,7 @@ export class Pushy {
PushyModule.markSuccess();
this.report({ type: 'markSuccess' });
};
switchVersion = async (hash: string) => {
switchVersion = (hash: string) => {
if (__DEV__) {
console.warn(
'您调用了switchVersion方法但是当前是开发环境不会进行任何操作。',
@@ -135,11 +136,11 @@ export class Pushy {
if (this.assertHash(hash) && !this.applyingUpdate) {
log('switchVersion: ' + hash);
this.applyingUpdate = true;
return PushyModule.reloadUpdate({ hash });
PushyModule.reloadUpdate({ hash });
}
};
switchVersionLater = async (hash: string) => {
switchVersionLater = (hash: string) => {
if (__DEV__) {
console.warn(
'您调用了switchVersionLater方法但是当前是开发环境不会进行任何操作。',
@@ -148,7 +149,7 @@ export class Pushy {
}
if (this.assertHash(hash)) {
log('switchVersionLater: ' + hash);
return PushyModule.setNeedUpdate({ hash });
PushyModule.setNeedUpdate({ hash });
}
};
checkUpdate = async (extra?: Record<string, any>) => {
@@ -162,13 +163,6 @@ export class Pushy {
console.warn('web 端不支持热更新检查');
return;
}
if (
this.options.beforeCheckUpdate &&
(await this.options.beforeCheckUpdate()) === false
) {
log('beforeCheckUpdate 返回 false, 忽略检查');
return;
}
const now = Date.now();
if (
this.lastRespJson &&
@@ -178,6 +172,7 @@ export class Pushy {
return await this.lastRespJson;
}
this.lastChecking = now;
this.report({ type: 'checking' });
const fetchBody = {
packageVersion,
hash: currentVersion,
@@ -188,21 +183,16 @@ export class Pushy {
if (__DEV__) {
delete fetchBody.buildTime;
}
const body = JSON.stringify(fetchBody);
const fetchPayload = {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body,
body: JSON.stringify(fetchBody),
};
let resp;
try {
this.report({
type: 'checking',
message: this.options.appKey + ': ' + body,
});
resp = await fetch(this.getCheckUrl(), fetchPayload);
} catch (e: any) {
this.report({
@@ -231,8 +221,6 @@ export class Pushy {
const result: CheckResult = await this.lastRespJson;
log('checking result:', result);
if (resp.status !== 200) {
this.report({
type: 'errorChecking',
@@ -271,21 +259,16 @@ export class Pushy {
) => {
const {
hash,
diff,
pdiff,
full,
paths = [],
diffUrl: _diffUrl,
diffUrls,
pdiffUrl: _pdiffUrl,
pdiffUrls,
updateUrl: _updateUrl,
updateUrls,
name,
description = '',
description,
metaInfo,
} = info;
if (
this.options.beforeDownloadUpdate &&
(await this.options.beforeDownloadUpdate(info)) === false
) {
log('beforeDownloadUpdate 返回 false, 忽略下载');
return;
}
if (!info.update || !hash) {
return;
}
@@ -310,10 +293,10 @@ export class Pushy {
},
);
}
let succeeded = '';
let succeeded = false;
this.report({ type: 'downloading' });
let lastError: any;
const diffUrl = await testUrls(joinUrls(paths, diff));
const diffUrl = (await testUrls(diffUrls)) || _diffUrl;
if (diffUrl) {
log('downloading diff');
try {
@@ -322,17 +305,17 @@ export class Pushy {
hash,
originHash: currentVersion,
});
succeeded = 'diff';
succeeded = true;
} catch (e: any) {
lastError = e;
if (__DEV__) {
succeeded = 'diff';
succeeded = true;
} else {
log(`diff error: ${e.message}, try pdiff`);
}
}
}
const pdiffUrl = await testUrls(joinUrls(paths, pdiff));
const pdiffUrl = (await testUrls(pdiffUrls)) || _pdiffUrl;
if (!succeeded && pdiffUrl) {
log('downloading pdiff');
try {
@@ -340,29 +323,29 @@ export class Pushy {
updateUrl: pdiffUrl,
hash,
});
succeeded = 'pdiff';
succeeded = true;
} catch (e: any) {
lastError = e;
if (__DEV__) {
succeeded = 'pdiff';
succeeded = true;
} else {
log(`pdiff error: ${e.message}, try full patch`);
}
}
}
const fullUrl = await testUrls(joinUrls(paths, full));
if (!succeeded && fullUrl) {
const updateUrl = (await testUrls(updateUrls)) || _updateUrl;
if (!succeeded && updateUrl) {
log('downloading full patch');
try {
await PushyModule.downloadFullUpdate({
updateUrl: fullUrl,
updateUrl: updateUrl,
hash,
});
succeeded = 'full';
succeeded = true;
} catch (e: any) {
lastError = e;
if (__DEV__) {
succeeded = 'full';
succeeded = true;
} else {
log(`full patch error: ${e.message}`);
}
@@ -384,13 +367,8 @@ export class Pushy {
throw lastError;
}
return;
} else {
this.report({
type: 'downloadSuccess',
data: { newVersion: hash, diff: succeeded },
});
}
log(`downloaded ${succeeded} hash:`, hash);
log('downloaded hash:', hash);
setLocalHashInfo(hash, {
name,
description,

View File

@@ -7,8 +7,8 @@ const asyncNoop = () => Promise.resolve();
export const defaultContext = {
checkUpdate: asyncNoop,
switchVersion: asyncNoop,
switchVersionLater: asyncNoop,
switchVersion: noop,
switchVersionLater: noop,
markSuccess: noop,
dismissError: noop,
downloadUpdate: asyncNoop,
@@ -21,8 +21,8 @@ export const defaultContext = {
export const PushyContext = createContext<{
checkUpdate: () => Promise<void>;
switchVersion: () => Promise<void>;
switchVersionLater: () => Promise<void>;
switchVersion: () => void;
switchVersionLater: () => void;
markSuccess: () => void;
dismissError: () => void;
downloadUpdate: () => Promise<void>;

View File

@@ -4,7 +4,9 @@ const {
version: v,
} = require('react-native/Libraries/Core/ReactNativeVersion');
const RNVersion = `${v.major}.${v.minor}.${v.patch}`;
const isTurboModuleEnabled = (global as any).__turboModuleProxy != null;
const isTurboModuleEnabled =
// @ts-expect-error
global.__turboModuleProxy != null;
export const PushyModule =
Platform.OS === 'web'
@@ -14,7 +16,7 @@ export const PushyModule =
: NativeModules.Pushy;
if (!PushyModule) {
throw new Error('react-native-update 模块无法加载,请对照安装文档检查配置。');
throw new Error('react-native-update模块无法加载请对照安装文档检查配置。');
}
const PushyConstants = isTurboModuleEnabled
@@ -33,7 +35,7 @@ let uuid = PushyConstants.uuid;
if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) {
throw new Error(
'react-native-update 模块无法加载,请对照文档检查 Bundle URL 的配置',
'react-native-update模块无法加载请对照文档检查Bundle URL的配置',
);
}

View File

@@ -1,77 +0,0 @@
/* eslint-disable no-fallthrough */
import { cInfo } from './core';
/* eslint-disable no-bitwise */
function murmurhash3_32_gc(key: string, seed = 0) {
let remainder, bytes, h1, h1b, c1, c2, k1, i;
remainder = key.length & 3; // key.length % 4
bytes = key.length - remainder;
h1 = seed;
c1 = 0xcc9e2d51;
c2 = 0x1b873593;
i = 0;
while (i < bytes) {
k1 =
(key.charCodeAt(i) & 0xff) |
((key.charCodeAt(++i) & 0xff) << 8) |
((key.charCodeAt(++i) & 0xff) << 16) |
((key.charCodeAt(++i) & 0xff) << 24);
++i;
((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff;
k1 = (k1 << 15) | (k1 >>> 17);
k1 =
((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff;
h1 ^= k1;
h1 = (h1 << 13) | (h1 >>> 19);
h1b =
((h1 & 0xffff) * 5 + ((((h1 >>> 16) * 5) & 0xffff) << 16)) & 0xffffffff;
h1 = (h1b & 0xffff) + 0x6b64 + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16);
}
k1 = 0;
switch (remainder) {
case 3:
k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16;
case 2:
k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8;
case 1:
k1 ^= key.charCodeAt(i) & 0xff;
k1 =
((k1 & 0xffff) * c1 + ((((k1 >>> 16) * c1) & 0xffff) << 16)) &
0xffffffff;
k1 = (k1 << 15) | (k1 >>> 17);
k1 =
((k1 & 0xffff) * c2 + ((((k1 >>> 16) * c2) & 0xffff) << 16)) &
0xffffffff;
h1 ^= k1;
}
h1 ^= key.length;
h1 ^= h1 >>> 16;
h1 =
((h1 & 0xffff) * 0x85ebca6b +
((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) &
0xffffffff;
h1 ^= h1 >>> 13;
h1 =
((h1 & 0xffff) * 0xc2b2ae35 +
((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16)) &
0xffffffff;
h1 ^= h1 >>> 16;
return h1 >>> 0;
}
const intForUUID = murmurhash3_32_gc(cInfo.uuid);
export function isInRollout(rollout: number) {
return intForUUID % 100 < rollout;
}

View File

@@ -22,8 +22,6 @@ import {
import { CheckResult, ProgressData, PushyTestPayload } from './type';
import { PushyContext } from './context';
import { URL } from 'react-native-url-polyfill';
import { isInRollout } from './isInRollout';
import { log } from './utils';
export const PushyProvider = ({
client,
@@ -75,18 +73,18 @@ export const PushyProvider = ({
);
const switchVersion = useCallback(
async (info: CheckResult | undefined = updateInfoRef.current) => {
(info: CheckResult | undefined = updateInfoRef.current) => {
if (info && info.hash) {
return client.switchVersion(info.hash);
client.switchVersion(info.hash);
}
},
[client],
);
const switchVersionLater = useCallback(
async (info: CheckResult | undefined = updateInfoRef.current) => {
(info: CheckResult | undefined = updateInfoRef.current) => {
if (info && info.hash) {
return client.switchVersionLater(info.hash);
client.switchVersionLater(info.hash);
}
},
[client],
@@ -149,7 +147,7 @@ export const PushyProvider = ({
);
const checkUpdate = useCallback(
async ({ extra }: { extra?: Record<string, any> } | undefined = {}) => {
async (extra?: Record<string, any>) => {
const now = Date.now();
if (lastChecking.current && now - lastChecking.current < 1000) {
return;
@@ -167,15 +165,6 @@ export const PushyProvider = ({
if (!info) {
return;
}
const rollout = info.config?.rollout;
if (rollout) {
if (!isInRollout(rollout)) {
log(`not in ${rollout}% rollout, ignored`);
return;
}
log(`in ${rollout}% rollout, continue`);
}
info.description = info.description ?? '';
updateInfoRef.current = info;
setUpdateInfo(info);
if (info.expired) {
@@ -283,7 +272,7 @@ export const PushyProvider = ({
Alert.alert(type, JSON.stringify(data));
};
if (payload.type === '__rnPushyVersionHash') {
checkUpdate({ extra: { toHash: payload.data } }).then(() => {
checkUpdate({ toHash: payload.data }).then(() => {
if (updateInfoRef.current && updateInfoRef.current.upToDate) {
Alert.alert(
'提示',
@@ -301,9 +290,10 @@ export const PushyProvider = ({
);
const parseTestQrCode = useCallback(
(code: string | PushyTestPayload) => {
(code: string) => {
let payload: PushyTestPayload;
try {
const payload = typeof code === 'string' ? JSON.parse(code) : code;
payload = JSON.parse(code);
return parseTestPayload(payload);
} catch {
return false;

View File

@@ -7,14 +7,12 @@ export interface CheckResult {
hash?: string;
description?: string;
metaInfo?: string;
config?: {
rollout?: number;
[key: string]: any;
};
pdiff?: string;
diff?: string;
full?: string;
paths?: string[];
pdiffUrl?: string;
pdiffUrls?: string[];
diffUrl?: string;
diffUrls?: string[];
updateUrl?: string;
updateUrls?: string[];
paused?: 'app' | 'package';
message?: string;
}
@@ -30,7 +28,6 @@ export type EventType =
| 'errorChecking'
| 'checking'
| 'downloading'
| 'downloadSuccess'
| 'errorUpdate'
| 'markSuccess'
| 'downloadingApk'
@@ -83,8 +80,6 @@ export interface PushyOptions {
dismissErrorAfter?: number;
debug?: boolean;
throwError?: boolean;
beforeCheckUpdate?: () => Promise<boolean>;
beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean>;
}
export interface PushyTestPayload {

View File

@@ -31,18 +31,9 @@ const ping =
const canUseGoogle = ping('https://www.google.com');
export function joinUrls(paths: string[], fileName?: string) {
if (fileName) {
return paths.map(path => 'https://' + path + '/' + fileName);
}
}
export const testUrls = async (urls?: string[]) => {
if (!urls?.length) {
if (!urls?.length || (await canUseGoogle)) {
return null;
}
if (await canUseGoogle) {
return urls[0];
}
return Promise.race(urls.map(ping)).catch(() => null);
};