mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 13:01:38 +08:00
Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d000c40e0f | ||
![]() |
5659c79726 | ||
![]() |
b20d987473 | ||
![]() |
14c9c0b1f5 | ||
![]() |
10178e1e64 | ||
![]() |
6d980a4c04 | ||
![]() |
084fbf35ee | ||
![]() |
d666e8c0f3 | ||
![]() |
5e89fb4a25 | ||
![]() |
ab01b6010a | ||
![]() |
92bc830d98 |
@@ -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 = false
|
||||
def enableSeparateBuildPerCPUArchitecture = true
|
||||
|
||||
/**
|
||||
* Run Proguard to shrink the Java bytecode in release builds.
|
||||
|
@@ -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.2",
|
||||
"react-native-update": "^10.11.3",
|
||||
"react-native-vector-icons": "^10.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable react/no-unstable-nested-components */
|
||||
/* eslint-disable react-native/no-inline-styles */
|
||||
import React, {useState} from 'react';
|
||||
import React, {useRef, useState} from 'react';
|
||||
import {
|
||||
StyleSheet,
|
||||
Platform,
|
||||
@@ -47,6 +47,7 @@ function App() {
|
||||
const snackbarVisible =
|
||||
!useDefaultAlert && showUpdateSnackbar && updateInfo?.update;
|
||||
const [showCamera, setShowCamera] = useState(false);
|
||||
const lastParsedCode = useRef('');
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
@@ -73,9 +74,16 @@ function App() {
|
||||
style={{minHeight: 320}}
|
||||
scanBarcode={true}
|
||||
onReadCode={({nativeEvent: {codeStringValue}}) => {
|
||||
console.log(codeStringValue);
|
||||
parseTestQrCode(codeStringValue);
|
||||
// 防止重复扫码
|
||||
if (lastParsedCode.current === codeStringValue) {
|
||||
return;
|
||||
}
|
||||
lastParsedCode.current = codeStringValue;
|
||||
setTimeout(() => {
|
||||
lastParsedCode.current = '';
|
||||
}, 1000);
|
||||
setShowCamera(false);
|
||||
parseTestQrCode(codeStringValue);
|
||||
}} // 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
|
||||
|
@@ -6236,10 +6236,10 @@ 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.2:
|
||||
version "10.11.2"
|
||||
resolved "https://registry.yarnpkg.com/react-native-update/-/react-native-update-10.11.2.tgz#d80f0c0f3705713d302b6c36d3fd8ff2f0fba340"
|
||||
integrity sha512-5WlJ3TRodHSftqDxi3OCAnI/OIq70Kh8gr1xa9OqEG2+UwD1SA+gqHRHunKED4J7N7OUtmxIDX+hvdf8xJEgRA==
|
||||
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==
|
||||
dependencies:
|
||||
nanoid "^3.3.3"
|
||||
react-native-url-polyfill "^2.0.0"
|
||||
|
@@ -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,8 +329,7 @@ RCT_EXPORT_METHOD(reloadUpdate:(NSDictionary *)options
|
||||
}
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(markSuccess:
|
||||
resolver:(RCTPromiseResolveBlock)resolve
|
||||
RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
|
||||
rejecter:(RCTPromiseRejectBlock)reject)
|
||||
{
|
||||
|
||||
@@ -347,7 +346,7 @@ RCT_EXPORT_METHOD(markSuccess:
|
||||
[pushyInfo removeObjectForKey:[keyHashInfo stringByAppendingString:lastVersion]];
|
||||
}
|
||||
[defaults setObject:pushyInfo forKey:keyPushyInfo];
|
||||
[defaults synchronize];
|
||||
|
||||
|
||||
// clear other package dir
|
||||
[self clearInvalidFiles];
|
||||
@@ -610,7 +609,7 @@ RCT_EXPORT_METHOD(markSuccess:
|
||||
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
||||
(const facebook::react::ObjCTurboModule::InitParams &)params
|
||||
{
|
||||
return std::make_shared<facebook::react::NativeUpdateSpecJSI>(params);
|
||||
return std::make_shared<facebook::react::NativePushySpecJSI>(params);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "10.11.3",
|
||||
"version": "10.12.0",
|
||||
"description": "react-native hot update",
|
||||
"main": "src/index",
|
||||
"scripts": {
|
||||
|
@@ -126,7 +126,7 @@ export class Pushy {
|
||||
PushyModule.markSuccess();
|
||||
this.report({ type: 'markSuccess' });
|
||||
};
|
||||
switchVersion = (hash: string) => {
|
||||
switchVersion = async (hash: string) => {
|
||||
if (__DEV__) {
|
||||
console.warn(
|
||||
'您调用了switchVersion方法,但是当前是开发环境,不会进行任何操作。',
|
||||
@@ -136,11 +136,11 @@ export class Pushy {
|
||||
if (this.assertHash(hash) && !this.applyingUpdate) {
|
||||
log('switchVersion: ' + hash);
|
||||
this.applyingUpdate = true;
|
||||
PushyModule.reloadUpdate({ hash });
|
||||
return PushyModule.reloadUpdate({ hash });
|
||||
}
|
||||
};
|
||||
|
||||
switchVersionLater = (hash: string) => {
|
||||
switchVersionLater = async (hash: string) => {
|
||||
if (__DEV__) {
|
||||
console.warn(
|
||||
'您调用了switchVersionLater方法,但是当前是开发环境,不会进行任何操作。',
|
||||
@@ -149,7 +149,7 @@ export class Pushy {
|
||||
}
|
||||
if (this.assertHash(hash)) {
|
||||
log('switchVersionLater: ' + hash);
|
||||
PushyModule.setNeedUpdate({ hash });
|
||||
return PushyModule.setNeedUpdate({ hash });
|
||||
}
|
||||
};
|
||||
checkUpdate = async (extra?: Record<string, any>) => {
|
||||
@@ -163,6 +163,13 @@ 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 &&
|
||||
@@ -172,7 +179,6 @@ export class Pushy {
|
||||
return await this.lastRespJson;
|
||||
}
|
||||
this.lastChecking = now;
|
||||
this.report({ type: 'checking' });
|
||||
const fetchBody = {
|
||||
packageVersion,
|
||||
hash: currentVersion,
|
||||
@@ -183,16 +189,21 @@ 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: JSON.stringify(fetchBody),
|
||||
body,
|
||||
};
|
||||
let resp;
|
||||
try {
|
||||
this.report({
|
||||
type: 'checking',
|
||||
message: this.options.appKey + ': ' + body,
|
||||
});
|
||||
resp = await fetch(this.getCheckUrl(), fetchPayload);
|
||||
} catch (e: any) {
|
||||
this.report({
|
||||
@@ -221,6 +232,8 @@ export class Pushy {
|
||||
|
||||
const result: CheckResult = await this.lastRespJson;
|
||||
|
||||
log('checking result:', result);
|
||||
|
||||
if (resp.status !== 200) {
|
||||
this.report({
|
||||
type: 'errorChecking',
|
||||
@@ -269,6 +282,13 @@ export class Pushy {
|
||||
description,
|
||||
metaInfo,
|
||||
} = info;
|
||||
if (
|
||||
this.options.beforeDownloadUpdate &&
|
||||
(await this.options.beforeDownloadUpdate(info)) === false
|
||||
) {
|
||||
log('beforeDownloadUpdate 返回 false, 忽略下载');
|
||||
return;
|
||||
}
|
||||
if (!info.update || !hash) {
|
||||
return;
|
||||
}
|
||||
|
@@ -7,8 +7,8 @@ const asyncNoop = () => Promise.resolve();
|
||||
|
||||
export const defaultContext = {
|
||||
checkUpdate: asyncNoop,
|
||||
switchVersion: noop,
|
||||
switchVersionLater: noop,
|
||||
switchVersion: asyncNoop,
|
||||
switchVersionLater: asyncNoop,
|
||||
markSuccess: noop,
|
||||
dismissError: noop,
|
||||
downloadUpdate: asyncNoop,
|
||||
@@ -21,8 +21,8 @@ export const defaultContext = {
|
||||
|
||||
export const PushyContext = createContext<{
|
||||
checkUpdate: () => Promise<void>;
|
||||
switchVersion: () => void;
|
||||
switchVersionLater: () => void;
|
||||
switchVersion: () => Promise<void>;
|
||||
switchVersionLater: () => Promise<void>;
|
||||
markSuccess: () => void;
|
||||
dismissError: () => void;
|
||||
downloadUpdate: () => Promise<void>;
|
||||
|
@@ -73,18 +73,18 @@ export const PushyProvider = ({
|
||||
);
|
||||
|
||||
const switchVersion = useCallback(
|
||||
(info: CheckResult | undefined = updateInfoRef.current) => {
|
||||
async (info: CheckResult | undefined = updateInfoRef.current) => {
|
||||
if (info && info.hash) {
|
||||
client.switchVersion(info.hash);
|
||||
return client.switchVersion(info.hash);
|
||||
}
|
||||
},
|
||||
[client],
|
||||
);
|
||||
|
||||
const switchVersionLater = useCallback(
|
||||
(info: CheckResult | undefined = updateInfoRef.current) => {
|
||||
async (info: CheckResult | undefined = updateInfoRef.current) => {
|
||||
if (info && info.hash) {
|
||||
client.switchVersionLater(info.hash);
|
||||
return client.switchVersionLater(info.hash);
|
||||
}
|
||||
},
|
||||
[client],
|
||||
@@ -147,7 +147,7 @@ export const PushyProvider = ({
|
||||
);
|
||||
|
||||
const checkUpdate = useCallback(
|
||||
async (extra?: Record<string, any>) => {
|
||||
async ({ extra }: { extra?: Record<string, any> } | undefined = {}) => {
|
||||
const now = Date.now();
|
||||
if (lastChecking.current && now - lastChecking.current < 1000) {
|
||||
return;
|
||||
@@ -272,7 +272,7 @@ export const PushyProvider = ({
|
||||
Alert.alert(type, JSON.stringify(data));
|
||||
};
|
||||
if (payload.type === '__rnPushyVersionHash') {
|
||||
checkUpdate({ toHash: payload.data }).then(() => {
|
||||
checkUpdate({ extra: { toHash: payload.data } }).then(() => {
|
||||
if (updateInfoRef.current && updateInfoRef.current.upToDate) {
|
||||
Alert.alert(
|
||||
'提示',
|
||||
@@ -290,10 +290,9 @@ export const PushyProvider = ({
|
||||
);
|
||||
|
||||
const parseTestQrCode = useCallback(
|
||||
(code: string) => {
|
||||
let payload: PushyTestPayload;
|
||||
(code: string | PushyTestPayload) => {
|
||||
try {
|
||||
payload = JSON.parse(code);
|
||||
const payload = typeof code === 'string' ? JSON.parse(code) : code;
|
||||
return parseTestPayload(payload);
|
||||
} catch {
|
||||
return false;
|
||||
|
@@ -81,6 +81,8 @@ export interface PushyOptions {
|
||||
dismissErrorAfter?: number;
|
||||
debug?: boolean;
|
||||
throwError?: boolean;
|
||||
beforeCheckUpdate?: () => Promise<boolean>;
|
||||
beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean>;
|
||||
}
|
||||
|
||||
export interface PushyTestPayload {
|
||||
|
Reference in New Issue
Block a user