1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

chore: some tweak

This commit is contained in:
sunnylqm 2023-02-20 13:03:12 +08:00
parent 55879198e8
commit d6c268f533
No known key found for this signature in database
7 changed files with 68 additions and 57 deletions

3
.gitignore vendored
View File

@ -42,5 +42,6 @@ node_modules/
npm-debug.log
Example/**/update.json
Example/**/.update
Example/**/.pushy
yarn-error.log
Example/testHotUpdate/.pushy

View File

@ -1,3 +0,0 @@
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoidXNlciIsInVpZCI6OTQ3NywiZXhwIjoxNjc5MjczODYwOTgzLCJpYXQiOjE2NzY2ODE4NjB9.RtoiYnN_2hJ6-aRsx6JkRWil0-RxkdpL7yD7koAky8E"
}

View File

@ -1,21 +1,23 @@
import React from 'react';
/* eslint-disable react-native/no-inline-styles */
/* eslint-disable react/react-in-jsx-scope */
import {useState} from 'react';
import {
ActivityIndicator,
Alert,
Modal,
TextInput,
Button,
NativeModules,
StyleSheet,
SafeAreaView,
Text,
View,
} from 'react-native';
const Pushy = NativeModules.Pushy;
import {PushyModule} from 'react-native-update';
export default function TestConsole({visible}) {
const [text, setText] = React.useState('');
const [running, setRunning] = React.useState(false);
const [text, setText] = useState('');
const [running, setRunning] = useState(false);
return (
<Modal visible={visible}>
<SafeAreaView style={{flex: 1, padding: 10}}>
@ -47,7 +49,7 @@ export default function TestConsole({visible}) {
const methodName = inputs[0];
let params;
if (inputs.length === 1) {
await Pushy[methodName]();
await PushyModule[methodName]();
} else {
if (inputs.length === 2) {
params = inputs[1];
@ -58,7 +60,7 @@ export default function TestConsole({visible}) {
}
console.log({inputs, params});
}
await Pushy[methodName](params);
await PushyModule[methodName](params);
}
Alert.alert('done');
} catch (e) {

View File

@ -3,7 +3,7 @@
#import "RCTPushyManager.h"
// Thanks to this guard, we won't import this header when we build for the old architecture.
#ifdef RCT_NEW_ARCH_ENABLED
#import "RNUpdateSpec.h"
#import "RCTPushySpec.h"
#endif
#import <React/RCTConvert.h>

View File

@ -4,38 +4,46 @@
*/
'use strict';
import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
import {TurboModuleRegistry} from 'react-native';
import type { TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
import { TurboModuleRegistry } from 'react-native';
export interface Spec extends TurboModule {
getConstants: () => {
downloadRootDir: string;
packageVersion: string;
currentVersion: string;
isFirstTime: boolean;
rolledBackVersion: string;
buildTime: string;
blockUpdate: Object;
uuid: string;
isUsingBundleUrl: boolean;
downloadRootDir: string,
packageVersion: string,
currentVersion: string,
isFirstTime: boolean,
rolledBackVersion: string,
buildTime: string,
blockUpdate: Object,
uuid: string,
isUsingBundleUrl: boolean,
};
setLocalHashInfo(hash: string, info:string): void;
getLocalHashInfo(hash: string):Promise<string>;
setLocalHashInfo(hash: string, info: string): void;
getLocalHashInfo(hash: string): Promise<string>;
setUuid(uuid: string): void;
setBlockUpdate(options: {reason: string,until: number}): void;
downloadPatchFromPpk(options: { updateUrl:string,
setBlockUpdate(options: { reason: string, until: number }): void;
downloadPatchFromPpk(options: {
updateUrl: string,
hash: string,
originHash: string}):Promise<void>;
downloadPatchFromPackage(options: { updateUrl:string,
hash: string}): Promise<void>;
downloadFullUpdate(options: { updateUrl:string,
hash: string}): Promise<void>;
reloadUpdate(options: { hash: string}): void;
setNeedUpdate(options: { hash: string}): void;
originHash: string,
}): Promise<void>;
downloadPatchFromPackage(options: {
updateUrl: string,
hash: string,
}): Promise<void>;
downloadFullUpdate(options: {
updateUrl: string,
hash: string,
}): Promise<void>;
reloadUpdate(options: { hash: string }): void;
setNeedUpdate(options: { hash: string }): void;
markSuccess(): void;
downloadAndInstallApk(options: { url: string,
target : string,
hash: string}): Promise<void>;
downloadAndInstallApk(options: {
url: string,
target: string,
hash: string,
}): Promise<void>;
}
export default (TurboModuleRegistry.get<Spec>('Pushy'): ?Spec);

View File

@ -16,14 +16,17 @@ const {
} = require('react-native/Libraries/Core/ReactNativeVersion');
const RNVersion = `${v.major}.${v.minor}.${v.patch}`;
const isTurboModuleEnabled = global.__turboModuleProxy != null;
const Pushy = isTurboModuleEnabled ?
require("./NativeUpdate").default :
NativeModules.Pushy;
if (!Pushy) {
export const PushyModule = isTurboModuleEnabled
? require('./NativeUpdate').default
: NativeModules.Pushy;
if (!PushyModule) {
throw new Error('react-native-update模块无法加载请对照安装文档检查配置。');
}
const PushyConstants = isTurboModuleEnabled ? Pushy.getConstants(): Pushy;
const PushyConstants = isTurboModuleEnabled
? PushyModule.getConstants()
: PushyModule;
export const downloadRootDir = PushyConstants.downloadRootDir;
export const packageVersion = PushyConstants.packageVersion;
@ -43,22 +46,22 @@ if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) {
}
function setLocalHashInfo(hash, info) {
Pushy.setLocalHashInfo(hash, JSON.stringify(info));
PushyModule.setLocalHashInfo(hash, JSON.stringify(info));
}
async function getLocalHashInfo(hash) {
return JSON.parse(await Pushy.getLocalHashInfo(hash));
return JSON.parse(await PushyModule.getLocalHashInfo(hash));
}
export async function getCurrentVersionInfo() {
return currentVersion ? (await getLocalHashInfo(currentVersion)) || {} : {};
}
const eventEmitter = new NativeEventEmitter(Pushy);
const eventEmitter = new NativeEventEmitter(PushyModule);
if (!uuid) {
uuid = require('nanoid/non-secure').nanoid();
Pushy.setUuid(uuid);
PushyModule.setUuid(uuid);
}
function logger(text) {
@ -166,7 +169,7 @@ function checkOperation(op) {
reason: action.reason,
until: Math.round((Date.now() + action.duration) / 1000),
};
Pushy.setBlockUpdate(blockUpdate);
PushyModule.setBlockUpdate(blockUpdate);
}
});
}
@ -212,7 +215,7 @@ export async function downloadUpdate(options, eventListeners) {
if (options.diffUrl) {
logger('downloading diff');
try {
await Pushy.downloadPatchFromPpk({
await PushyModule.downloadPatchFromPpk({
updateUrl: options.diffUrl,
hash: options.hash,
originHash: currentVersion,
@ -225,7 +228,7 @@ export async function downloadUpdate(options, eventListeners) {
if (!succeeded && options.pdiffUrl) {
logger('downloading pdiff');
try {
await Pushy.downloadPatchFromPackage({
await PushyModule.downloadPatchFromPackage({
updateUrl: options.pdiffUrl,
hash: options.hash,
});
@ -237,7 +240,7 @@ export async function downloadUpdate(options, eventListeners) {
if (!succeeded && options.updateUrl) {
logger('downloading full patch');
try {
await Pushy.downloadFullUpdate({
await PushyModule.downloadFullUpdate({
updateUrl: options.updateUrl,
hash: options.hash,
});
@ -276,7 +279,7 @@ export function switchVersion(hash) {
assertRelease();
if (assertHash(hash)) {
logger('switchVersion: ' + hash);
Pushy.reloadUpdate({ hash });
PushyModule.reloadUpdate({ hash });
}
}
@ -284,7 +287,7 @@ export function switchVersionLater(hash) {
assertRelease();
if (assertHash(hash)) {
logger('switchVersionLater: ' + hash);
Pushy.setNeedUpdate({ hash });
PushyModule.setNeedUpdate({ hash });
}
}
@ -296,7 +299,7 @@ export function markSuccess() {
return;
}
marked = true;
Pushy.markSuccess();
PushyModule.markSuccess();
report(currentVersion, 'success');
}
@ -326,7 +329,7 @@ export async function downloadAndInstallApk({ url, onDownloadProgress }) {
},
);
}
await Pushy.downloadAndInstallApk({
await PushyModule.downloadAndInstallApk({
url,
target: 'update.apk',
hash,

View File

@ -34,7 +34,7 @@
"codegenConfig": {
"libraries": [
{
"name": "RNUpdateSpec",
"name": "RCTPushySpec",
"type": "modules",
"jsSrcsDir": "lib"
}