mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-11-22 23:46:10 +08:00
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f941b93cb3 | ||
|
|
bea0e077a0 | ||
|
|
dc9b5d722a | ||
|
|
e151c9c618 | ||
|
|
2a79061b89 | ||
|
|
e04ce54de6 | ||
|
|
38229a8bca | ||
|
|
6661e307cd | ||
|
|
027bd16af2 | ||
|
|
4daaadce70 | ||
|
|
43ed2f50fe | ||
|
|
e46d01714a | ||
|
|
366b2a6618 | ||
|
|
34e053ae48 | ||
|
|
d55ef1d8c8 | ||
|
|
de3e7d9e4c | ||
|
|
e0201d3882 | ||
|
|
ba5b35813d | ||
|
|
3134f36739 | ||
|
|
d4f4740053 | ||
|
|
a248f18035 | ||
|
|
268f39f43b | ||
|
|
6e4f432e26 | ||
|
|
1b4c03924a | ||
|
|
d458371f54 | ||
|
|
84381e5ed7 | ||
|
|
8970fd406d | ||
|
|
34d6fef493 | ||
|
|
84b71e33a8 | ||
|
|
6cd99dece0 | ||
|
|
d726f3602b | ||
|
|
da21c99bcc | ||
|
|
1f8748375c | ||
|
|
fa731cd583 | ||
|
|
d077dcb6d3 | ||
|
|
59b60fdc6d | ||
|
|
c768705221 | ||
|
|
57206dd2f1 | ||
|
|
4e27d906c3 | ||
|
|
c24f469475 |
8
.gitignore
vendored
8
.gitignore
vendored
@@ -52,3 +52,11 @@ Example/testHotUpdate/harmony
|
||||
Example/testHotUpdate/android/app/.cxx
|
||||
Example/harmony_use_pushy/libs
|
||||
**/mcp.json
|
||||
|
||||
|
||||
harmony/package
|
||||
**/oh_modules
|
||||
harmony/pushy/.preview
|
||||
Example/harmony_use_pushy/harmony/entry/src/main/resources/rawfile/meta.json
|
||||
**/.hvigor
|
||||
Example/harmony_use_pushy/harmony/entry/src/main/cpp/generated
|
||||
|
||||
6
.gitmodules
vendored
6
.gitmodules
vendored
@@ -4,9 +4,3 @@
|
||||
[submodule "android/jni/HDiffPatch"]
|
||||
path = android/jni/HDiffPatch
|
||||
url = https://github.com/sisong/HDiffPatch.git
|
||||
[submodule "harmony/src/main/cpp/HDiffPatch"]
|
||||
path = harmony/src/main/cpp/HDiffPatch
|
||||
url = https://github.com/sisong/HDiffPatch.git
|
||||
[submodule "harmony/src/main/cpp/lzma"]
|
||||
path = harmony/src/main/cpp/lzma
|
||||
url = https://github.com/sisong/lzma.git
|
||||
|
||||
@@ -20,7 +20,8 @@
|
||||
"adaptiveIcon": {
|
||||
"foregroundImage": "./assets/adaptive-icon.png",
|
||||
"backgroundColor": "#ffffff"
|
||||
}
|
||||
},
|
||||
"package": "com.anonymous.expoUsePushy"
|
||||
},
|
||||
"web": {
|
||||
"favicon": "./assets/favicon.png"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1 @@
|
||||
import { registerRootComponent } from 'expo';
|
||||
|
||||
import App from './App';
|
||||
|
||||
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
|
||||
// It also ensures that whether you load the app in Expo Go or in a native build,
|
||||
// the environment is set up appropriately
|
||||
registerRootComponent(App);
|
||||
import 'expo-router/entry';
|
||||
|
||||
@@ -1,27 +1,50 @@
|
||||
{
|
||||
"name": "expousepushy",
|
||||
"version": "1.0.0",
|
||||
"main": "index.js",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"start": "expo start",
|
||||
"reset-project": "node ./scripts/reset-project.js",
|
||||
"android": "expo run:android",
|
||||
"ios": "expo run:ios",
|
||||
"web": "expo start --web"
|
||||
"web": "expo start --web",
|
||||
"lint": "expo lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@expo/metro-runtime": "~4.0.1",
|
||||
"expo": "~52.0.46",
|
||||
"expo-status-bar": "~2.0.1",
|
||||
"react": "18.3.1",
|
||||
"react-dom": "18.3.1",
|
||||
"react-native": "0.76.9",
|
||||
"react-native-update": "^10.30.3",
|
||||
"react-native-web": "~0.19.13"
|
||||
"@expo/vector-icons": "^14.1.0",
|
||||
"@react-navigation/bottom-tabs": "^7.3.10",
|
||||
"@react-navigation/elements": "^2.3.8",
|
||||
"@react-navigation/native": "^7.1.6",
|
||||
"expo": "~53.0.22",
|
||||
"expo-blur": "~14.1.5",
|
||||
"expo-constants": "~17.1.7",
|
||||
"expo-font": "~13.3.2",
|
||||
"expo-haptics": "~14.1.4",
|
||||
"expo-image": "~2.4.0",
|
||||
"expo-linking": "~7.1.7",
|
||||
"expo-router": "~5.1.5",
|
||||
"expo-splash-screen": "~0.30.10",
|
||||
"expo-status-bar": "~2.2.3",
|
||||
"expo-symbols": "~0.4.5",
|
||||
"expo-system-ui": "~5.0.11",
|
||||
"expo-web-browser": "~14.2.0",
|
||||
"react": "19.0.0",
|
||||
"react-dom": "19.0.0",
|
||||
"react-native": "0.79.6",
|
||||
"react-native-gesture-handler": "~2.24.0",
|
||||
"react-native-reanimated": "~3.17.4",
|
||||
"react-native-safe-area-context": "5.4.0",
|
||||
"react-native-screens": "~4.11.1",
|
||||
"react-native-update": "^10.34.4",
|
||||
"react-native-web": "~0.20.0",
|
||||
"react-native-webview": "13.13.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.25.2",
|
||||
"@types/react": "~18.3.12",
|
||||
"typescript": "^5.3.3"
|
||||
"@types/react": "~19.0.10",
|
||||
"typescript": "~5.8.3",
|
||||
"eslint": "^9.25.0",
|
||||
"eslint-config-expo": "~9.2.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
/* eslint-disable react/no-unstable-nested-components */
|
||||
/* eslint-disable react-native/no-inline-styles */
|
||||
import React, {useState} from 'react';
|
||||
import {StyleSheet, Text, View, TouchableOpacity, Image} from 'react-native';
|
||||
@@ -6,7 +5,7 @@ import {StyleSheet, Text, View, TouchableOpacity, Image} from 'react-native';
|
||||
import TestConsole from './TestConsole';
|
||||
|
||||
import _updateConfig from './update.json';
|
||||
import {PushyProvider, Pushy, usePushy} from 'react-native-update';
|
||||
import {UpdateProvider, Pushy, useUpdate} from 'react-native-update';
|
||||
const {appKey} = _updateConfig.harmony;
|
||||
|
||||
function App() {
|
||||
@@ -20,7 +19,7 @@ function App() {
|
||||
packageVersion,
|
||||
currentHash,
|
||||
progress: {received, total} = {},
|
||||
} = usePushy();
|
||||
} = useUpdate();
|
||||
const [useDefaultAlert, setUseDefaultAlert] = useState(false);
|
||||
const [showTestConsole, setShowTestConsole] = useState(false);
|
||||
const [showUpdateBanner, setShowUpdateBanner] = useState(false);
|
||||
@@ -41,6 +40,7 @@ function App() {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.welcome}>欢迎使用Pushy热更新服务</Text>
|
||||
{/* <Image source={require('./gmail.png')} style={styles.image} /> */}
|
||||
{/* <Text style={styles.welcome}>😁hdiffFromAPP更新成功!!!</Text> */}
|
||||
{/* <Text style={styles.welcome}>😁hdiffFromPPk更新成功!!!</Text> */}
|
||||
<View style={{flexDirection: 'row'}}>
|
||||
@@ -166,7 +166,7 @@ function App() {
|
||||
style={{marginRight: 20}}>
|
||||
<Text style={{color: '#2196F3'}}>下次再说</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity onPress={switchVersion}>
|
||||
<TouchableOpacity onPress={() => switchVersion()}>
|
||||
<Text style={{color: '#2196F3'}}>立即重启</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
@@ -204,18 +204,22 @@ const styles = StyleSheet.create({
|
||||
color: '#333333',
|
||||
marginBottom: 5,
|
||||
},
|
||||
image: {},
|
||||
image: {
|
||||
width: 109,
|
||||
height: 40,
|
||||
},
|
||||
});
|
||||
|
||||
const pushyClient = new Pushy({
|
||||
appKey,
|
||||
debug: true,
|
||||
updateStrategy: null,
|
||||
});
|
||||
|
||||
export default function Root() {
|
||||
return (
|
||||
<PushyProvider client={pushyClient}>
|
||||
<UpdateProvider client={pushyClient}>
|
||||
<App />
|
||||
</PushyProvider>
|
||||
</UpdateProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
|
||||
ruby ">= 2.6.10"
|
||||
|
||||
gem 'cocoapods', '~> 1.12'
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,41 +1,44 @@
|
||||
{
|
||||
"app": {
|
||||
"signingConfigs": [],
|
||||
"products": [
|
||||
app: {
|
||||
signingConfigs: [],
|
||||
products: [
|
||||
{
|
||||
"name": "default",
|
||||
"signingConfig": "default",
|
||||
"compatibleSdkVersion": "5.0.0(12)",
|
||||
"runtimeOS": "HarmonyOS",
|
||||
"buildOption": {
|
||||
"strictMode": {
|
||||
"caseSensitiveCheck": true,
|
||||
"useNormalizedOHMUrl": true
|
||||
}
|
||||
}
|
||||
}
|
||||
name: 'default',
|
||||
signingConfig: 'default',
|
||||
compatibleSdkVersion: '5.0.0(12)',
|
||||
runtimeOS: 'HarmonyOS',
|
||||
buildOption: {
|
||||
strictMode: {
|
||||
caseSensitiveCheck: true,
|
||||
useNormalizedOHMUrl: true
|
||||
},
|
||||
"nativeCompiler": "BiSheng"
|
||||
},
|
||||
},
|
||||
],
|
||||
"buildModeSet": [
|
||||
buildModeSet: [
|
||||
{
|
||||
"name": "debug",
|
||||
name: 'debug',
|
||||
},
|
||||
{
|
||||
"name": "release"
|
||||
}
|
||||
]
|
||||
name: 'release',
|
||||
},
|
||||
],
|
||||
},
|
||||
"modules": [
|
||||
modules: [
|
||||
{
|
||||
"name": "entry",
|
||||
"srcPath": "./entry",
|
||||
"targets": [
|
||||
name: 'entry',
|
||||
srcPath: './entry',
|
||||
targets: [
|
||||
{
|
||||
"name": "default",
|
||||
"applyToProducts": [
|
||||
"default"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
name: 'default',
|
||||
applyToProducts: ['default'],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'pushy',
|
||||
srcPath: '../node_modules/react-native-update/harmony/pushy',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -1,44 +1,9 @@
|
||||
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export function generatePushyBuildTime(str?: string) {
|
||||
return {
|
||||
pluginId: 'PushyBuildTimePlugin',
|
||||
apply(pluginContext) {
|
||||
pluginContext.registerTask({
|
||||
name: 'pushy_build_time',
|
||||
run: (taskContext) => {
|
||||
const metaFilePath = path.resolve(__dirname, 'src/main/resources/rawfile/meta.json');
|
||||
const dirPath = path.dirname(metaFilePath);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
const moduleJsonPath = path.resolve(__dirname, '../AppScope/app.json5');
|
||||
let versionName = '';
|
||||
if (fs.existsSync(moduleJsonPath)) {
|
||||
const moduleContent = fs.readFileSync(moduleJsonPath, 'utf-8');
|
||||
const versionMatch = moduleContent.match(/"versionName":\s*"([^"]+)"/);
|
||||
if (versionMatch && versionMatch[1]) {
|
||||
versionName = versionMatch[1];
|
||||
}
|
||||
}
|
||||
const buildTime = new Date().toISOString();
|
||||
const metaContent = {
|
||||
pushy_build_time: buildTime,
|
||||
versionName: versionName
|
||||
};
|
||||
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4));
|
||||
console.log(`Build time written to ${metaFilePath}`);
|
||||
},
|
||||
dependencies: [],
|
||||
postDependencies: ['default@BuildJS']
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
import {hapTasks} from '@ohos/hvigor-ohos-plugin';
|
||||
import {reactNativeUpdatePlugin} from 'pushy/hvigor-plugin';
|
||||
|
||||
export default {
|
||||
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[generatePushyBuildTime()] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
||||
system: hapTasks /* Built-in plugin of Hvigor. It cannot be modified. */,
|
||||
plugins: [
|
||||
reactNativeUpdatePlugin(),
|
||||
] /* Custom plugin to extend the functionality of Hvigor. */,
|
||||
};
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
{
|
||||
"meta": {
|
||||
"stableOrder": true
|
||||
"stableOrder": true,
|
||||
"enableUnifiedLockfile": false
|
||||
},
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38",
|
||||
"pushy@../../node_modules/react-native-update/harmony": "pushy@../../node_modules/react-native-update/harmony"
|
||||
"@rnoh/react-native-openharmony@0.72.96": "@rnoh/react-native-openharmony@0.72.96",
|
||||
"pushy@../../node_modules/react-native-update/harmony/pushy": "pushy@../../node_modules/react-native-update/harmony/pushy"
|
||||
},
|
||||
"packages": {
|
||||
"@rnoh/react-native-openharmony@0.72.38": {
|
||||
"name": "@rnoh/react-native-openharmony",
|
||||
"version": "0.72.38",
|
||||
"integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
|
||||
"@rnoh/react-native-openharmony@0.72.96": {
|
||||
"name": "",
|
||||
"version": "0.72.96",
|
||||
"integrity": "sha512-gBbm8LLyqi5UE7qHWdZYeQnjyncfEpCczKZUP/9M2U1Z7exR0Kya8PMKMwr1ta5ujy7w/hZVC2LomEV4QvBeqA==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.96.har",
|
||||
"registryType": "ohpm"
|
||||
},
|
||||
"pushy@../../node_modules/react-native-update/harmony": {
|
||||
"pushy@../../node_modules/react-native-update/harmony/pushy": {
|
||||
"name": "pushy",
|
||||
"version": "3.1.0-0.0.7",
|
||||
"resolved": "../../node_modules/react-native-update/harmony",
|
||||
"resolved": "",
|
||||
"registryType": "local",
|
||||
"dependencies": {
|
||||
"@rnoh/react-native-openharmony": "^0.72.38"
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
{
|
||||
"name": "entry",
|
||||
"version": "1.0.0",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"author": "",
|
||||
"license": "",
|
||||
"dependencies": {
|
||||
"@rnoh/react-native-openharmony": "0.72.38",
|
||||
"pushy": "file:../../node_modules/react-native-update/harmony/pushy.har",
|
||||
}
|
||||
name: 'entry',
|
||||
version: '1.0.0',
|
||||
description: 'Please describe the basic information.',
|
||||
main: '',
|
||||
author: '',
|
||||
license: '',
|
||||
dependencies: {
|
||||
'@rnoh/react-native-openharmony': '0.72.96',
|
||||
pushy: 'file:../../node_modules/react-native-update/harmony/pushy',
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/**
|
||||
* This code was generated by "react-native codegen-harmony"
|
||||
*
|
||||
* Do not edit this file as changes may cause incorrect behavior and will be
|
||||
* lost once the code is regenerated.
|
||||
*
|
||||
* @generatorVersion: 1
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RNOH/Package.h"
|
||||
#include "RNOH/ArkTSTurboModule.h"
|
||||
|
||||
namespace rnoh {
|
||||
|
||||
class RNOHGeneratedPackageTurboModuleFactoryDelegate : public TurboModuleFactoryDelegate {
|
||||
public:
|
||||
SharedTurboModule createTurboModule(Context ctx, const std::string &name) const override {
|
||||
return nullptr;
|
||||
};
|
||||
};
|
||||
|
||||
class GeneratedEventEmitRequestHandler : public EventEmitRequestHandler {
|
||||
public:
|
||||
void handleEvent(Context const &ctx) override {
|
||||
auto eventEmitter = ctx.shadowViewRegistry->getEventEmitter<facebook::react::EventEmitter>(ctx.tag);
|
||||
if (eventEmitter == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> supportedEventNames = {
|
||||
};
|
||||
if (std::find(supportedEventNames.begin(), supportedEventNames.end(), ctx.eventName) != supportedEventNames.end()) {
|
||||
eventEmitter->dispatchEvent(ctx.eventName, ArkJS(ctx.env).getDynamic(ctx.payload));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class RNOHGeneratedPackage : public Package {
|
||||
public:
|
||||
RNOHGeneratedPackage(Package::Context ctx) : Package(ctx){};
|
||||
|
||||
std::unique_ptr<TurboModuleFactoryDelegate> createTurboModuleFactoryDelegate() override {
|
||||
return std::make_unique<RNOHGeneratedPackageTurboModuleFactoryDelegate>();
|
||||
}
|
||||
|
||||
std::vector<facebook::react::ComponentDescriptorProvider> createComponentDescriptorProviders() override {
|
||||
return {
|
||||
};
|
||||
}
|
||||
|
||||
ComponentJSIBinderByString createComponentJSIBinderByName() override {
|
||||
return {
|
||||
};
|
||||
};
|
||||
|
||||
EventEmitRequestHandlers createEventEmitRequestHandlers() override {
|
||||
return {
|
||||
std::make_shared<GeneratedEventEmitRequestHandler>(),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace rnoh
|
||||
@@ -54,7 +54,6 @@ struct Index {
|
||||
enableCAPIArchitecture: true,
|
||||
arkTsComponentNames: arkTsComponentNames,
|
||||
},
|
||||
initialProps: { "foo": "bar" } as Record<string, string>,
|
||||
appKey: "harmony_use_pushy",
|
||||
wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder,
|
||||
onSetUp: (rnInstance) => {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"pushy_build_time": "2025-04-30T02:46:33.340Z",
|
||||
"versionName": "1.0.0"
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"modelVersion": "5.0.0",
|
||||
"dependencies": {
|
||||
pushy: 'file:../../node_modules/react-native-update/harmony/pushy'
|
||||
},
|
||||
"execution": {
|
||||
// "analyze": "normal", /* Define the build analyze mode. Value: [ "normal" | "advanced" | false ]. Default: "normal" */
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { appTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
import {appTasks} from '@ohos/hvigor-ohos-plugin';
|
||||
|
||||
export default {
|
||||
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
||||
system: appTasks /* Built-in plugin of Hvigor. It cannot be modified. */,
|
||||
plugins: [] /* Custom plugin to extend the functionality of Hvigor. */,
|
||||
};
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
{
|
||||
"meta": {
|
||||
"stableOrder": true
|
||||
"stableOrder": true,
|
||||
"enableUnifiedLockfile": false
|
||||
},
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@ohos/hamock@1.0.0": "@ohos/hamock@1.0.0",
|
||||
"@ohos/hypium@1.0.19": "@ohos/hypium@1.0.19"
|
||||
},
|
||||
"packages": {
|
||||
"@ohos/hamock@1.0.0": {
|
||||
"name": "@ohos/hamock",
|
||||
"version": "1.0.0",
|
||||
"integrity": "sha512-K6lDPYc6VkKe6ZBNQa9aoG+ZZMiwqfcR/7yAVFSUGIuOAhPvCJAo9+t1fZnpe0dBRBPxj2bxPPbKh69VuyAtDg==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hamock/-/hamock-1.0.0.har",
|
||||
"registryType": "ohpm"
|
||||
},
|
||||
"@ohos/hypium@1.0.19": {
|
||||
"name": "@ohos/hypium",
|
||||
"name": "",
|
||||
"version": "1.0.19",
|
||||
"integrity": "sha512-cEjDgLFCm3cWZDeRXk7agBUkPqjWxUo6AQeiu0gEkb3J8ESqlduQLSIXeo3cCsm8U/asL7iKjF85ZyOuufAGSQ==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/hypium/-/hypium-1.0.19.har",
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
{
|
||||
"modelVersion": "5.0.0",
|
||||
"description": "Please describe the basic information.",
|
||||
"dependencies": {
|
||||
modelVersion: '5.0.0',
|
||||
description: 'Please describe the basic information.',
|
||||
dependencies: {},
|
||||
devDependencies: {
|
||||
'@ohos/hypium': '1.0.19'
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ohos/hypium": "1.0.19",
|
||||
"@ohos/hamock": "1.0.0"
|
||||
arkTs: {
|
||||
compilerOptions: {
|
||||
noImplicitAny: false,
|
||||
suppressImplicitAnyIndexErrors: true,
|
||||
strict: false,
|
||||
},
|
||||
},
|
||||
"arkTs": {
|
||||
"compilerOptions": {
|
||||
"noImplicitAny": false,
|
||||
"suppressImplicitAnyIndexErrors": true,
|
||||
"strict": false
|
||||
}
|
||||
overrides: {
|
||||
'@rnoh/react-native-openharmony': '0.72.96',
|
||||
},
|
||||
"overrides": {
|
||||
"@rnoh/react-native-openharmony": "0.72.38"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"lint": "eslint .",
|
||||
"start": "npm run codegen && hdc rport tcp:8081 tcp:8081 && react-native start",
|
||||
"codegen": "react-native codegen-harmony --rnoh-module-path ./harmony/react_native_openharmony",
|
||||
"build": "pushy bundle --platform harmony",
|
||||
"build": "pushy bundle --platform harmony --no-interactive",
|
||||
"test": "jest",
|
||||
"hdiffFromPPK": "pushy hdiffFromPPK .pushy/output/harmony.1735052610653.ppk .pushy/output/harmony.1735052678646.ppk .pushy/output/hdiff.ppk-patch",
|
||||
"hdiffFromApp": "pushy hdiffFromApp .pushy/output/version-1.0.0.app .pushy/output/harmony.1735052610653.ppk .pushy/output/hdiff.app-patch",
|
||||
@@ -18,7 +18,7 @@
|
||||
"@react-native-oh/react-native-harmony": "^0.72.59",
|
||||
"react": "18.2.0",
|
||||
"react-native": "0.72.5",
|
||||
"react-native-update": "latest"
|
||||
"react-native-update": "^10.35.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.0",
|
||||
@@ -40,4 +40,4 @@
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
{
|
||||
"lockfileVersion": 1,
|
||||
"configVersion": 0,
|
||||
"workspaces": {
|
||||
"": {
|
||||
"name": "testHotUpdate",
|
||||
@@ -12,7 +13,7 @@
|
||||
"react-native-paper": "^5.14.5",
|
||||
"react-native-safe-area-context": "^5.6.1",
|
||||
"react-native-svg": "^15.13.0",
|
||||
"react-native-update": "^10.31.2",
|
||||
"react-native-update": "^10.35.6",
|
||||
"react-native-vector-icons": "^10.3.0",
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -1430,7 +1431,7 @@
|
||||
|
||||
"react-native-svg": ["react-native-svg@15.13.0", "", { "dependencies": { "css-select": "^5.1.0", "css-tree": "^1.1.3", "warn-once": "0.1.1" }, "peerDependencies": { "react": "*", "react-native": "*" } }, "sha512-/YPK+PAAXg4T0x2d2vYPvqqAhOYid2bRKxUVT7STIyd1p2JxWmsGQkfZxXCkEFN7TwLfIyVlT5RimT91Pj/qXw=="],
|
||||
|
||||
"react-native-update": ["react-native-update@10.31.2", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-doKTDyU/+6eN1jDswSh1HxnM9/XuxYFM65dLadsYVR+JvdLJ0PtbceSauthv4HYI3QXoeGaStkrRCaQAVKvp+w=="],
|
||||
"react-native-update": ["react-native-update@10.35.6", "", { "dependencies": { "nanoid": "^3.3.3", "react-native-url-polyfill": "^2.0.0" }, "peerDependencies": { "react": ">=16.8.0", "react-native": ">=0.59.0" } }, "sha512-2k16I1QdI4wVbepaXjf+Ej9vSpnL7hpzTknitK0s4dI+hVah+cKVntnIexW4DdIpyTk7abCLVJH4MUFGjlaUSQ=="],
|
||||
|
||||
"react-native-url-polyfill": ["react-native-url-polyfill@2.0.0", "", { "dependencies": { "whatwg-url-without-unicode": "8.0.0-3" }, "peerDependencies": { "react-native": "*" } }, "sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA=="],
|
||||
|
||||
|
||||
@@ -403,6 +403,8 @@
|
||||
"-DFOLLY_NO_CONFIG",
|
||||
"-DFOLLY_MOBILE=1",
|
||||
"-DFOLLY_USE_LIBCPP=1",
|
||||
"-DFOLLY_CFG_NO_COROUTINES=1",
|
||||
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
|
||||
);
|
||||
OTHER_LDFLAGS = "$(inherited)";
|
||||
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
||||
@@ -475,6 +477,8 @@
|
||||
"-DFOLLY_NO_CONFIG",
|
||||
"-DFOLLY_MOBILE=1",
|
||||
"-DFOLLY_USE_LIBCPP=1",
|
||||
"-DFOLLY_CFG_NO_COROUTINES=1",
|
||||
"-DFOLLY_HAVE_CLOCK_GETTIME=1",
|
||||
);
|
||||
OTHER_LDFLAGS = "$(inherited)";
|
||||
REACT_NATIVE_PATH = "${PODS_ROOT}/../../node_modules/react-native";
|
||||
|
||||
@@ -1835,7 +1835,7 @@ PODS:
|
||||
- ReactCommon/turbomodule/core
|
||||
- SocketRocket
|
||||
- Yoga
|
||||
- react-native-update (10.31.2):
|
||||
- react-native-update (10.35.6):
|
||||
- boost
|
||||
- DoubleConversion
|
||||
- fast_float
|
||||
@@ -1854,7 +1854,7 @@ PODS:
|
||||
- React-graphics
|
||||
- React-ImageManager
|
||||
- React-jsi
|
||||
- react-native-update/RCTPushy (= 10.31.2)
|
||||
- react-native-update/RCTPushy (= 10.35.6)
|
||||
- React-NativeModulesApple
|
||||
- React-RCTFabric
|
||||
- React-renderercss
|
||||
@@ -1866,7 +1866,7 @@ PODS:
|
||||
- SocketRocket
|
||||
- SSZipArchive
|
||||
- Yoga
|
||||
- react-native-update/RCTPushy (10.31.2):
|
||||
- react-native-update/RCTPushy (10.35.6):
|
||||
- boost
|
||||
- DoubleConversion
|
||||
- fast_float
|
||||
@@ -2800,7 +2800,7 @@ SPEC CHECKSUMS:
|
||||
React-Mapbuffer: 9d2434a42701d6144ca18f0ca1c4507808ca7696
|
||||
React-microtasksnativemodule: 75b6604b667d297292345302cc5bfb6b6aeccc1b
|
||||
react-native-safe-area-context: c6e2edd1c1da07bdce287fa9d9e60c5f7b514616
|
||||
react-native-update: 7a05a78c6da651c1961b8407859f44bd0aa9b03a
|
||||
react-native-update: 5e2274c66e654b001fae360600f5a9314c1c67e1
|
||||
React-NativeModulesApple: 879fbdc5dcff7136abceb7880fe8a2022a1bd7c3
|
||||
React-oscompat: 93b5535ea7f7dff46aaee4f78309a70979bdde9d
|
||||
React-perflogger: 5536d2df3d18fe0920263466f7b46a56351c0510
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
"test:e2e": "detox test --configuration android.emu.debug",
|
||||
"lint": "eslint .",
|
||||
"postinstall": "patch-package",
|
||||
"apk": "cd android && ./gradlew assembleRelease",
|
||||
"dev:harmony": "react-native bundle-harmony --dev"
|
||||
"apk": "cd android && ./gradlew assembleRelease"
|
||||
},
|
||||
"dependencies": {
|
||||
"form-data": "^4.0.4",
|
||||
@@ -22,7 +21,7 @@
|
||||
"react-native-paper": "^5.14.5",
|
||||
"react-native-safe-area-context": "^5.6.1",
|
||||
"react-native-svg": "^15.13.0",
|
||||
"react-native-update": "^10.31.2",
|
||||
"react-native-update": "^10.35.6",
|
||||
"react-native-vector-icons": "^10.3.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -25,7 +25,7 @@ import { LocalSvg } from 'react-native-svg/css';
|
||||
import TestConsole from './TestConsole';
|
||||
|
||||
import _updateConfig from '../update.json';
|
||||
import { UpdateProvider, Pushy, Cresc, useUpdate } from 'react-native-update';
|
||||
import { UpdateProvider, Pushy, useUpdate } from 'react-native-update';
|
||||
const { appKey } = _updateConfig[Platform.OS];
|
||||
|
||||
function App() {
|
||||
@@ -53,7 +53,7 @@ function App() {
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text style={styles.welcome}>欢迎22使用Pushy热更新服务</Text>
|
||||
<Text style={styles.welcome}>欢迎使用Pushy热更新服务</Text>
|
||||
<View style={{ flexDirection: 'row' }}>
|
||||
<Text>
|
||||
{useDefaultAlert ? '当前使用' : '当前不使用'}默认的alert更新提示
|
||||
|
||||
27
README.md
27
README.md
@@ -19,6 +19,33 @@
|
||||
7. meta 信息及开放 API,提供更高扩展性。
|
||||
8. 提供付费的专人技术支持。
|
||||
|
||||
### 与其他热更新库对比
|
||||
|
||||
| 对比维度 | react-native-update | expo-update | react-native-code-push |
|
||||
|---------|---------------------|-------------|------------------------|
|
||||
| **价格/成本** | 提供免费额度,多级梯度付费(最低约 66 元/月),流量不单独计费 | 提供免费额度,多级梯度付费(最低约 136 元/月),超出流量额外计费 | ❌ **已停运**(Microsoft App Center 已于 2025 年 3 月 31 日停止服务) |
|
||||
| **更新包大小** | ⭐⭐⭐⭐⭐ 几十 KB(增量更新) | ⭐⭐⭐ 全量更新(通常几十 MB) | ❌ **已停运** |
|
||||
| **中国地区访问速度** | ⭐⭐⭐⭐⭐ 阿里云 CDN,速度极快 | ⭐⭐ 国外服务器,可能较慢 | ❌ **已停运** |
|
||||
| **iOS 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **Android 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **鸿蒙支持** | ✅ 支持 | ❌ 不支持 | ❌ **已停运** |
|
||||
| **Expo 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **RN 版本支持** | ⭐⭐⭐⭐⭐ 第一时间支持最新版本 | ⭐⭐⭐⭐ 跟随 Expo SDK | ❌ **已停运** |
|
||||
| **新架构支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **Hermes 支持** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **崩溃回滚** | ✅ 自动回滚机制 | ✅ 支持 | ❌ **已停运** |
|
||||
| **管理界面** | ✅ 命令行工具 + Web 管理界面 | ✅ Expo Dashboard | ❌ **已停运** |
|
||||
| **CI/CD 集成** | ✅ 支持 | ✅ 支持 | ❌ **已停运** |
|
||||
| **API 扩展性** | ✅ Meta 信息 + 开放 API | ⚠️ 有限 | ❌ **已停运** |
|
||||
| **中文文档/支持** | ⭐⭐⭐⭐⭐ 完整中文文档,中文社区支持 | ⭐⭐ 英文为主 | ❌ **已停运** |
|
||||
| **技术支持** | ✅ 付费专人技术支持 | ⚠️ 社区支持 | ❌ **已停运** |
|
||||
| **服务器部署** | ✅ 可托管也可付费私有部署 | ✅ Expo 托管(EAS Update) | ❌ **已停运** |
|
||||
| **更新策略** | 灵活配置(静默/提示/立即/延迟) | 相对固定 | ❌ **已停运** |
|
||||
| **流量消耗** | ⭐⭐⭐⭐⭐ 极低(增量更新) | ⭐⭐⭐ 较高(全量更新) | ❌ **已停运** |
|
||||
| **更新成功率** | ⭐⭐⭐⭐⭐ 极高(国内 CDN 优势) | ⭐⭐⭐ 中等 | ❌ **已停运** |
|
||||
|
||||
|
||||
|
||||
### 本地开发
|
||||
|
||||
```
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package cn.reactnative.modules.update;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.WritableMap;
|
||||
@@ -25,7 +28,6 @@ import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.HashMap;
|
||||
|
||||
import okio.BufferedSink;
|
||||
@@ -98,9 +100,6 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
while ((bytesRead = source.read(sink.buffer(), DOWNLOAD_CHUNK_SIZE)) != -1) {
|
||||
received += bytesRead;
|
||||
sink.emit();
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("react-native-update", "Progress " + received + "/" + contentLength);
|
||||
}
|
||||
|
||||
int percentage = (int)(received * 100.0 / contentLength + 0.5);
|
||||
if (percentage > currentPercentage) {
|
||||
@@ -199,10 +198,6 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
return fout.toByteArray();
|
||||
}
|
||||
|
||||
private String getCRC32AsDecimal(long crc32Value) {
|
||||
return String.valueOf(crc32Value & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
private void copyFilesWithBlacklist(String current, File from, File to, JSONObject blackList) throws IOException {
|
||||
File[] files = from.listFiles();
|
||||
for (File file : files) {
|
||||
@@ -252,57 +247,209 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
}
|
||||
}
|
||||
|
||||
private void copyFromResource(HashMap<String, ArrayList<File> > resToCopy) throws IOException {
|
||||
SafeZipFile zipFile = new SafeZipFile(new File(context.getPackageResourcePath()));
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry ze = entries.nextElement();
|
||||
private String findDrawableFallback(String originalToPath, HashMap<String, String> copiesMap, HashMap<String, ZipEntry> availableEntries) {
|
||||
// 检查是否是 drawable 路径
|
||||
if (!originalToPath.contains("drawable")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String fn = ze.getName();
|
||||
ArrayList<File> targets = resToCopy.get(fn);
|
||||
if (targets != null) {
|
||||
File lastTarget = null;
|
||||
for (File target: targets) {
|
||||
// 提取文件名(路径的最后部分)
|
||||
int lastSlash = originalToPath.lastIndexOf('/');
|
||||
if (lastSlash == -1) {
|
||||
return null;
|
||||
}
|
||||
String fileName = originalToPath.substring(lastSlash + 1);
|
||||
|
||||
// 定义密度优先级(从高到低)
|
||||
String[] densities = {"xxxhdpi", "xxhdpi", "xhdpi", "hdpi", "mdpi", "ldpi"};
|
||||
|
||||
// 尝试找到相同文件名但不同密度的 key
|
||||
for (String density : densities) {
|
||||
// 构建可能的 key 路径(替换密度部分)
|
||||
String fallbackToPath = originalToPath.replaceFirst("drawable-[^/]+", "drawable-" + density);
|
||||
|
||||
// 检查这个 key 是否在 copies 映射中
|
||||
if (copiesMap.containsKey(fallbackToPath)) {
|
||||
String fallbackFromPath = copiesMap.get(fallbackToPath);
|
||||
// 检查对应的 value 路径是否在 APK 中存在
|
||||
if (availableEntries.containsKey(fallbackFromPath)) {
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("react-native-update", "Copying from resource " + fn + " to " + target);
|
||||
}
|
||||
if (lastTarget != null) {
|
||||
copyFile(lastTarget, target);
|
||||
} else {
|
||||
zipFile.unzipToFile(ze, target);
|
||||
lastTarget = target;
|
||||
Log.d("react-native-update", "Found fallback for " + originalToPath + ": " + fallbackToPath + " -> " + fallbackFromPath);
|
||||
}
|
||||
return fallbackFromPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
zipFile.close();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void copyFromResourceV2(HashMap<String, ArrayList<File>> resToCopy2) throws IOException {
|
||||
SafeZipFile zipFile = new SafeZipFile(new File(context.getPackageResourcePath()));
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry ze = entries.nextElement();
|
||||
String fn = ze.getName();
|
||||
long zipCrc32 = ze.getCrc();
|
||||
String crc32Decimal = getCRC32AsDecimal(zipCrc32);
|
||||
ArrayList<File> targets = resToCopy2.get(crc32Decimal);
|
||||
if (targets != null) {
|
||||
File lastTarget = null;
|
||||
for (File target: targets) {
|
||||
private void copyFromResource(HashMap<String, ArrayList<File> > resToCopy, HashMap<String, String> copiesMap) throws IOException {
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("react-native-update", "copyFromResource called, resToCopy size: " + resToCopy.size());
|
||||
}
|
||||
|
||||
// 收集所有 APK 路径(包括基础 APK 和所有 split APK)
|
||||
ArrayList<String> apkPaths = new ArrayList<>();
|
||||
apkPaths.add(context.getPackageResourcePath());
|
||||
|
||||
// 获取所有 split APK 路径(用于资源分割的情况)
|
||||
try {
|
||||
ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(
|
||||
context.getPackageName(), 0);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && appInfo.splitSourceDirs != null) {
|
||||
for (String splitPath : appInfo.splitSourceDirs) {
|
||||
apkPaths.add(splitPath);
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("react-native-update", "Copying from resource " + fn + " to " + target);
|
||||
}
|
||||
if (lastTarget != null) {
|
||||
copyFile(lastTarget, target);
|
||||
} else {
|
||||
zipFile.unzipToFile(ze, target);
|
||||
lastTarget = target;
|
||||
Log.d("react-native-update", "Found split APK: " + splitPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.w("react-native-update", "Failed to get application info: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 第一遍:从所有 APK 中收集所有可用的 zip 条目
|
||||
HashMap<String, ZipEntry> availableEntries = new HashMap<>();
|
||||
HashMap<String, SafeZipFile> zipFileMap = new HashMap<>(); // 保存每个路径对应的 ZipFile
|
||||
HashMap<String, SafeZipFile> entryToZipFileMap = new HashMap<>(); // 保存每个条目对应的 ZipFile
|
||||
|
||||
for (String apkPath : apkPaths) {
|
||||
SafeZipFile zipFile = new SafeZipFile(new File(apkPath));
|
||||
zipFileMap.put(apkPath, zipFile);
|
||||
Enumeration<? extends ZipEntry> entries = zipFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry ze = entries.nextElement();
|
||||
String entryName = ze.getName();
|
||||
// 如果条目已存在,保留第一个(基础 APK 优先)
|
||||
if (!availableEntries.containsKey(entryName)) {
|
||||
availableEntries.put(entryName, ze);
|
||||
entryToZipFileMap.put(entryName, zipFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用基础 APK 的 ZipFile 作为主要操作对象
|
||||
SafeZipFile zipFile = zipFileMap.get(context.getPackageResourcePath());
|
||||
|
||||
// 处理所有需要复制的文件
|
||||
HashMap<String, ArrayList<File>> remainingFiles = new HashMap<>(resToCopy);
|
||||
|
||||
for (String fromPath : new ArrayList<>(remainingFiles.keySet())) {
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("react-native-update", "Processing fromPath: " + fromPath);
|
||||
}
|
||||
ArrayList<File> targets = remainingFiles.get(fromPath);
|
||||
if (targets == null || targets.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ZipEntry ze = availableEntries.get(fromPath);
|
||||
String actualSourcePath = fromPath;
|
||||
|
||||
// 如果文件不存在,尝试 fallback
|
||||
if (ze == null) {
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("react-native-update", "File not found in APK: " + fromPath + ", trying fallback");
|
||||
}
|
||||
// 找到对应的 to 路径(从 copiesMap 的反向查找)
|
||||
String toPath = null;
|
||||
for (String to : copiesMap.keySet()) {
|
||||
if (copiesMap.get(to).equals(fromPath)) {
|
||||
toPath = to;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (toPath != null) {
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("react-native-update", "Found toPath: " + toPath + " for fromPath: " + fromPath);
|
||||
}
|
||||
String fallbackFromPath = findDrawableFallback(toPath, copiesMap, availableEntries);
|
||||
if (fallbackFromPath != null) {
|
||||
ze = availableEntries.get(fallbackFromPath);
|
||||
actualSourcePath = fallbackFromPath;
|
||||
// 确保 fallback 路径也在 entryToZipFileMap 中
|
||||
if (!entryToZipFileMap.containsKey(fallbackFromPath)) {
|
||||
// 查找包含该 fallback 路径的 ZipFile
|
||||
for (String apkPath : apkPaths) {
|
||||
SafeZipFile testZipFile = zipFileMap.get(apkPath);
|
||||
if (testZipFile != null) {
|
||||
try {
|
||||
ZipEntry testEntry = testZipFile.getEntry(fallbackFromPath);
|
||||
if (testEntry != null) {
|
||||
entryToZipFileMap.put(fallbackFromPath, testZipFile);
|
||||
break;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 继续查找
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.w("react-native-update", "Using fallback: " + fallbackFromPath + " for " + fromPath);
|
||||
}
|
||||
} else {
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.w("react-native-update", "No fallback found for: " + fromPath + " (toPath: " + toPath + ")");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.w("react-native-update", "No toPath found for fromPath: " + fromPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ze != null) {
|
||||
File lastTarget = null;
|
||||
for (File target: targets) {
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("react-native-update", "Copying from resource " + actualSourcePath + " to " + target);
|
||||
}
|
||||
try {
|
||||
// 确保目标文件的父目录存在
|
||||
File parentDir = target.getParentFile();
|
||||
if (parentDir != null && !parentDir.exists()) {
|
||||
parentDir.mkdirs();
|
||||
}
|
||||
|
||||
if (lastTarget != null) {
|
||||
copyFile(lastTarget, target);
|
||||
} else {
|
||||
// 从保存的映射中获取包含该条目的 ZipFile
|
||||
SafeZipFile sourceZipFile = entryToZipFileMap.get(actualSourcePath);
|
||||
if (sourceZipFile == null) {
|
||||
sourceZipFile = zipFile; // 回退到基础 APK
|
||||
}
|
||||
sourceZipFile.unzipToFile(ze, target);
|
||||
lastTarget = target;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.w("react-native-update", "Failed to copy resource " + actualSourcePath + " to " + target + ": " + e.getMessage());
|
||||
}
|
||||
// 继续处理下一个目标
|
||||
}
|
||||
}
|
||||
remainingFiles.remove(fromPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 处理剩余的文件(如果还有的话)
|
||||
if (!remainingFiles.isEmpty() && UpdateContext.DEBUG) {
|
||||
for (String fromPath : remainingFiles.keySet()) {
|
||||
Log.w("react-native-update", "Resource not found and no fallback available: " + fromPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭所有 ZipFile
|
||||
for (SafeZipFile zf : zipFileMap.values()) {
|
||||
zf.close();
|
||||
}
|
||||
zipFile.close();
|
||||
}
|
||||
|
||||
private void doPatchFromApk(DownloadTaskParams param) throws IOException, JSONException {
|
||||
@@ -311,8 +458,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
removeDirectory(param.unzipDirectory);
|
||||
param.unzipDirectory.mkdirs();
|
||||
HashMap<String, ArrayList<File>> copyList = new HashMap<String, ArrayList<File>>();
|
||||
HashMap<String, ArrayList<File>> copiesv2List = new HashMap<String, ArrayList<File>>();
|
||||
Boolean isV2 = false;
|
||||
HashMap<String, String> copiesMap = new HashMap<String, String>(); // to -> from 映射
|
||||
|
||||
boolean foundDiff = false;
|
||||
boolean foundBundlePatch = false;
|
||||
@@ -331,58 +477,32 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
JSONObject obj = (JSONObject)new JSONTokener(json).nextValue();
|
||||
|
||||
JSONObject copies = obj.getJSONObject("copies");
|
||||
JSONObject copiesv2 = obj.getJSONObject("copiesv2");
|
||||
Iterator<?> keys = copies.keys();
|
||||
Iterator<?> keysV2 = copiesv2.keys();
|
||||
if(keysV2.hasNext()){
|
||||
isV2 = true;
|
||||
while( keysV2.hasNext() ) {
|
||||
String from = (String)keysV2.next();
|
||||
String to = copiesv2.getString(from);
|
||||
if (from.isEmpty()) {
|
||||
from = to;
|
||||
}
|
||||
ArrayList<File> target = null;
|
||||
if (!copiesv2List.containsKey(from)) {
|
||||
target = new ArrayList<File>();
|
||||
copiesv2List.put(from, target);
|
||||
} else {
|
||||
target = copiesv2List.get((from));
|
||||
}
|
||||
File toFile = new File(param.unzipDirectory, to);
|
||||
|
||||
// Fixing a Zip Path Traversal Vulnerability
|
||||
// https://support.google.com/faqs/answer/9294009
|
||||
String canonicalPath = toFile.getCanonicalPath();
|
||||
if (!canonicalPath.startsWith(param.unzipDirectory.getCanonicalPath() + File.separator)) {
|
||||
throw new SecurityException("Illegal name: " + to);
|
||||
}
|
||||
target.add(toFile);
|
||||
while( keys.hasNext() ) {
|
||||
String to = (String)keys.next();
|
||||
String from = copies.getString(to);
|
||||
if (from.isEmpty()) {
|
||||
from = to;
|
||||
}
|
||||
}else{
|
||||
while( keys.hasNext() ) {
|
||||
String to = (String)keys.next();
|
||||
String from = copies.getString(to);
|
||||
if (from.isEmpty()) {
|
||||
from = to;
|
||||
}
|
||||
ArrayList<File> target = null;
|
||||
if (!copyList.containsKey(from)) {
|
||||
target = new ArrayList<File>();
|
||||
copyList.put(from, target);
|
||||
} else {
|
||||
target = copyList.get((from));
|
||||
}
|
||||
File toFile = new File(param.unzipDirectory, to);
|
||||
|
||||
// Fixing a Zip Path Traversal Vulnerability
|
||||
// https://support.google.com/faqs/answer/9294009
|
||||
String canonicalPath = toFile.getCanonicalPath();
|
||||
if (!canonicalPath.startsWith(param.unzipDirectory.getCanonicalPath() + File.separator)) {
|
||||
throw new SecurityException("Illegal name: " + to);
|
||||
}
|
||||
target.add(toFile);
|
||||
// 保存 copies 映射关系(to -> from)
|
||||
copiesMap.put(to, from);
|
||||
|
||||
ArrayList<File> target = null;
|
||||
if (!copyList.containsKey(from)) {
|
||||
target = new ArrayList<File>();
|
||||
copyList.put(from, target);
|
||||
} else {
|
||||
target = copyList.get((from));
|
||||
}
|
||||
File toFile = new File(param.unzipDirectory, to);
|
||||
|
||||
// Fixing a Zip Path Traversal Vulnerability
|
||||
// https://support.google.com/faqs/answer/9294009
|
||||
String canonicalPath = toFile.getCanonicalPath();
|
||||
if (!canonicalPath.startsWith(param.unzipDirectory.getCanonicalPath() + File.separator)) {
|
||||
throw new SecurityException("Illegal name: " + to);
|
||||
}
|
||||
target.add(toFile);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -411,12 +531,15 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
|
||||
throw new Error("bundle patch not found");
|
||||
}
|
||||
|
||||
if(isV2){
|
||||
copyFromResourceV2(copiesv2List);
|
||||
}else{
|
||||
copyFromResource(copyList);
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("react-native-update", "copyList size: " + copyList.size() + ", copiesMap size: " + copiesMap.size());
|
||||
for (String from : copyList.keySet()) {
|
||||
Log.d("react-native-update", "copyList entry: " + from + " -> " + copyList.get(from).size() + " targets");
|
||||
}
|
||||
}
|
||||
|
||||
copyFromResource(copyList, copiesMap);
|
||||
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("react-native-update", "Unzip finished");
|
||||
}
|
||||
|
||||
@@ -66,9 +66,8 @@ public class SafeZipFile extends ZipFile {
|
||||
throw new SecurityException("Illegal name: " + name);
|
||||
}
|
||||
|
||||
if (UpdateContext.DEBUG) {
|
||||
Log.d("RNUpdate", "Unzipping " + name);
|
||||
}
|
||||
|
||||
Log.d("react-native-update", "Unzipping " + name);
|
||||
|
||||
if (ze.isDirectory()) {
|
||||
target.mkdirs();
|
||||
|
||||
@@ -19,9 +19,13 @@ public class UpdateContext {
|
||||
private File rootDir;
|
||||
private Executor executor;
|
||||
|
||||
public static boolean DEBUG = false;
|
||||
public static boolean DEBUG = true;
|
||||
private static ReactInstanceManager mReactInstanceManager;
|
||||
private static boolean isUsingBundleUrl = false;
|
||||
|
||||
// Singleton instance
|
||||
private static UpdateContext sInstance;
|
||||
private static final Object sLock = new Object();
|
||||
|
||||
public UpdateContext(Context context) {
|
||||
this.context = context;
|
||||
@@ -54,13 +58,17 @@ public class UpdateContext {
|
||||
boolean buildTimeChanged = !buildTime.equals(storedBuildTime);
|
||||
|
||||
if (packageVersionChanged || buildTimeChanged) {
|
||||
// Execute cleanUp before clearing SharedPreferences to avoid race condition
|
||||
this.cleanUp();
|
||||
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.clear();
|
||||
editor.putString("packageVersion", packageVersion);
|
||||
editor.putString("buildTime", buildTime);
|
||||
editor.apply();
|
||||
|
||||
this.cleanUp();
|
||||
// Use commit() instead of apply() to ensure synchronous write completion
|
||||
// This prevents race condition where getBundleUrl() might read null values
|
||||
// if called before apply() completes
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,12 +235,26 @@ public class UpdateContext {
|
||||
return mReactInstanceManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get singleton instance of UpdateContext
|
||||
*/
|
||||
public static UpdateContext getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
synchronized (sLock) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new UpdateContext(context.getApplicationContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public static String getBundleUrl(Context context) {
|
||||
return new UpdateContext(context.getApplicationContext()).getBundleUrl();
|
||||
return getInstance(context).getBundleUrl();
|
||||
}
|
||||
|
||||
public static String getBundleUrl(Context context, String defaultAssetsUrl) {
|
||||
return new UpdateContext(context.getApplicationContext()).getBundleUrl(defaultAssetsUrl);
|
||||
return getInstance(context).getBundleUrl(defaultAssetsUrl);
|
||||
}
|
||||
|
||||
public String getBundleUrl() {
|
||||
@@ -273,6 +295,7 @@ public class UpdateContext {
|
||||
if (lastVersion == null) {
|
||||
editor.remove("currentVersion");
|
||||
} else {
|
||||
editor.remove("lastVersion");
|
||||
editor.putString("currentVersion", lastVersion);
|
||||
}
|
||||
editor.putBoolean("firstTimeOk", true);
|
||||
|
||||
@@ -27,7 +27,7 @@ public class UpdateModule extends NativePushySpec {
|
||||
}
|
||||
|
||||
public UpdateModule(ReactApplicationContext reactContext) {
|
||||
this(reactContext, new UpdateContext(reactContext.getApplicationContext()));
|
||||
this(reactContext, UpdateContext.getInstance(reactContext));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UpdateModule extends ReactContextBaseJavaModule {
|
||||
}
|
||||
|
||||
public UpdateModule(ReactApplicationContext reactContext) {
|
||||
this(reactContext, new UpdateContext(reactContext.getApplicationContext()));
|
||||
this(reactContext, UpdateContext.getInstance(reactContext));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Binary file not shown.
39
harmony/pushy/hvigor-plugin.ts
Normal file
39
harmony/pushy/hvigor-plugin.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export function reactNativeUpdatePlugin() {
|
||||
return {
|
||||
pluginId: 'reactNativeUpdatePlugin',
|
||||
apply(node) {
|
||||
node.registerTask({
|
||||
name: 'reactNativeUpdatePlugin',
|
||||
run: () => {
|
||||
const cwd = process.cwd();
|
||||
const metaFilePath = path.resolve(
|
||||
cwd,
|
||||
'entry/src/main/resources/rawfile/meta.json',
|
||||
);
|
||||
fs.mkdirSync(path.dirname(metaFilePath), { recursive: true });
|
||||
|
||||
const moduleJsonPath = path.resolve(cwd, 'AppScope/app.json5');
|
||||
let versionName = '';
|
||||
if (fs.existsSync(moduleJsonPath)) {
|
||||
const content = fs.readFileSync(moduleJsonPath, 'utf-8');
|
||||
const match = content.match(
|
||||
/(?:"versionName"|versionName):\s*["']([^"']+)["']/,
|
||||
);
|
||||
versionName = match?.[1] || '';
|
||||
}
|
||||
|
||||
const metaContent = {
|
||||
pushy_build_time: new Date().toISOString(),
|
||||
versionName,
|
||||
};
|
||||
|
||||
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 2));
|
||||
console.log(`Build time written to ${metaFilePath}`);
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,18 +1,19 @@
|
||||
{
|
||||
"meta": {
|
||||
"stableOrder": true
|
||||
"stableOrder": true,
|
||||
"enableUnifiedLockfile": false
|
||||
},
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38"
|
||||
"@rnoh/react-native-openharmony@^0.72.96": "@rnoh/react-native-openharmony@0.72.96"
|
||||
},
|
||||
"packages": {
|
||||
"@rnoh/react-native-openharmony@0.72.38": {
|
||||
"name": "@rnoh/react-native-openharmony",
|
||||
"version": "0.72.38",
|
||||
"integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
|
||||
"@rnoh/react-native-openharmony@0.72.96": {
|
||||
"name": "",
|
||||
"version": "0.72.96",
|
||||
"integrity": "sha512-gBbm8LLyqi5UE7qHWdZYeQnjyncfEpCczKZUP/9M2U1Z7exR0Kya8PMKMwr1ta5ujy7w/hZVC2LomEV4QvBeqA==",
|
||||
"resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.96.har",
|
||||
"registryType": "ohpm"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
{
|
||||
"license": "ISC",
|
||||
"types": "",
|
||||
"devDependencies": {},
|
||||
"name": "pushy",
|
||||
"description": "",
|
||||
"main": "index.ets",
|
||||
"version": "3.1.0-0.0.7",
|
||||
"dependencies": {
|
||||
"@rnoh/react-native-openharmony":"^0.72.38"
|
||||
}
|
||||
license: 'MIT',
|
||||
types: '',
|
||||
devDependencies: {},
|
||||
name: 'pushy',
|
||||
description: '',
|
||||
main: 'index.ets',
|
||||
version: '10.35.1',
|
||||
dependencies: {
|
||||
'@rnoh/react-native-openharmony': '^0.72.96',
|
||||
},
|
||||
modelVersion: '5.0.0',
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
project(rnupdate)
|
||||
|
||||
set(HDIFFPATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR}/HDiffPatch)
|
||||
set(LZMA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lzma)
|
||||
# Point to android/jni directory for shared source code
|
||||
set(ANDROID_JNI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../../node_modules/react-native-update/android/jni)
|
||||
set(HDIFFPATCH_DIR ${ANDROID_JNI_DIR}/HDiffPatch)
|
||||
set(LZMA_DIR ${ANDROID_JNI_DIR}/lzma)
|
||||
set(HDP_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/pushy.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/hpatch.c
|
||||
${ANDROID_JNI_DIR}/hpatch.c
|
||||
${HDIFFPATCH_DIR}/libHDiffPatch/HPatch/patch.c
|
||||
${HDIFFPATCH_DIR}/file_for_patch.c
|
||||
${LZMA_DIR}/C/LzmaDec.c
|
||||
@@ -20,6 +22,7 @@ add_library(rnupdate SHARED
|
||||
|
||||
target_include_directories(rnupdate PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${ANDROID_JNI_DIR}
|
||||
${HDIFFPATCH_DIR}
|
||||
${HDIFFPATCH_DIR}/libHDiffPatch/HPatch
|
||||
${LZMA_DIR}/C
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
// hpatch.c
|
||||
// Copyright 2021 housisong, All rights reserved
|
||||
#include "hpatch.h"
|
||||
#include "HDiffPatch/libHDiffPatch/HPatch/patch.h"
|
||||
#include "HDiffPatch/file_for_patch.h"
|
||||
|
||||
//#define _CompressPlugin_zlib
|
||||
//#define _CompressPlugin_bz2
|
||||
#define _CompressPlugin_lzma
|
||||
#define _CompressPlugin_lzma2
|
||||
#define _IsNeedIncludeDefaultCompressHead 0
|
||||
#include "lzma/C/LzmaDec.h"
|
||||
#include "lzma/C/Lzma2Dec.h"
|
||||
#include "HDiffPatch/decompress_plugin_demo.h"
|
||||
|
||||
#define kMaxLoadMemOldSize ((1<<20)*8)
|
||||
|
||||
#define _check(v,errorType) do{ \
|
||||
if (!(v)){ if (result==kHPatch_ok) result=errorType; if (!_isInClear){ goto _clear; }; } }while(0)
|
||||
|
||||
int hpatch_getInfo_by_mem(hpatch_singleCompressedDiffInfo* out_patinfo,
|
||||
const uint8_t* pat,size_t patsize){
|
||||
hpatch_TStreamInput patStream;
|
||||
mem_as_hStreamInput(&patStream,pat,pat+patsize);
|
||||
if (!getSingleCompressedDiffInfo(out_patinfo,&patStream,0))
|
||||
return kHPatch_error_info;//data error;
|
||||
return kHPatch_ok; //ok
|
||||
}
|
||||
|
||||
static hpatch_TDecompress* getDecompressPlugin(const char* compressType){
|
||||
#ifdef _CompressPlugin_zlib
|
||||
if (zlibDecompressPlugin.is_can_open(compressType))
|
||||
return &zlibDecompressPlugin;
|
||||
#endif
|
||||
#ifdef _CompressPlugin_bz2
|
||||
if (bz2DecompressPlugin.is_can_open(compressType))
|
||||
return &bz2DecompressPlugin;
|
||||
#endif
|
||||
#ifdef _CompressPlugin_lzma
|
||||
if (lzmaDecompressPlugin.is_can_open(compressType))
|
||||
return &lzmaDecompressPlugin;
|
||||
#endif
|
||||
#ifdef _CompressPlugin_lzma2
|
||||
if (lzma2DecompressPlugin.is_can_open(compressType))
|
||||
return &lzma2DecompressPlugin;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
static int hpatch_by_stream(const hpatch_TStreamInput* old,hpatch_BOOL isLoadOldAllToMem,const hpatch_TStreamInput* pat,
|
||||
hpatch_TStreamOutput* out_new,const hpatch_singleCompressedDiffInfo* patInfo){
|
||||
int result=kHPatch_ok;
|
||||
int _isInClear=hpatch_FALSE;
|
||||
hpatch_TDecompress* decompressPlugin=0;
|
||||
uint8_t* temp_cache=0;
|
||||
size_t temp_cache_size;
|
||||
hpatch_singleCompressedDiffInfo _patinfo;
|
||||
hpatch_TStreamInput _old;
|
||||
{// info
|
||||
if (!patInfo){
|
||||
_check(getSingleCompressedDiffInfo(&_patinfo,pat,0),kHPatch_error_info);
|
||||
patInfo=&_patinfo;
|
||||
}
|
||||
_check(old->streamSize==patInfo->oldDataSize,kHPatch_error_old_size);
|
||||
_check(out_new->streamSize>=patInfo->newDataSize,kHPatch_error_new_size);
|
||||
out_new->streamSize=patInfo->newDataSize;
|
||||
if (strlen(patInfo->compressType)>0){
|
||||
decompressPlugin=getDecompressPlugin(patInfo->compressType);
|
||||
_check(decompressPlugin,kHPatch_error_compressType);
|
||||
}
|
||||
}
|
||||
{// mem
|
||||
size_t mem_size;
|
||||
size_t oldSize=(size_t)old->streamSize;
|
||||
isLoadOldAllToMem=isLoadOldAllToMem&&(old->streamSize<=kMaxLoadMemOldSize);
|
||||
temp_cache_size=patInfo->stepMemSize+hpatch_kFileIOBufBetterSize*3;
|
||||
mem_size=temp_cache_size+(isLoadOldAllToMem?oldSize:0);
|
||||
temp_cache=malloc(mem_size);
|
||||
_check(temp_cache,kHPatch_error_malloc);
|
||||
if (isLoadOldAllToMem){//load old to mem
|
||||
uint8_t* oldMem=temp_cache+temp_cache_size;
|
||||
_check(old->read(old,0,oldMem,oldMem+oldSize),kHPatch_error_old_fread);
|
||||
mem_as_hStreamInput(&_old,oldMem,oldMem+oldSize);
|
||||
old=&_old;
|
||||
}
|
||||
}
|
||||
|
||||
_check(patch_single_compressed_diff(out_new,old,pat,patInfo->diffDataPos,
|
||||
patInfo->uncompressedSize,decompressPlugin,patInfo->coverCount,
|
||||
patInfo->stepMemSize,temp_cache,temp_cache+temp_cache_size),kHPatch_error_patch);
|
||||
|
||||
_clear:
|
||||
_isInClear=hpatch_TRUE;
|
||||
if (temp_cache){ free(temp_cache); temp_cache=0; }
|
||||
return result;
|
||||
}
|
||||
|
||||
int hpatch_by_mem(const uint8_t* old,size_t oldsize,uint8_t* newBuf,size_t newsize,
|
||||
const uint8_t* pat,size_t patsize,const hpatch_singleCompressedDiffInfo* patInfo){
|
||||
hpatch_TStreamInput oldStream;
|
||||
hpatch_TStreamInput patStream;
|
||||
hpatch_TStreamOutput newStream;
|
||||
mem_as_hStreamInput(&oldStream,old,old+oldsize);
|
||||
mem_as_hStreamInput(&patStream,pat,pat+patsize);
|
||||
mem_as_hStreamOutput(&newStream,newBuf,newBuf+newsize);
|
||||
return hpatch_by_stream(&oldStream,hpatch_FALSE,&patStream,&newStream,patInfo);
|
||||
}
|
||||
|
||||
int hpatch_by_file(const char* oldfile, const char* newfile, const char* patchfile){
|
||||
int result=kHPatch_ok;
|
||||
int _isInClear=hpatch_FALSE;
|
||||
int patch_result;
|
||||
hpatch_TFileStreamInput oldStream;
|
||||
hpatch_TFileStreamInput patStream;
|
||||
hpatch_TFileStreamOutput newStream;
|
||||
hpatch_TFileStreamInput_init(&oldStream);
|
||||
hpatch_TFileStreamInput_init(&patStream);
|
||||
hpatch_TFileStreamOutput_init(&newStream);
|
||||
|
||||
_check(hpatch_TFileStreamInput_open(&oldStream,oldfile),kHPatch_error_old_fopen);
|
||||
_check(hpatch_TFileStreamInput_open(&patStream,patchfile),kHPatch_error_pat_fopen);
|
||||
_check(hpatch_TFileStreamOutput_open(&newStream,newfile,~(hpatch_StreamPos_t)0),kHPatch_error_new_fopen);
|
||||
|
||||
patch_result=hpatch_by_stream(&oldStream.base,hpatch_TRUE,&patStream.base,&newStream.base,0);
|
||||
if (patch_result!=kHPatch_ok){
|
||||
_check(!oldStream.fileError,kHPatch_error_old_fread);
|
||||
_check(!patStream.fileError,kHPatch_error_pat_fread);
|
||||
_check(!newStream.fileError,kHPatch_error_new_fwrite);
|
||||
_check(hpatch_FALSE,patch_result);
|
||||
}
|
||||
|
||||
_clear:
|
||||
_isInClear=hpatch_TRUE;
|
||||
_check(hpatch_TFileStreamInput_close(&oldStream),kHPatch_error_old_fclose);
|
||||
_check(hpatch_TFileStreamInput_close(&patStream),kHPatch_error_pat_fclose);
|
||||
_check(hpatch_TFileStreamOutput_close(&newStream),kHPatch_error_new_fclose);
|
||||
return result;
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
// hpatch.h
|
||||
// import HDiffPatch, support patchData created by "hdiffz -SD -c-lzma2 oldfile newfile patchfile"
|
||||
// Copyright 2021 housisong, All rights reserved
|
||||
|
||||
#ifndef HDIFFPATCH_PATCH_H
|
||||
#define HDIFFPATCH_PATCH_H
|
||||
# include <stdint.h> //for uint8_t
|
||||
#include "HDiffPatch/libHDiffPatch/HPatch/patch_types.h" //for hpatch_singleCompressedDiffInfo
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//result
|
||||
enum {
|
||||
kHPatch_ok = 0,
|
||||
kHPatch_error_malloc =-1,
|
||||
kHPatch_error_info =-2,
|
||||
kHPatch_error_compressType =-3,
|
||||
kHPatch_error_patch =-4,
|
||||
kHPatch_error_old_fopen =-5,
|
||||
kHPatch_error_old_fread =-6,
|
||||
kHPatch_error_old_fclose =-7,
|
||||
kHPatch_error_pat_fopen =-8,
|
||||
kHPatch_error_pat_fread =-9,
|
||||
kHPatch_error_pat_fclose =-10,
|
||||
kHPatch_error_new_fopen =-11,
|
||||
kHPatch_error_new_fwrite =-12,
|
||||
kHPatch_error_new_fclose =-13,
|
||||
kHPatch_error_old_size =-14,
|
||||
kHPatch_error_new_size =-15,
|
||||
};
|
||||
|
||||
int hpatch_getInfo_by_mem(hpatch_singleCompressedDiffInfo* out_patinfo,
|
||||
const uint8_t* pat,size_t patsize);
|
||||
|
||||
//patInfo can NULL
|
||||
int hpatch_by_mem(const uint8_t* old,size_t oldsize, uint8_t* newBuf,size_t newsize,
|
||||
const uint8_t* pat,size_t patsize,const hpatch_singleCompressedDiffInfo* patInfo);
|
||||
int hpatch_by_file(const char* oldfile, const char* newfile, const char* patchfile);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif //HDIFFPATCH_PATCH_H
|
||||
@@ -1,10 +1,7 @@
|
||||
import http from '@ohos.net.http';
|
||||
import fileIo from '@ohos.file.fs';
|
||||
import util from '@ohos.util';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { BusinessError } from '@kit.BasicServicesKit';
|
||||
import { buffer } from '@kit.ArkTS';
|
||||
import zip from '@ohos.zlib';
|
||||
import { zlib } from '@kit.BasicServicesKit';
|
||||
import { EventHub } from './EventHub';
|
||||
import { DownloadTaskParams } from './DownloadTaskParams';
|
||||
import Pushy from 'librnupdate.so';
|
||||
@@ -37,7 +34,9 @@ export class DownloadTask {
|
||||
if (stat.isDirectory()) {
|
||||
const files = await fileIo.listFile(path);
|
||||
for (const file of files) {
|
||||
if (file === '.' || file === '..') continue;
|
||||
if (file === '.' || file === '..') {
|
||||
continue;
|
||||
}
|
||||
await this.removeDirectory(`${path}/${file}`);
|
||||
}
|
||||
await fileIo.rmdir(path);
|
||||
@@ -57,7 +56,7 @@ export class DownloadTask {
|
||||
|
||||
try {
|
||||
try {
|
||||
const exists = fileIo.accessSync(params.targetFile);
|
||||
let exists = fileIo.accessSync(params.targetFile);
|
||||
if (exists) {
|
||||
await fileIo.unlink(params.targetFile);
|
||||
} else {
|
||||
@@ -65,7 +64,7 @@ export class DownloadTask {
|
||||
0,
|
||||
params.targetFile.lastIndexOf('/'),
|
||||
);
|
||||
const exists = fileIo.accessSync(targetDir);
|
||||
exists = fileIo.accessSync(targetDir);
|
||||
if (!exists) {
|
||||
await fileIo.mkdir(targetDir);
|
||||
}
|
||||
@@ -128,64 +127,12 @@ export class DownloadTask {
|
||||
});
|
||||
}
|
||||
|
||||
private async copyFile(from: string, to: string): Promise<void> {
|
||||
let reader;
|
||||
let writer;
|
||||
try {
|
||||
reader = fileIo.openSync(from, fileIo.OpenMode.READ_ONLY);
|
||||
writer = fileIo.openSync(
|
||||
to,
|
||||
fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY,
|
||||
);
|
||||
const arrayBuffer = new ArrayBuffer(4096);
|
||||
let bytesRead: number;
|
||||
do {
|
||||
bytesRead = await fileIo
|
||||
.read(reader.fd, arrayBuffer)
|
||||
.catch((err: BusinessError) => {
|
||||
throw Error(
|
||||
`Error reading file: ${err.message}, code: ${err.code}`,
|
||||
);
|
||||
});
|
||||
if (bytesRead > 0) {
|
||||
const buf = buffer.from(arrayBuffer, 0, bytesRead);
|
||||
await fileIo
|
||||
.write(writer.fd, buf.buffer, {
|
||||
offset: 0,
|
||||
length: bytesRead,
|
||||
})
|
||||
.catch((err: BusinessError) => {
|
||||
throw Error(
|
||||
`Error writing file: ${err.message}, code: ${err.code}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
} while (bytesRead > 0);
|
||||
console.info('File copied successfully');
|
||||
} catch (error) {
|
||||
console.error('Copy file failed:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
if (reader !== undefined) {
|
||||
fileIo.closeSync(reader);
|
||||
}
|
||||
if (writer !== undefined) {
|
||||
fileIo.closeSync(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async doFullPatch(params: DownloadTaskParams): Promise<void> {
|
||||
await this.downloadFile(params);
|
||||
await this.removeDirectory(params.unzipDirectory);
|
||||
await fileIo.mkdir(params.unzipDirectory);
|
||||
|
||||
try {
|
||||
await zip.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
} catch (error) {
|
||||
console.error('Unzip failed:', error);
|
||||
throw error;
|
||||
}
|
||||
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
}
|
||||
|
||||
private async processUnzippedFiles(directory: string): Promise<ZipFile> {
|
||||
@@ -193,7 +140,9 @@ export class DownloadTask {
|
||||
try {
|
||||
const files = await fileIo.listFile(directory);
|
||||
for (const file of files) {
|
||||
if (file === '.' || file === '..') continue;
|
||||
if (file === '.' || file === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const filePath = `${directory}/${file}`;
|
||||
const stat = await fileIo.stat(filePath);
|
||||
@@ -230,7 +179,7 @@ export class DownloadTask {
|
||||
let foundDiff = false;
|
||||
let foundBundlePatch = false;
|
||||
const copyList: Map<string, Array<any>> = new Map();
|
||||
await zip.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
const zipFile = await this.processUnzippedFiles(params.unzipDirectory);
|
||||
for (const entry of zipFile.entries) {
|
||||
const fn = entry.filename;
|
||||
@@ -246,7 +195,7 @@ export class DownloadTask {
|
||||
|
||||
const copies = obj.copies;
|
||||
for (const to in copies) {
|
||||
let from = copies[to];
|
||||
let from = copies[to].replace('resources/rawfile/', '');
|
||||
if (from === '') {
|
||||
from = to;
|
||||
}
|
||||
@@ -295,10 +244,6 @@ export class DownloadTask {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
if (fn !== '.DS_Store') {
|
||||
await zip.decompressFile(fn, params.unzipDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundDiff) {
|
||||
@@ -317,14 +262,20 @@ export class DownloadTask {
|
||||
|
||||
let foundDiff = false;
|
||||
let foundBundlePatch = false;
|
||||
const copyList: Map<string, Array<any>> = new Map();
|
||||
await zip.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
const zipFile = await this.processUnzippedFiles(params.unzipDirectory);
|
||||
for (const entry of zipFile.entries) {
|
||||
const fn = entry.filename;
|
||||
|
||||
if (fn === '__diff.json') {
|
||||
foundDiff = true;
|
||||
|
||||
await fileIo
|
||||
.copyDir(params.originDirectory + '/', params.unzipDirectory + '/')
|
||||
.catch(error => {
|
||||
console.error('copy error:', error);
|
||||
});
|
||||
|
||||
let jsonContent = '';
|
||||
const bufferArray = new Uint8Array(entry.content);
|
||||
for (let i = 0; i < bufferArray.length; i++) {
|
||||
@@ -332,22 +283,23 @@ export class DownloadTask {
|
||||
}
|
||||
const obj = JSON.parse(jsonContent);
|
||||
|
||||
const copies = obj.copies;
|
||||
for (const to in copies) {
|
||||
let from = copies[to];
|
||||
if (from === '') {
|
||||
from = to;
|
||||
}
|
||||
|
||||
if (!copyList.has(from)) {
|
||||
copyList.set(from, []);
|
||||
}
|
||||
|
||||
const target = copyList.get(from);
|
||||
if (target) {
|
||||
const toFile = `${params.unzipDirectory}/${to}`;
|
||||
target.push(toFile);
|
||||
}
|
||||
const { copies, deletes } = obj;
|
||||
for (const [to, from] of Object.entries(copies)) {
|
||||
await fileIo
|
||||
.copyFile(
|
||||
`${params.originDirectory}/${from}`,
|
||||
`${params.unzipDirectory}/${to}`,
|
||||
)
|
||||
.catch(error => {
|
||||
console.error('copy error:', error);
|
||||
});
|
||||
}
|
||||
for (const fileToDelete of Object.keys(deletes)) {
|
||||
await fileIo
|
||||
.unlink(`${params.unzipDirectory}/${fileToDelete}`)
|
||||
.catch(error => {
|
||||
console.error('delete error:', error);
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -389,8 +341,6 @@ export class DownloadTask {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await zip.decompressFile(entry.filename, params.unzipDirectory);
|
||||
}
|
||||
|
||||
if (!foundDiff) {
|
||||
@@ -406,27 +356,14 @@ export class DownloadTask {
|
||||
copyList: Map<string, Array<string>>,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const bundlePath = this.context.bundleCodeDir;
|
||||
const resourceManager = this.context.resourceManager;
|
||||
|
||||
const files = await fileIo.listFile(bundlePath);
|
||||
for (const file of files) {
|
||||
if (file === '.' || file === '..') continue;
|
||||
|
||||
const targets = copyList.get(file);
|
||||
if (targets) {
|
||||
let lastTarget: string | undefined;
|
||||
|
||||
for (const target of targets) {
|
||||
console.info(`Copying from resource ${file} to ${target}`);
|
||||
|
||||
if (lastTarget) {
|
||||
await this.copyFile(lastTarget, target);
|
||||
} else {
|
||||
const sourcePath = `${bundlePath}/${file}`;
|
||||
await this.copyFile(sourcePath, target);
|
||||
lastTarget = target;
|
||||
}
|
||||
}
|
||||
for (const [from, targets] of copyList.entries()) {
|
||||
const fromContent = await resourceManager.getRawFileContent(from);
|
||||
for (const target of targets) {
|
||||
const fileStream = fileIo.createStreamSync(target, 'w+');
|
||||
fileStream.writeSync(fromContent.buffer);
|
||||
fileStream.close();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -443,7 +380,9 @@ export class DownloadTask {
|
||||
try {
|
||||
const files = await fileIo.listFile(params.unzipDirectory);
|
||||
for (const file of files) {
|
||||
if (file.startsWith('.')) continue;
|
||||
if (file.startsWith('.')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const filePath = `${params.unzipDirectory}/${file}`;
|
||||
const stat = await fileIo.stat(filePath);
|
||||
|
||||
@@ -1,49 +1,44 @@
|
||||
import { HotReloadConfig, JSBundleProvider, JSBundleProviderError, JSPackagerClientConfig } from '@rnoh/react-native-openharmony';
|
||||
import fileIo from '@ohos.file.fs';
|
||||
import {
|
||||
FileJSBundle,
|
||||
HotReloadConfig,
|
||||
JSBundleProvider,
|
||||
JSBundleProviderError
|
||||
} from '@rnoh/react-native-openharmony';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import fs from '@ohos.file.fs';
|
||||
import { UpdateContext } from './UpdateContext';
|
||||
|
||||
export class PushyFileJSBundleProvider extends JSBundleProvider {
|
||||
private updateContext: UpdateContext;
|
||||
private filePath: string = ''
|
||||
private path: string = ''
|
||||
|
||||
constructor(context: common.UIAbilityContext) {
|
||||
super();
|
||||
this.updateContext = new UpdateContext(context);
|
||||
}
|
||||
getURL(): string {
|
||||
return this.updateContext.getBundleUrl().substring(1);
|
||||
this.path = this.updateContext.getBundleUrl();
|
||||
}
|
||||
|
||||
async getBundle(): Promise<ArrayBuffer> {
|
||||
getURL(): string {
|
||||
return this.path;
|
||||
}
|
||||
|
||||
async getBundle(): Promise<FileJSBundle> {
|
||||
if (!this.path) {
|
||||
throw new JSBundleProviderError({
|
||||
whatHappened: 'No pushy bundle found. using default bundle',
|
||||
howCanItBeFixed: ['']
|
||||
})
|
||||
}
|
||||
try {
|
||||
this.filePath = this.updateContext.getBundleUrl();
|
||||
const res = fileIo.accessSync(this.filePath);
|
||||
if (res) {
|
||||
const file = fileIo.openSync(this.filePath, fileIo.OpenMode.READ_ONLY);
|
||||
try {
|
||||
const stat = await fileIo.stat(this.filePath);
|
||||
const fileSize = stat.size;
|
||||
const buffer = new ArrayBuffer(fileSize);
|
||||
const bytesRead = fileIo.readSync(file.fd, buffer, {
|
||||
offset: 0,
|
||||
length: fileSize
|
||||
});
|
||||
|
||||
if (bytesRead !== fileSize) {
|
||||
throw new Error(`Failed to read entire file: read ${bytesRead} of ${fileSize} bytes`);
|
||||
}
|
||||
return buffer;
|
||||
} finally {
|
||||
fileIo.closeSync(file.fd);
|
||||
}
|
||||
await fs.access(this.path, fs.OpenMode.READ_ONLY);
|
||||
return {
|
||||
filePath: this.path
|
||||
}
|
||||
throw new Error('Update bundle not found');
|
||||
} catch (error) {
|
||||
throw new JSBundleProviderError({
|
||||
whatHappened: `Couldn't load JSBundle from ${this.filePath}`,
|
||||
whatHappened: `Couldn't load JSBundle from ${this.path}`,
|
||||
extraData: error,
|
||||
howCanItBeFixed: [`Check if a bundle exists at "${this.filePath}" on your device.`]
|
||||
howCanItBeFixed: [`Check if a bundle exists at "${this.path}" on your device.`]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +1,84 @@
|
||||
import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
|
||||
import {
|
||||
TurboModule,
|
||||
TurboModuleContext,
|
||||
} from '@rnoh/react-native-openharmony/ts';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import dataPreferences from '@ohos.data.preferences';
|
||||
import { bundleManager } from '@kit.AbilityKit';
|
||||
import abilityAccessCtrl, { Permissions } from '@ohos.abilityAccessCtrl';
|
||||
import { BusinessError } from '@ohos.base';
|
||||
import logger from './Logger';
|
||||
import { UpdateModuleImpl } from './UpdateModuleImpl';
|
||||
import { UpdateContext } from './UpdateContext';
|
||||
import { EventHub } from './EventHub';
|
||||
|
||||
const TAG = "PushyTurboModule"
|
||||
const TAG = 'PushyTurboModule';
|
||||
|
||||
export class PushyTurboModule extends TurboModule {
|
||||
mUiCtx: common.UIAbilityContext
|
||||
context: UpdateContext
|
||||
mUiCtx: common.UIAbilityContext;
|
||||
context: UpdateContext;
|
||||
|
||||
constructor(protected ctx: TurboModuleContext) {
|
||||
super(ctx);
|
||||
logger.debug(TAG, ",PushyTurboModule constructor");
|
||||
this.mUiCtx = ctx.uiAbilityContext
|
||||
this.context = new UpdateContext(this.mUiCtx)
|
||||
EventHub.getInstance().setRNInstance(ctx.rnInstance)
|
||||
logger.debug(TAG, ',PushyTurboModule constructor');
|
||||
this.mUiCtx = ctx.uiAbilityContext;
|
||||
this.context = new UpdateContext(this.mUiCtx);
|
||||
EventHub.getInstance().setRNInstance(ctx.rnInstance);
|
||||
}
|
||||
|
||||
getConstants(): Object {
|
||||
logger.debug(TAG, ',call getConstants');
|
||||
const context = this.mUiCtx;
|
||||
const preferencesManager = dataPreferences.getPreferencesSync(context, {
|
||||
name: 'update',
|
||||
});
|
||||
const isFirstTime = preferencesManager.getSync(
|
||||
'isFirstTime',
|
||||
false,
|
||||
) as boolean;
|
||||
const rolledBackVersion = preferencesManager.getSync(
|
||||
'rolledBackVersion',
|
||||
'',
|
||||
) as string;
|
||||
const uuid = preferencesManager.getSync('uuid', '') as string;
|
||||
const currentVersion = preferencesManager.getSync(
|
||||
'currentVersion',
|
||||
'',
|
||||
) as string;
|
||||
const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
|
||||
const buildTime = preferencesManager.getSync('buildTime', '') as string;
|
||||
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
|
||||
let bundleFlags =
|
||||
bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
||||
let packageVersion = '';
|
||||
try {
|
||||
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
|
||||
packageVersion = bundleInfo?.versionName || 'Unknown';
|
||||
} catch (error) {
|
||||
console.error('Failed to get bundle info:', error);
|
||||
}
|
||||
|
||||
getConstants(): Object {
|
||||
logger.debug(TAG, ",call getConstants");
|
||||
const context = this.mUiCtx;
|
||||
const preferencesManager = dataPreferences.getPreferencesSync(context,{ name: 'update' });
|
||||
const isFirstTime = preferencesManager.getSync("isFirstTime", false) as boolean;
|
||||
const rolledBackVersion = preferencesManager.getSync("rolledBackVersion", "") as string;
|
||||
const uuid = preferencesManager.getSync("uuid", "") as string;
|
||||
const currentVersion = preferencesManager.getSync("currentVersion", "") as string;
|
||||
const currentVersionInfo = this.context.getKv(`hash_${currentVersion}`);
|
||||
const buildTime = preferencesManager.getSync("buildTime", "") as string;
|
||||
const isUsingBundleUrl = this.context.getIsUsingBundleUrl();
|
||||
let bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION;
|
||||
let packageVersion = '';
|
||||
try {
|
||||
const bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleFlags);
|
||||
packageVersion = bundleInfo?.versionName || "Unknown"
|
||||
} catch (error) {
|
||||
console.error("Failed to get bundle info:", error);
|
||||
if (isFirstTime) {
|
||||
preferencesManager.deleteSync('isFirstTime');
|
||||
}
|
||||
|
||||
if (rolledBackVersion) {
|
||||
preferencesManager.deleteSync('rolledBackVersion');
|
||||
}
|
||||
|
||||
return {
|
||||
downloadRootDir: `${context.filesDir}/_update`,
|
||||
currentVersionInfo,
|
||||
packageVersion,
|
||||
currentVersion,
|
||||
buildTime,
|
||||
isUsingBundleUrl,
|
||||
isFirstTime,
|
||||
rolledBackVersion,
|
||||
uuid,
|
||||
};
|
||||
}
|
||||
|
||||
if (isFirstTime) {
|
||||
preferencesManager.deleteSync("isFirstTime");
|
||||
}
|
||||
|
||||
if (rolledBackVersion) {
|
||||
preferencesManager.deleteSync("rolledBackVersion");
|
||||
}
|
||||
|
||||
return {
|
||||
downloadRootDir: `${context.filesDir}/_update`,
|
||||
currentVersionInfo,
|
||||
packageVersion,
|
||||
currentVersion,
|
||||
buildTime,
|
||||
isUsingBundleUrl,
|
||||
isFirstTime,
|
||||
rolledBackVersion,
|
||||
uuid,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setLocalHashInfo(hash: string, info: string): boolean {
|
||||
logger.debug(TAG, ",call setLocalHashInfo");
|
||||
setLocalHashInfo(hash: string, info: string): boolean {
|
||||
logger.debug(TAG, ',call setLocalHashInfo');
|
||||
return UpdateModuleImpl.setLocalHashInfo(this.context, hash, info);
|
||||
}
|
||||
|
||||
@@ -75,51 +86,65 @@ getConstants(): Object {
|
||||
return UpdateModuleImpl.getLocalHashInfo(this.context, hash);
|
||||
}
|
||||
|
||||
async setUuid(uuid: string): Promise<boolean> {
|
||||
logger.debug(TAG, `,call setUuid`);
|
||||
return UpdateModuleImpl.setUuid(this.context,uuid);
|
||||
async setUuid(uuid: string): Promise<boolean> {
|
||||
logger.debug(TAG, ',call setUuid');
|
||||
return UpdateModuleImpl.setUuid(this.context, uuid);
|
||||
}
|
||||
|
||||
async reloadUpdate(options: { hash: string }): Promise<void> {
|
||||
logger.debug(TAG, `,call reloadUpdate`);
|
||||
logger.debug(TAG, ',call reloadUpdate');
|
||||
return UpdateModuleImpl.reloadUpdate(this.context, this.mUiCtx, options);
|
||||
}
|
||||
|
||||
async setNeedUpdate(options: { hash: string }): Promise<boolean> {
|
||||
logger.debug(TAG, `,call setNeedUpdate`);
|
||||
logger.debug(TAG, ',call setNeedUpdate');
|
||||
return UpdateModuleImpl.setNeedUpdate(this.context, options);
|
||||
}
|
||||
|
||||
async markSuccess(): Promise<boolean> {
|
||||
logger.debug(TAG, `,call markSuccess`);
|
||||
logger.debug(TAG, ',call markSuccess');
|
||||
return UpdateModuleImpl.markSuccess(this.context);
|
||||
}
|
||||
|
||||
async downloadPatchFromPpk(options: { updateUrl: string; hash: string; originHash: string }): Promise<void> {
|
||||
logger.debug(TAG, `,call downloadPatchFromPpk`);
|
||||
async downloadPatchFromPpk(options: {
|
||||
updateUrl: string;
|
||||
hash: string;
|
||||
originHash: string;
|
||||
}): Promise<void> {
|
||||
logger.debug(TAG, ',call downloadPatchFromPpk');
|
||||
return UpdateModuleImpl.downloadPatchFromPpk(this.context, options);
|
||||
}
|
||||
|
||||
async downloadPatchFromPackage(options: { updateUrl: string; hash: string }): Promise<void> {
|
||||
logger.debug(TAG, `,call downloadPatchFromPackage`);
|
||||
async downloadPatchFromPackage(options: {
|
||||
updateUrl: string;
|
||||
hash: string;
|
||||
}): Promise<void> {
|
||||
logger.debug(TAG, ',call downloadPatchFromPackage');
|
||||
return UpdateModuleImpl.downloadPatchFromPackage(this.context, options);
|
||||
}
|
||||
|
||||
async downloadFullUpdate(options: { updateUrl: string; hash: string }): Promise<void> {
|
||||
logger.debug(TAG, `,call downloadFullUpdate`);
|
||||
async downloadFullUpdate(options: {
|
||||
updateUrl: string;
|
||||
hash: string;
|
||||
}): Promise<void> {
|
||||
logger.debug(TAG, ',call downloadFullUpdate');
|
||||
return UpdateModuleImpl.downloadFullUpdate(this.context, options);
|
||||
}
|
||||
|
||||
async downloadAndInstallApk(options: { url: string; target: string; hash: string }): Promise<void> {
|
||||
logger.debug(TAG, `,call downloadAndInstallApk`);
|
||||
async downloadAndInstallApk(options: {
|
||||
url: string;
|
||||
target: string;
|
||||
hash: string;
|
||||
}): Promise<void> {
|
||||
logger.debug(TAG, ',call downloadAndInstallApk');
|
||||
return UpdateModuleImpl.downloadAndInstallApk(this.mUiCtx, options);
|
||||
}
|
||||
|
||||
addListener(eventName: string): void {
|
||||
logger.debug(TAG, `,call addListener`);
|
||||
addListener(_eventName: string): void {
|
||||
logger.debug(TAG, ',call addListener');
|
||||
}
|
||||
|
||||
removeListeners(count: number): void {
|
||||
logger.debug(TAG, `,call removeListeners`);
|
||||
removeListeners(_count: number): void {
|
||||
logger.debug(TAG, ',call removeListeners');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,10 +37,10 @@ export class UpdateContext {
|
||||
this.preferences.putSync('packageVersion', packageVersion);
|
||||
this.preferences.flush();
|
||||
} else if (storedVersion && packageVersion !== storedVersion) {
|
||||
this.cleanUp();
|
||||
this.preferences.clear();
|
||||
this.preferences.putSync('packageVersion', packageVersion);
|
||||
this.preferences.flush();
|
||||
this.cleanUp();
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to init preferences:', e);
|
||||
@@ -101,6 +101,7 @@ export class UpdateContext {
|
||||
params.hash = hash;
|
||||
params.listener = listener;
|
||||
params.targetFile = `${this.rootDir}/${hash}.ppk`;
|
||||
params.unzipDirectory = `${this.rootDir}/${hash}`;
|
||||
const downloadTask = new DownloadTask(this.context);
|
||||
await downloadTask.execute(params);
|
||||
} catch (e) {
|
||||
@@ -162,8 +163,8 @@ export class UpdateContext {
|
||||
const downloadTask = new DownloadTask(this.context);
|
||||
return await downloadTask.execute(params);
|
||||
} catch (e) {
|
||||
throw e;
|
||||
console.error('Failed to download APK patch:', e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,18 +189,11 @@ export class UpdateContext {
|
||||
}
|
||||
}
|
||||
|
||||
public static getBundleUrl(
|
||||
context: common.UIAbilityContext,
|
||||
defaultAssetsUrl?: string,
|
||||
): string {
|
||||
return new UpdateContext(context).getBundleUrl(defaultAssetsUrl);
|
||||
}
|
||||
|
||||
public getBundleUrl(defaultAssetsUrl?: string): string {
|
||||
public getBundleUrl() {
|
||||
UpdateContext.isUsingBundleUrl = true;
|
||||
const currentVersion = this.getCurrentVersion();
|
||||
if (!currentVersion) {
|
||||
return defaultAssetsUrl;
|
||||
return '';
|
||||
}
|
||||
if (!this.isFirstTime()) {
|
||||
if (!this.preferences.getSync('firstTimeOk', true)) {
|
||||
@@ -221,7 +215,7 @@ export class UpdateContext {
|
||||
version = this.rollBack();
|
||||
}
|
||||
}
|
||||
return defaultAssetsUrl;
|
||||
return '';
|
||||
}
|
||||
|
||||
getPackageVersion(): string {
|
||||
@@ -251,6 +245,7 @@ export class UpdateContext {
|
||||
if (!lastVersion) {
|
||||
this.preferences.deleteSync('currentVersion');
|
||||
} else {
|
||||
this.preferences.deleteSync('lastVersion');
|
||||
this.preferences.putSync('currentVersion', lastVersion);
|
||||
}
|
||||
this.preferences.putSync('firstTimeOk', true);
|
||||
|
||||
@@ -78,7 +78,7 @@ RCT_EXPORT_MODULE(RCTPushy);
|
||||
NSString *storedBuildTime = [defaults stringForKey:paramBuildTime];
|
||||
|
||||
// If stored versions don't exist, write current versions first
|
||||
if (!storedPackageVersion || !storedBuildTime) {
|
||||
if (!storedPackageVersion && !storedBuildTime) {
|
||||
[defaults setObject:curPackageVersion forKey:paramPackageVersion];
|
||||
[defaults setObject:curBuildTime forKey:paramBuildTime];
|
||||
storedPackageVersion = curPackageVersion;
|
||||
@@ -86,7 +86,7 @@ RCT_EXPORT_MODULE(RCTPushy);
|
||||
}
|
||||
|
||||
BOOL packageVersionChanged = ![curPackageVersion isEqualToString:storedPackageVersion];
|
||||
BOOL buildTimeChanged = ![curBuildTime isEqualToString:storedBuildTime];
|
||||
BOOL buildTimeChanged = curBuildTime && ![curBuildTime isEqualToString:storedBuildTime];
|
||||
|
||||
if (packageVersionChanged || buildTimeChanged) {
|
||||
// Clear all update data and store new versions
|
||||
@@ -304,8 +304,8 @@ RCT_EXPORT_METHOD(setNeedUpdate:(NSDictionary *)options
|
||||
if (hash.length) {
|
||||
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
||||
NSString *lastVersion = nil;
|
||||
if ([defaults objectForKey:keyPushyInfo]) {
|
||||
NSDictionary *pushyInfo = [defaults objectForKey:keyPushyInfo];
|
||||
NSDictionary *pushyInfo = [defaults objectForKey:keyPushyInfo];
|
||||
if (pushyInfo) {
|
||||
lastVersion = pushyInfo[paramCurrentVersion];
|
||||
}
|
||||
|
||||
@@ -679,4 +679,4 @@ RCT_EXPORT_METHOD(markSuccess:(RCTPromiseResolveBlock)resolve
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
@end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "10.34.0",
|
||||
"version": "10.36.0",
|
||||
"description": "react-native hot update",
|
||||
"main": "src/index",
|
||||
"scripts": {
|
||||
@@ -9,7 +9,7 @@
|
||||
"lint": "eslint \"src/*.@(ts|tsx|js|jsx)\" && tsc --noEmit",
|
||||
"submodule": "git submodule update --init --recursive",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build-lib": "bun submodule && $ANDROID_HOME/ndk/28.2.13676358/ndk-build NDK_PROJECT_PATH=android APP_BUILD_SCRIPT=android/jni/Android.mk NDK_APPLICATION_MK=android/jni/Application.mk NDK_LIBS_OUT=android/lib",
|
||||
"build:so": "bun submodule && $ANDROID_HOME/ndk/28.2.13676358/ndk-build NDK_PROJECT_PATH=android APP_BUILD_SCRIPT=android/jni/Android.mk NDK_APPLICATION_MK=android/jni/Application.mk NDK_LIBS_OUT=android/lib",
|
||||
"build:ios-debug": "cd Example/testHotUpdate && bun && detox build --configuration ios.sim.debug",
|
||||
"build:ios-release": "cd Example/testHotUpdate && bun && detox build --configuration ios.sim.release",
|
||||
"test:ios-debug": "cd Example/testHotUpdate && detox test --configuration ios.sim.debug",
|
||||
@@ -72,6 +72,5 @@
|
||||
"react-native": "0.73",
|
||||
"ts-jest": "^29.3.2",
|
||||
"typescript": "^5.6.3"
|
||||
},
|
||||
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,18 +105,17 @@ Pod::Spec.new do |s|
|
||||
|
||||
# Conditionally add Expo dependency
|
||||
if valid_expo_project
|
||||
s.public_header_files = ['ios/ImportReact.h']
|
||||
s.dependency 'ExpoModulesCore'
|
||||
end
|
||||
|
||||
s.subspec 'RCTPushy' do |ss|
|
||||
ss.source_files = ['ios/RCTPushy/**/*.{h,m,mm,c}',
|
||||
ss.source_files = ['ios/**/*.{h,m,mm,c}',
|
||||
'android/jni/hpatch.{h,c}',
|
||||
'android/jni/HDiffPatch/libHDiffPatch/HPatch/*.{h,c}',
|
||||
'android/jni/HDiffPatch/file_for_patch.{h,c}',
|
||||
'android/jni/lzma/C/LzmaDec.{h,c}',
|
||||
'android/jni/lzma/C/Lzma2Dec.{h,c}']
|
||||
ss.public_header_files = ['ios/RCTPushy/**/*.h']
|
||||
ss.public_header_files = ['ios/**/*.h']
|
||||
end
|
||||
|
||||
# Conditionally add Expo subspec and check ExpoModulesCore version
|
||||
|
||||
1
react-native.config.js
Normal file
1
react-native.config.js
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = {};
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
buildTime,
|
||||
cInfo,
|
||||
currentVersion,
|
||||
getCurrentVersionInfo,
|
||||
currentVersionInfo,
|
||||
isFirstTime,
|
||||
isRolledBack,
|
||||
packageVersion,
|
||||
@@ -110,8 +110,7 @@ export class Pushy {
|
||||
this.clientType = clientType || 'Pushy';
|
||||
this.options.server = SERVER_PRESETS[this.clientType];
|
||||
|
||||
// Initialize i18n based on clientType
|
||||
i18n.setLocale(this.clientType === 'Pushy' ? 'zh' : 'en');
|
||||
i18n.setLocale(options.locale ?? this.clientType === 'Pushy' ? 'zh' : 'en');
|
||||
|
||||
if (Platform.OS === 'ios' || Platform.OS === 'android') {
|
||||
if (!options.appKey) {
|
||||
@@ -163,7 +162,6 @@ export class Pushy {
|
||||
log(type + ' ' + message);
|
||||
await this.loggerPromise.promise;
|
||||
const { logger = noop, appKey } = this.options;
|
||||
const info = await getCurrentVersionInfo();
|
||||
const overridePackageVersion = this.options.overridePackageVersion;
|
||||
logger({
|
||||
type,
|
||||
@@ -175,7 +173,7 @@ export class Pushy {
|
||||
overridePackageVersion,
|
||||
buildTime,
|
||||
message,
|
||||
...info,
|
||||
...currentVersionInfo,
|
||||
...data,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createContext, useContext } from 'react';
|
||||
import { CheckResult, ProgressData } from './type';
|
||||
import { Pushy, Cresc } from './client';
|
||||
import i18n from './i18n';
|
||||
|
||||
const noop = () => {};
|
||||
const asyncNoop = () => Promise.resolve();
|
||||
@@ -50,7 +51,16 @@ export const UpdateContext = createContext<{
|
||||
lastError?: Error;
|
||||
}>(defaultContext);
|
||||
|
||||
export const useUpdate = () => useContext(UpdateContext);
|
||||
export const useUpdate = __DEV__ ? () => {
|
||||
const context = useContext(UpdateContext);
|
||||
|
||||
// 检查是否在 UpdateProvider 内部使用
|
||||
if (!context.client) {
|
||||
throw new Error(i18n.t('error_use_update_outside_provider'));
|
||||
}
|
||||
|
||||
return context;
|
||||
} : () => useContext(UpdateContext);
|
||||
|
||||
/** @deprecated Please use `useUpdate` instead */
|
||||
export const usePushy = useUpdate;
|
||||
|
||||
@@ -47,7 +47,7 @@ export const currentVersionInfo = _currentVersionInfo;
|
||||
|
||||
export const isFirstTime: boolean = PushyConstants.isFirstTime;
|
||||
export const rolledBackVersion: string = PushyConstants.rolledBackVersion;
|
||||
export const isRolledBack: boolean = typeof rolledBackVersion === 'string';
|
||||
export const isRolledBack: boolean = !!rolledBackVersion;
|
||||
|
||||
export const buildTime: string = PushyConstants.buildTime;
|
||||
let uuid = PushyConstants.uuid;
|
||||
|
||||
@@ -71,4 +71,8 @@ export default {
|
||||
// Development environment messages
|
||||
dev_incremental_update_disabled:
|
||||
'Currently in development environment, incremental hot update cannot be executed and restart will not take effect. If you need to test effective full hot update in development environment (but will reconnect to metro after restart), please enable "ignore timestamp" switch and retry.',
|
||||
|
||||
// Context error messages
|
||||
error_use_update_outside_provider:
|
||||
'useUpdate must be used within an UpdateProvider. Please wrap your component tree with <UpdateProvider client={...}>.',
|
||||
};
|
||||
|
||||
@@ -68,4 +68,8 @@ export default {
|
||||
// Development environment messages
|
||||
dev_incremental_update_disabled:
|
||||
'当前是开发环境,无法执行增量式热更新,重启不会生效。如果需要在开发环境中测试可生效的全量热更新(但也会在再次重启后重新连接 metro),请打开"忽略时间戳"开关再重试。',
|
||||
|
||||
// Context error messages
|
||||
error_use_update_outside_provider:
|
||||
'useUpdate 必须在 UpdateProvider 内部使用。请使用 <UpdateProvider client={...}> 包裹您的组件树。',
|
||||
};
|
||||
|
||||
@@ -13,7 +13,12 @@ import {
|
||||
Linking,
|
||||
} from 'react-native';
|
||||
import { Pushy, Cresc, sharedState } from './client';
|
||||
import { currentVersion, packageVersion, getCurrentVersionInfo, currentVersionInfo } from './core';
|
||||
import {
|
||||
currentVersion,
|
||||
packageVersion,
|
||||
getCurrentVersionInfo,
|
||||
currentVersionInfo,
|
||||
} from './core';
|
||||
import {
|
||||
CheckResult,
|
||||
ProgressData,
|
||||
@@ -165,7 +170,7 @@ export const UpdateProvider = ({
|
||||
lastChecking.current = now;
|
||||
let rootInfo: CheckResult | undefined;
|
||||
try {
|
||||
rootInfo = await client.checkUpdate(extra);
|
||||
rootInfo = { ...(await client.checkUpdate(extra)) };
|
||||
} catch (e: any) {
|
||||
setLastError(e);
|
||||
alertError(client.t('error_update_check_failed'), e.message);
|
||||
@@ -175,12 +180,14 @@ export const UpdateProvider = ({
|
||||
if (!rootInfo) {
|
||||
return;
|
||||
}
|
||||
const versions = [rootInfo.expVersion, rootInfo].filter(Boolean) as VersionInfo[];
|
||||
const versions = [rootInfo.expVersion, rootInfo].filter(
|
||||
Boolean,
|
||||
) as VersionInfo[];
|
||||
delete rootInfo.expVersion;
|
||||
for (const versionInfo of versions) {
|
||||
const info: CheckResult = {
|
||||
...versionInfo,
|
||||
...rootInfo,
|
||||
...versionInfo,
|
||||
};
|
||||
const rollout = info.config?.rollout?.[packageVersion];
|
||||
if (info.update && rollout) {
|
||||
|
||||
@@ -86,6 +86,7 @@ export interface ClientOptions {
|
||||
appKey: string;
|
||||
server?: UpdateServerConfig;
|
||||
logger?: UpdateEventsLogger;
|
||||
locale?: 'zh' | 'en';
|
||||
updateStrategy?:
|
||||
| 'alwaysAlert'
|
||||
| 'alertUpdateAndIgnoreError'
|
||||
|
||||
Reference in New Issue
Block a user