mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-10-07 19:05:13 +08:00
chore: some tweak
This commit is contained in:
37
lib/main.js
37
lib/main.js
@@ -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,
|
||||
|
Reference in New Issue
Block a user