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

Compare commits

..

49 Commits

Author SHA1 Message Date
sunnylqm
4944b05378 checkUpdate now returns info 2025-03-05 20:17:06 +08:00
sunnylqm
90d1539038 update example deps 2025-03-05 17:03:21 +08:00
sunnylqm
26eacb923a bump 10.25.4 2025-03-05 16:52:39 +08:00
sunnylqm
37739940ab fix clientType 2025-03-05 16:52:13 +08:00
sunnylqm
020e4f9239 print error 2025-03-05 15:38:11 +08:00
sunnylqm
e0d4fe81fd print body for harmony 2025-03-05 11:41:20 +08:00
波仔糕
49b0c25a3d Update README.md (#481) 2025-03-04 22:05:47 +08:00
sunnylqm
10cb072fc3 improve errorUpdate message 2025-02-26 20:40:10 +08:00
sunnylqm
a432e5f1b1 Bump package version to 10.25.2 and improve linking event listener removal 2025-02-26 12:53:40 +08:00
sunnylqm
23d1fcd4d1 Bump package version to 10.25.1 2025-02-26 12:50:18 +08:00
sunnylqm
e3a748065a Fix linking event listener removal for legacy compatibility 2025-02-26 12:48:26 +08:00
sunnylqm
effd7e129d fix android reload in bridge-less mode 2025-02-25 23:22:31 +08:00
sunnylqm
9a00cf7483 Bump package version to 10.24.3 2025-02-25 19:33:43 +08:00
sunnylqm
d854082495 Clear hash info on package version update 2025-02-25 19:33:02 +08:00
sunnylqm
3073bd99db update example 2025-02-23 17:43:24 +08:00
sunnylqm
4436654769 fix class properties 2025-02-23 17:26:59 +08:00
sunnylqm
3ccc3653ac export useUpdate 2025-02-22 11:20:43 +08:00
sunnylqm
e150db486a add cresc 2025-02-21 18:41:39 +08:00
sunnylqm
66c2504718 comments 2025-02-18 22:38:09 +08:00
sunnylqm
bbda7217ac add cresc 2025-02-18 15:16:01 +08:00
sunnylqm
0b52cf35d2 bump 10.23.1 2025-02-17 23:00:39 +08:00
sunnylqm
46974ddb75 fix error 2025-02-17 23:00:16 +08:00
sunnylqm
0df6fa822b update deps 2025-02-17 13:28:47 +08:00
sunnylqm
fdb1fc304a change repo name 2025-02-16 10:45:28 +08:00
sunnylqm
39ea11a435 change repo name 2025-02-16 10:44:48 +08:00
sunnylqm
618a582e42 add svg 2025-02-15 21:26:12 +08:00
Sunny Luo
31e6b0f5f0 更新 package.json 2025-02-14 17:55:52 +08:00
波仔糕
2a96684de7 update RNOH SDK dependence from local to remote (#473)
* fix harmony more than 2M issue

* fix mtpush-react-native conflics

* update harmony remote dependency flow

* udpate

* udpate

* udpate

* udpate

* udpate

* update

* uddate

* udpapte
2025-02-14 17:55:09 +08:00
Sunny Luo
b04247b486 Update package.json 2025-02-10 14:59:07 +08:00
波仔糕
828212f5bf fix harmony more than 2M issue (#470) 2025-02-10 14:58:54 +08:00
sunnylqm
23ccfccdce update example 2025-02-02 23:29:46 +08:00
sunnylqm
6943b3634e bump version to 10.22.0 2025-02-02 22:58:47 +08:00
sunnylqm
1beb8762a7 support 0.77 2025-02-02 22:57:35 +08:00
sunny.luo
3ce7f0ff80 update example 2025-01-20 10:21:17 +08:00
Sunny Luo
bd5190331a bump v10.21.1 2025-01-15 17:37:14 +08:00
sunny.luo
64b77d1b66 fix reload 2025-01-15 17:29:39 +08:00
sunny.luo
a0adf1e778 fix platform check 2025-01-15 17:11:23 +08:00
sunny.luo
08547b7c8d use reflect 2025-01-15 17:02:29 +08:00
Sunny Luo
d355b37501 Update README.md 2025-01-13 12:29:55 +08:00
Sunny Luo
ef9b773f41 Delete harmony/README.OpenSource 2025-01-12 13:15:20 +08:00
Sunny Luo
9eba54bdd4 Delete harmony/README.md 2025-01-12 13:15:10 +08:00
Sunny Luo
3d34410488 Delete Example/react-native-harmony-cli directory 2025-01-12 12:18:40 +08:00
Sunny Luo
9b9adc5d6a Delete Example/react-native-harmony directory 2025-01-12 12:18:31 +08:00
波仔糕
964d66da74 adapter for harmony (#464)
* update hvigorfile.ts file

* change versionName get logic

* change post logic for harmony
2025-01-12 12:17:54 +08:00
Sunny Luo
261427705c Update package.json 2025-01-11 19:29:51 +08:00
sunnylqm
f71419be45 fix android reload 2025-01-11 19:22:12 +08:00
sunnylqm
eabacaa1e3 fix example 2025-01-11 17:22:32 +08:00
波仔糕
22d80890e2 update hvigorfile.ts file (#463) 2025-01-07 14:20:13 +08:00
sunny.luo
0df8261acb fix android 2024-12-26 15:27:45 +08:00
59 changed files with 1298 additions and 958 deletions

View File

@@ -1,25 +1,16 @@
## 运行harmony_use_pushy项目步骤 ## 运行harmony_use_pushy项目步骤
### 1.将项目克隆到本地后在项目根目录创建libs文件夹 ### 1. 先在react-native-update根目录执行下面命令同步C++模块
### 2.然后将[`rnoh`](https://github.com/bozaigao/rnoh)克隆到libs文件夹中。
说明rnoh项目基于react-native 0.72.5版本适配如果使用最新的RN版本可能会报错项目适配RN新版本请关注[`gitee仓库`](https://gitee.com/openharmony-sig/ohos_react_native/tree/0.72.5-ohos-5.0-release/tester/harmony/react_native_openharmony/src/main)
### 3.进入rnoh项目执行下面命令对rnoh项目依赖的C++库进行初始化;
``` ```
git submodule update --init --recursive yarn submodule
``` ```
### 4. 确保在react-native-update根目录已经执行过yarn submodule命令 ### 2. 在项目根目录执行下面命令安装第三方依赖
说明这个命令会在harmony/src/main/cpp目录生成HDiffPatch和lzma的C++模块依赖。
### 5. 在项目根目录执行下面命令安装第三方依赖。
``` ```
yarn install yarn install
``` ```
### 6. 在项目根目录执行下面命令生成bundle包文件。 ### 3. 在项目根目录执行下面命令生成bundle包文件。
``` ```
yarn build yarn build
``` ```
@@ -27,8 +18,8 @@ yarn build
**注意⚠️**在使用pushy bundle --platform harmony命令进行打包的默认bundle包名是Hbundle.harmony.js不要随意修改包名因为diff是匹配该包名进行生成的。 **注意⚠️**在使用pushy bundle --platform harmony命令进行打包的默认bundle包名是Hbundle.harmony.js不要随意修改包名因为diff是匹配该包名进行生成的。
### 7. 使用DevEco Studio IDE打开harmony目录然后执行sync运行项目 ### 4. 使用DevEco Studio IDE打开harmony目录然后执行sync运行项目
![image](./sync.png) ![image](./sync.png)
### 8 运行效果图 ### 5 运行效果图
![image](./demo.png) ![image](./demo.png)

View File

@@ -37,10 +37,6 @@
} }
] ]
}, },
{
name: 'rnoh',
srcPath: '../libs/rnoh',
},
{ {
name: 'pushy', name: 'pushy',
srcPath: '../node_modules/react-native-update/harmony', srcPath: '../node_modules/react-native-update/harmony',

View File

@@ -1,6 +1,7 @@
import { hapTasks } from '@ohos/hvigor-ohos-plugin'; import { hapTasks } from '@ohos/hvigor-ohos-plugin';
import fs from 'fs'; import fs from 'fs';
import path from 'path'; import path from 'path';
export function generatePushyBuildTime(str?: string) { export function generatePushyBuildTime(str?: string) {
return { return {
pluginId: 'PushyBuildTimePlugin', pluginId: 'PushyBuildTimePlugin',
@@ -13,11 +14,22 @@ export function generatePushyBuildTime(str?: string) {
if (!fs.existsSync(dirPath)) { if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true }); 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 buildTime = new Date().toISOString();
const metaContent = { pushy_build_time : buildTime }; const metaContent = {
pushy_build_time: buildTime,
versionName: versionName
};
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4)); fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4));
console.log(`Build time written to ${metaFilePath}`); console.log(`Build time written to ${metaFilePath}`);
}, },
dependencies: [], dependencies: [],
postDependencies: ['default@BuildJS'] postDependencies: ['default@BuildJS']

View File

@@ -5,24 +5,25 @@
"lockfileVersion": 3, "lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": { "specifiers": {
"pushy@../../node_modules/react-native-update/harmony": "pushy@../../node_modules/react-native-update/harmony", "@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38",
"rnoh@../../libs/rnoh": "rnoh@../../libs/rnoh" "pushy@../../node_modules/react-native-update/harmony": "pushy@../../node_modules/react-native-update/harmony"
}, },
"packages": { "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",
"registryType": "ohpm"
},
"pushy@../../node_modules/react-native-update/harmony": { "pushy@../../node_modules/react-native-update/harmony": {
"name": "pushy", "name": "pushy",
"version": "3.1.0-0.0.7", "version": "3.1.0-0.0.7",
"resolved": "../../node_modules/react-native-update/harmony", "resolved": "../../node_modules/react-native-update/harmony",
"registryType": "local", "registryType": "local",
"dependencies": { "dependencies": {
"rnoh": "file:../../../libs/rnoh" "@rnoh/react-native-openharmony": "^0.72.38"
} }
},
"rnoh@../../libs/rnoh": {
"name": "rnoh",
"version": "0.72.12",
"resolved": "../../libs/rnoh",
"registryType": "local"
} }
} }
} }

View File

@@ -6,7 +6,7 @@
"author": "", "author": "",
"license": "", "license": "",
"dependencies": { "dependencies": {
"rnoh": "file:../../libs/rnoh", "@rnoh/react-native-openharmony": "0.72.38",
"pushy": "file:../../node_modules/react-native-update/harmony" "pushy": "file:../../node_modules/react-native-update/harmony"
} }
} }

View File

@@ -2,12 +2,23 @@ cmake_minimum_required(VERSION 3.16)
project(rnapp) project(rnapp)
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules") set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../libs/rnoh/src/main/cpp") set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp")
set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules") set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy) set(LOG_VERBOSITY_LEVEL 1)
set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
add_compile_definitions(WITH_HITRACE_SYSTRACE)
add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy)
add_subdirectory("${RNOH_CPP_DIR}" ./rn) add_subdirectory("${RNOH_CPP_DIR}" ./rn)
file(GLOB GENERATED_CPP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/generated/*.cpp") # this line is needed by codegen v1
add_library(rnoh_app SHARED add_library(rnoh_app SHARED
${GENERATED_CPP_FILES}
"./PackageProvider.cpp" "./PackageProvider.cpp"
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp" "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
) )

View File

@@ -1,4 +1,4 @@
import type {RNPackageContext, RNPackage} from 'rnoh/ts'; import type {RNPackageContext, RNPackage} from '@rnoh/react-native-openharmony/ts';
import {PushyPackage} from 'pushy/ts'; import {PushyPackage} from 'pushy/ts';
export function createRNPackages(ctx: RNPackageContext): RNPackage[] { export function createRNPackages(ctx: RNPackageContext): RNPackage[] {

View File

@@ -1,4 +1,4 @@
import {RNAbility} from 'rnoh/ts'; import {RNAbility} from '@rnoh/react-native-openharmony';
export default class EntryAbility extends RNAbility { export default class EntryAbility extends RNAbility {
getPagePath() { getPagePath() {

View File

@@ -1,26 +1,32 @@
import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider'; import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider';
import { ComponentBuilderContext, JSBundleProvider, RNOHLogger } from 'rnoh'; import { ComponentBuilderContext, RNOHCoreContext,RNAbility } from '@rnoh/react-native-openharmony';
import { import {
RNApp, RNApp,
RNAbility,
AnyJSBundleProvider, AnyJSBundleProvider,
ResourceJSBundleProvider, ResourceJSBundleProvider,
TraceJSBundleProviderDecorator, TraceJSBundleProviderDecorator,
} from 'rnoh' } from '@rnoh/react-native-openharmony'
import { createRNPackages } from '../RNPackagesFactory' import { createRNPackages } from '../RNPackagesFactory'
import preferences from '@ohos.data.preferences';
const arkTsComponentNames: Array<string> = [];
@Builder @Builder
export function CustomComponentBuilder(ctx: ComponentBuilderContext) { export function buildCustomRNComponent(ctx: ComponentBuilderContext) {
// There seems to be a problem with the placement of ArkTS components in mixed mode. Nested Stack temporarily avoided.
Stack() {
}
.position({ x: 0, y: 0 })
} }
const wrappedCustomRNComponentBuilder = wrapBuilder(buildCustomRNComponent)
@Entry @Entry
@Component @Component
struct Index { struct Index {
@StorageLink('RNAbility') private rnAbility: RNAbility | undefined = undefined @StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
@State shouldShow: boolean = false @State shouldShow: boolean = false
@State message: string = 'Hello World';
aboutToAppear(): void { aboutToAppear(): void {
this.shouldShow = true this.shouldShow = true
@@ -30,28 +36,37 @@ struct Index {
// NOTE: this is required since `Ability`'s `onBackPressed` function always // NOTE: this is required since `Ability`'s `onBackPressed` function always
// terminates or puts the app in the background, but we want Ark to ignore it completely // terminates or puts the app in the background, but we want Ark to ignore it completely
// when handled by RN // when handled by RN
return this.rnAbility?.onBackPress(); this.rnohCoreContext!.dispatchBackPress()
// this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
return true
} }
build() { build() {
Column() { Column() {
if (this.rnAbility && this.shouldShow) { if (this.rnohCoreContext && this.shouldShow) {
RNApp({ RNApp({
rnInstanceConfig: { createRNPackages }, rnInstanceConfig: {
createRNPackages,
enableNDKTextMeasuring: true,
enableBackgroundExecutor: false,
enableCAPIArchitecture: true,
arkTsComponentNames: arkTsComponentNames,
},
initialProps: { "foo": "bar" } as Record<string, string>, initialProps: { "foo": "bar" } as Record<string, string>,
appKey: "harmony_use_pushy", appKey: "harmony_use_pushy",
buildCustomComponent: CustomComponentBuilder, wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder,
onSetUp: (rnInstance) => { onSetUp: (rnInstance) => {
rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP") rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP")
}, },
jsBundleProvider: new TraceJSBundleProviderDecorator( jsBundleProvider: new TraceJSBundleProviderDecorator(
new AnyJSBundleProvider([ new AnyJSBundleProvider([
// MetroJSBundleProvider.fromServerIp('127.0.0.1'), // MetroJSBundleProvider.fromServerIp('127.0.0.1'),
// new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'hermes_bundle.hbc'), // new ResourceJSBundleProvider(rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
new FileJSBundleProvider(this.rnAbility.context), new FileJSBundleProvider(this.rnohCoreContext.uiAbilityContext),
new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'bundle.harmony.js') new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
]), ]),
this.rnAbility.getLogger()), this.rnohCoreContext.logger),
}) })
} }
} }

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
{
"pushy_build_time": "2025-02-14T09:43:25.648Z",
"versionName": "1.0.0"
}

View File

@@ -0,0 +1,14 @@
{
"ios": {
"appId": 24794,
"appKey": "SqShg4Klnj2hG6LAFMW2PdcgSSuniz0T"
},
"android": {
"appId": 27509,
"appKey": "aQz3Uc2pA7gt_prDaQ4rbWRY"
},
"harmony": {
"appId": 29140,
"appKey": "JLklGflGIRbY-cMebjQwm1J1"
}
}

View File

@@ -13,5 +13,8 @@
"suppressImplicitAnyIndexErrors": true, "suppressImplicitAnyIndexErrors": true,
"strict": false "strict": false
} }
},
"overrides": {
"@rnoh/react-native-openharmony": "0.72.38"
} }
} }

View File

@@ -8,7 +8,7 @@
"appKey": "aQz3Uc2pA7gt_prDaQ4rbWRY" "appKey": "aQz3Uc2pA7gt_prDaQ4rbWRY"
}, },
"harmony": { "harmony": {
"appId": 29040, "appId": 29140,
"appKey": "gdzeAqAFE5Jew15c5Df8EKU9" "appKey": "JLklGflGIRbY-cMebjQwm1J1"
} }
} }

View File

@@ -6003,7 +6003,7 @@ react-is@^17.0.1:
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
"react-native-update@file:../..": "react-native-update@file:../..":
version "10.15.1" version "10.19.6"
dependencies: dependencies:
nanoid "^3.3.3" nanoid "^3.3.3"
react-native-url-polyfill "^2.0.0" react-native-url-polyfill "^2.0.0"

View File

@@ -72,8 +72,8 @@ def jscFlavor = 'org.webkit:android-jsc:+'
android { android {
ndkVersion rootProject.ext.ndkVersion ndkVersion rootProject.ext.ndkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
compileSdkVersion rootProject.ext.compileSdkVersion compileSdk rootProject.ext.compileSdkVersion
namespace "com.awesomeproject" namespace "com.awesomeproject"
defaultConfig { defaultConfig {

View File

@@ -2,12 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<application <application
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
tools:targetApi="28" tools:targetApi="28"
tools:ignore="GoogleAppIndexingWarning"> tools:ignore="GoogleAppIndexingWarning"/>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
</application>
</manifest> </manifest>

View File

@@ -1,5 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android">
package="com.awesomeproject">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.CAMERA" />

View File

@@ -1,32 +0,0 @@
package com.awesomeproject;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.defaults.DefaultReactActivityDelegate;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "AwesomeProject";
}
/**
* Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
* DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
* (aka React 18) with two boolean flags.
*/
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new DefaultReactActivityDelegate(
this,
getMainComponentName(),
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
DefaultNewArchitectureEntryPoint.getFabricEnabled());
}
}

View File

@@ -0,0 +1,22 @@
package com.awesomeproject
import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
class MainActivity : ReactActivity() {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
override fun getMainComponentName(): String = "AwesomeProject"
/**
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
*/
override fun createReactActivityDelegate(): ReactActivityDelegate =
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
}

View File

@@ -1,69 +0,0 @@
package com.awesomeproject;
import android.app.Application;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.defaults.DefaultReactNativeHost;
import com.facebook.soloader.SoLoader;
import java.util.List;
import cn.reactnative.modules.update.UpdateContext;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost =
new DefaultReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected String getJSBundleFile() {
return UpdateContext.getBundleUrl(MainApplication.this);
}
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return packages;
}
@Override
protected boolean isNewArchEnabled() {
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
}
@Override
protected Boolean isHermesEnabled() {
return BuildConfig.IS_HERMES_ENABLED;
}
@Override
protected String getJSMainModuleName() {
return "index";
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
@Override
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
DefaultNewArchitectureEntryPoint.load();
}
}
}

View File

@@ -0,0 +1,48 @@
package com.awesomeproject
import android.app.Application
import cn.reactnative.modules.update.UpdateContext
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.soloader.OpenSourceMergedSoMapping
import com.facebook.soloader.SoLoader
class MainApplication : Application(), ReactApplication {
override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getJSBundleFile(): String? = UpdateContext.getBundleUrl(this@MainApplication)
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage())
}
override fun getJSMainModuleName(): String = "index"
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}
override val reactHost: ReactHost
get() = getDefaultReactHost(applicationContext, reactNativeHost)
override fun onCreate() {
super.onCreate()
SoLoader.init(this, OpenSourceMergedSoMapping)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
}
}

View File

@@ -5,7 +5,7 @@ buildscript {
compileSdkVersion = 35 compileSdkVersion = 35
targetSdkVersion = 34 targetSdkVersion = 34
ndkVersion = "26.1.10909125" ndkVersion = "26.1.10909125"
kotlinVersion = "1.9.24" kotlinVersion = "1.9.25"
} }
repositories { repositories {
google() google()

View File

@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-all.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View File

@@ -2,6 +2,5 @@ pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") }
plugins { id("com.facebook.react.settings") } plugins { id("com.facebook.react.settings") }
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() } extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand() }
rootProject.name = 'AwesomeProject' rootProject.name = 'AwesomeProject'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app' include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin') includeBuild('../node_modules/@react-native/gradle-plugin')

561
Example/testHotUpdate/bun.lock Executable file → Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -14,41 +14,45 @@
"dev:harmony": "react-native bundle-harmony --dev" "dev:harmony": "react-native bundle-harmony --dev"
}, },
"dependencies": { "dependencies": {
"form-data": "^4.0.1", "form-data": "^4.0.2",
"patch-package": "^8.0.0", "patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0", "postinstall-postinstall": "^2.1.0",
"react": "18.3.1", "react": "18.3.1",
"react-native": "0.76.3", "react-native": "0.76.7",
"react-native-camera-kit": "^14.1.0", "react-native-camera-kit": "^14.2.0",
"react-native-paper": "^5.12.5", "react-native-paper": "^5.13.1",
"react-native-safe-area-context": "^4.14.0", "react-native-safe-area-context": "^5.3.0",
"react-native-update": "^10.17.1", "react-native-svg": "^15.11.2",
"react-native-update": "10.25.4",
"react-native-vector-icons": "^10.2.0" "react-native-vector-icons": "^10.2.0"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.26.0", "@babel/core": "^7.26.0",
"@babel/preset-env": "^7.26.0", "@babel/preset-env": "^7.26.0",
"@babel/runtime": "^7.26.0", "@babel/runtime": "^7.26.0",
"@react-native-community/cli": "15.0.0-alpha.2", "@react-native-community/cli": "15.0.1",
"@react-native-community/cli-platform-android": "15.0.0-alpha.2", "@react-native-community/cli-platform-android": "15.0.1",
"@react-native-community/cli-platform-ios": "15.0.0-alpha.2", "@react-native-community/cli-platform-ios": "15.0.1",
"@react-native/babel-preset": "0.76.3", "@react-native/babel-preset": "0.76.7",
"@react-native/eslint-config": "0.76.3", "@react-native/eslint-config": "0.76.7",
"@react-native/metro-config": "0.76.3", "@react-native/metro-config": "0.76.7",
"@react-native/typescript-config": "0.76.3", "@react-native/typescript-config": "0.76.7",
"@types/react": "^18.2.6", "@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0", "@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3", "babel-jest": "^29.6.3",
"detox": "^20.32.0",
"eslint": "^8.19.0", "eslint": "^8.19.0",
"jest": "^29.6.3", "jest": "^29.6.3",
"prettier": "2.8.8", "prettier": "2.8.8",
"react-test-renderer": "18.3.1", "react-test-renderer": "18.3.1",
"typescript": "5.7.2" "typescript": "5.8.2"
}, },
"engines": { "engines": {
"node": ">=16" "node": ">=18"
}, },
"trustedDependencies": [ "trustedDependencies": [
"detox",
"dtrace-provider",
"postinstall-postinstall" "postinstall-postinstall"
] ]
} }

View File

@@ -0,0 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-11.5 -10.23174 23 20.46348">
<title>React Logo</title>
<circle cx="0" cy="0" r="2.05" fill="#61dafb"/>
<g stroke="#61dafb" stroke-width="1" fill="none">
<ellipse rx="11" ry="4.2"/>
<ellipse rx="11" ry="4.2" transform="rotate(60)"/>
<ellipse rx="11" ry="4.2" transform="rotate(120)"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 365 B

View File

@@ -20,11 +20,12 @@ import {
Portal, Portal,
} from 'react-native-paper'; } from 'react-native-paper';
import {Camera} from 'react-native-camera-kit'; import {Camera} from 'react-native-camera-kit';
import {LocalSvg} from 'react-native-svg/css';
import TestConsole from './TestConsole'; import TestConsole from './TestConsole';
import _updateConfig from '../update.json'; import _updateConfig from '../update.json';
import {PushyProvider, Pushy, usePushy} from 'react-native-update'; import {UpdateProvider, Pushy, Cresc, useUpdate} from 'react-native-update';
const {appKey} = _updateConfig[Platform.OS]; const {appKey} = _updateConfig[Platform.OS];
function App() { function App() {
@@ -39,7 +40,7 @@ function App() {
currentHash, currentHash,
parseTestQrCode, parseTestQrCode,
progress: {received, total} = {}, progress: {received, total} = {},
} = usePushy(); } = useUpdate();
const [useDefaultAlert, setUseDefaultAlert] = useState(true); const [useDefaultAlert, setUseDefaultAlert] = useState(true);
const [showTestConsole, setShowTestConsole] = useState(false); const [showTestConsole, setShowTestConsole] = useState(false);
const [showUpdateBanner, setShowUpdateBanner] = useState(false); const [showUpdateBanner, setShowUpdateBanner] = useState(false);
@@ -91,11 +92,21 @@ function App() {
/> />
</Modal> </Modal>
</Portal> </Portal>
<View style={{flexDirection: 'row', alignItems: 'center', gap: 10}}>
<Text>png:</Text>
<Image <Image
resizeMode={'contain'} resizeMode={'contain'}
source={require('./assets/shezhi.png')} source={require('./assets/shezhi.png')}
style={styles.image} style={styles.image}
/> />
</View>
<View style={{flexDirection: 'row', alignItems: 'center', gap: 10}}>
<Text>svg:</Text>
<LocalSvg
asset={require('./assets/react-logo.svg')}
style={{width: 30, height: 30}}
/>
</View>
<Text style={styles.instructions}> <Text style={styles.instructions}>
{'\n'} {'\n'}
: {packageVersion} : {packageVersion}
@@ -192,17 +203,24 @@ const styles = StyleSheet.create({
image: {}, image: {},
}); });
const pushyClient = new Pushy({ // use Pushy for China users
// const updateClient = new Pushy({
// appKey,
// debug: true,
// });
// use Cresc for global users
const updateClient = new Cresc({
appKey, appKey,
debug: true, debug: true,
}); });
export default function Root() { export default function Root() {
return ( return (
<PushyProvider client={pushyClient}> <UpdateProvider client={updateClient}>
<PaperProvider> <PaperProvider>
<App /> <App />
</PaperProvider> </PaperProvider>
</PushyProvider> </UpdateProvider>
); );
} }

View File

@@ -2,6 +2,8 @@
本组件是面向 React Native 提供热更新功能的组件,详情请访问我们的官方网站 <https://pushy.reactnative.cn> 本组件是面向 React Native 提供热更新功能的组件,详情请访问我们的官方网站 <https://pushy.reactnative.cn>
**现已支持鸿蒙以及新架构**
### 快速开始 ### 快速开始
请查看[文档](https://pushy.reactnative.cn/docs/getting-started.html) 请查看[文档](https://pushy.reactnative.cn/docs/getting-started.html)
@@ -20,7 +22,7 @@
### 本地开发 ### 本地开发
``` ```
$ git clone git@github.com:reactnativecn/react-native-pushy.git $ git clone git@github.com:reactnativecn/react-native-update.git
$ cd react-native-pushy/Example/testHotUpdate $ cd react-native-pushy/Example/testHotUpdate
$ yarn $ yarn
$ yarn start $ yarn start
@@ -32,4 +34,4 @@ $ yarn start
本组件由[React Native 中文网](https://reactnative.cn/)独家发布,如有定制需求可以[联系我们](https://reactnative.cn/about.html#content)。 本组件由[React Native 中文网](https://reactnative.cn/)独家发布,如有定制需求可以[联系我们](https://reactnative.cn/about.html#content)。
关于此插件发现任何问题,可以前往[Issues](https://github.com/reactnativecn/react-native-pushy/issues)发帖提问。 关于此插件发现任何问题,可以前往[Issues](https://github.com/reactnativecn/react-native-update/issues)发帖提问。

View File

@@ -49,7 +49,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
private void removeDirectory(File file) throws IOException { private void removeDirectory(File file) throws IOException {
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Removing " + file); Log.d("react-native-update", "Removing " + file);
} }
if (file.isDirectory()) { if (file.isDirectory()) {
File[] files = file.listFiles(); File[] files = file.listFiles();
@@ -88,7 +88,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
BufferedSink sink = Okio.buffer(Okio.sink(writePath)); BufferedSink sink = Okio.buffer(Okio.sink(writePath));
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Downloading " + url); Log.d("react-native-update", "Downloading " + url);
} }
long bytesRead = 0; long bytesRead = 0;
@@ -98,7 +98,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
received += bytesRead; received += bytesRead;
sink.emit(); sink.emit();
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Progress " + received + "/" + contentLength); Log.d("react-native-update", "Progress " + received + "/" + contentLength);
} }
int percentage = (int)(received * 100.0 / contentLength + 0.5); int percentage = (int)(received * 100.0 / contentLength + 0.5);
@@ -115,7 +115,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
sink.close(); sink.close();
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Download finished"); Log.d("react-native-update", "Download finished");
} }
} }
@@ -244,7 +244,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Unzip finished"); Log.d("react-native-update", "Unzip finished");
} }
} }
@@ -260,7 +260,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
File lastTarget = null; File lastTarget = null;
for (File target: targets) { for (File target: targets) {
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Copying from resource " + fn + " to " + target); Log.d("react-native-update", "Copying from resource " + fn + " to " + target);
} }
if (lastTarget != null) { if (lastTarget != null) {
copyFile(lastTarget, target); copyFile(lastTarget, target);
@@ -352,7 +352,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
copyFromResource(copyList); copyFromResource(copyList);
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Unzip finished"); Log.d("react-native-update", "Unzip finished");
} }
} }
@@ -418,12 +418,12 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
throw new Error("bundle patch not found"); throw new Error("bundle patch not found");
} }
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Unzip finished"); Log.d("react-native-update", "Unzip finished");
} }
} }
private void doCleanUp(DownloadTaskParams param) throws IOException { private void doCleanUp(DownloadTaskParams param) throws IOException {
if (UpdateContext.DEBUG) { if (UpdateContext.DEBUG) {
Log.d("RNUpdate", "Start cleaning up"); Log.d("react-native-update", "Start cleaning up");
} }
File root = param.unzipDirectory; File root = param.unzipDirectory;
for (File sub : root.listFiles()) { for (File sub : root.listFiles()) {
@@ -499,7 +499,7 @@ class DownloadTask extends AsyncTask<DownloadTaskParams, long[], Void> {
default: default:
break; break;
} }
Log.e("pushy", "download task failed", e); Log.e("react-native-update", "download task failed", e);
if (params[0].listener != null) { if (params[0].listener != null) {
params[0].listener.onDownloadFailed(e); params[0].listener.onDownloadFailed(e);

View File

@@ -3,7 +3,10 @@ package cn.reactnative.modules.update;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.util.Log; import android.util.Log;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactApplication; import com.facebook.react.ReactApplication;
import com.facebook.react.ReactDelegate;
import com.facebook.react.ReactInstanceManager; import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.JSBundleLoader; import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.Promise;
@@ -12,16 +15,10 @@ import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.bridge.UiThreadUtil;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class UpdateModuleImpl { public class UpdateModuleImpl {
@@ -101,37 +98,20 @@ public class UpdateModuleImpl {
} }
}); });
}catch (Exception e){ }catch (Exception e){
promise.reject("执行报错:"+e.getMessage()); promise.reject("downloadPatchFromPpk failed: "+e.getMessage());
} }
} }
private void loadBundleLegacy(ReactApplicationContext mContext) { public static void reloadUpdate(UpdateContext updateContext, ReactApplicationContext mContext, ReadableMap options, Promise promise) {
final Activity currentActivity = mContext.getCurrentActivity();
if (currentActivity == null) {
return;
}
currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
currentActivity.recreate();
}
});
}
public static void reloadUpdate(UpdateContext updateContext, ReactApplicationContext mContext, ReadableMap options,Promise promise) {
final String hash = options.getString("hash"); final String hash = options.getString("hash");
if (hash == null || hash.isEmpty()) {
promise.reject("hash不能为空");
return;
}
UiThreadUtil.runOnUiThread(new Runnable() { UiThreadUtil.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
try {
updateContext.switchVersion(hash); updateContext.switchVersion(hash);
final Context application = mContext.getApplicationContext(); final Context application = mContext.getApplicationContext();
JSBundleLoader loader = JSBundleLoader.createFileLoader(UpdateContext.getBundleUrl(application));
try {
ReactInstanceManager instanceManager = updateContext.getCustomReactInstanceManager(); ReactInstanceManager instanceManager = updateContext.getCustomReactInstanceManager();
if (instanceManager == null) { if (instanceManager == null) {
@@ -139,12 +119,10 @@ public class UpdateModuleImpl {
} }
try { try {
JSBundleLoader loader = JSBundleLoader.createFileLoader(UpdateContext.getBundleUrl(application));
Field loadField = instanceManager.getClass().getDeclaredField("mBundleLoader"); Field loadField = instanceManager.getClass().getDeclaredField("mBundleLoader");
loadField.setAccessible(true); loadField.setAccessible(true);
loadField.set(instanceManager, loader); loadField.set(instanceManager, loader);
} catch (Throwable err) { } catch (Throwable err) {
promise.reject("pushy:"+err.getMessage());
Field jsBundleField = instanceManager.getClass().getDeclaredField("mJSBundleFile"); Field jsBundleField = instanceManager.getClass().getDeclaredField("mJSBundleFile");
jsBundleField.setAccessible(true); jsBundleField.setAccessible(true);
jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application)); jsBundleField.set(instanceManager, UpdateContext.getBundleUrl(application));
@@ -154,22 +132,53 @@ public class UpdateModuleImpl {
promise.resolve(true); promise.resolve(true);
} catch (Throwable err) { } catch (Throwable err) {
promise.reject(err); final Activity currentActivity = mContext.getCurrentActivity();
Log.e("pushy", "switchVersion failed ", err); if (currentActivity == null) {
loadBundleLegacy(mContext); return;
} }
try {
java.lang.reflect.Method getReactDelegateMethod =
ReactActivity.class.getMethod("getReactDelegate");
ReactDelegate reactDelegate = (ReactDelegate)
getReactDelegateMethod.invoke(currentActivity);
Field reactHostField = ReactDelegate.class.getDeclaredField("mReactHost");
reactHostField.setAccessible(true);
Object reactHost = reactHostField.get(reactDelegate);
// Access the mReactHostDelegate field
Field reactHostDelegateField = reactHost.getClass().getDeclaredField("mReactHostDelegate");
reactHostDelegateField.setAccessible(true);
Object reactHostDelegate = reactHostDelegateField.get(reactHost);
// Modify the jsBundleLoader field
Field jsBundleLoaderField = reactHostDelegate.getClass().getDeclaredField("jsBundleLoader");
jsBundleLoaderField.setAccessible(true);
jsBundleLoaderField.set(reactHostDelegate, loader);
// Get the reload method with a String parameter
java.lang.reflect.Method reloadMethod = reactHost.getClass().getMethod("reload", String.class);
// Invoke the reload method with a reason
reloadMethod.invoke(reactHost, "react-native-update");
} catch (Throwable e) {
currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
currentActivity.recreate();
}
});
}
}
promise.resolve(true);
} }
}); });
} }
public static void setNeedUpdate(UpdateContext updateContext, ReadableMap options,Promise promise) { public static void setNeedUpdate(UpdateContext updateContext, ReadableMap options, Promise promise) {
try {
final String hash = options.getString("hash"); final String hash = options.getString("hash");
if(hash==null || hash.isEmpty()){
promise.reject("hash不能为空");
return;
}
UiThreadUtil.runOnUiThread(new Runnable() { UiThreadUtil.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -177,18 +186,14 @@ public class UpdateModuleImpl {
updateContext.switchVersion(hash); updateContext.switchVersion(hash);
promise.resolve(true); promise.resolve(true);
} catch (Throwable err) { } catch (Throwable err) {
promise.reject("switchVersionLater failed:"+err.getMessage()); promise.reject("switchVersionLater failed: "+err.getMessage());
Log.e("pushy", "switchVersionLater failed", err); Log.e("pushy", "switchVersionLater failed", err);
} }
} }
}); });
} catch (Exception e){
promise.reject("执行报错:"+e.getMessage());
}
} }
public static void markSuccess(UpdateContext updateContext,Promise promise) { public static void markSuccess(UpdateContext updateContext, Promise promise) {
try {
UiThreadUtil.runOnUiThread(new Runnable() { UiThreadUtil.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -196,13 +201,9 @@ public class UpdateModuleImpl {
promise.resolve(true); promise.resolve(true);
} }
}); });
} catch (Exception e){
promise.reject("执行报错:"+e.getMessage());
}
} }
public static void setUuid(UpdateContext updateContext, String uuid, Promise promise) { public static void setUuid(UpdateContext updateContext, String uuid, Promise promise) {
try {
UiThreadUtil.runOnUiThread(new Runnable() { UiThreadUtil.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -210,20 +211,14 @@ public class UpdateModuleImpl {
promise.resolve(true); promise.resolve(true);
} }
}); });
} catch (Exception e){
promise.reject("执行报错:"+e.getMessage());
}
} }
public static boolean check(String json) { public static boolean check(String json) {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
try { try {
mapper.readValue(json, Map.class); mapper.readValue(json, Map.class);
System.out.println("String can be converted to Map");
return true; return true;
} catch (IOException e) { } catch (IOException e) {
System.out.println("String cannot be converted to Map");
return false; return false;
} }
} }
@@ -233,12 +228,12 @@ public class UpdateModuleImpl {
UiThreadUtil.runOnUiThread(new Runnable() { UiThreadUtil.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
if(!check(info)){ if (check(info)) {
updateContext.setKv("hash_" + hash, info);
promise.reject("校验报错:json字符串格式错误");
}else {
updateContext.setKv("hash_" + hash, info); updateContext.setKv("hash_" + hash, info);
promise.resolve(true); promise.resolve(true);
} else {
updateContext.setKv("hash_" + hash, info);
promise.reject("setLocalHashInfo failed: invalid json string");
} }
} }
}); });
@@ -249,7 +244,7 @@ public class UpdateModuleImpl {
if (check(value)) { if (check(value)) {
promise.resolve(value); promise.resolve(value);
} else { } else {
promise.reject("校验报错:json字符串格式错误"); promise.reject("getLocalHashInfo failed: invalid json string");
} }
} }

View File

@@ -9,9 +9,6 @@ import com.facebook.react.module.model.ReactModuleInfoProvider;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/**
* Created by tdzl2003 on 3/31/16.
*/
public class UpdatePackage extends TurboReactPackage { public class UpdatePackage extends TurboReactPackage {
@Nullable @Nullable
@Override @Override
@@ -25,7 +22,9 @@ public class UpdatePackage extends TurboReactPackage {
@Override @Override
public ReactModuleInfoProvider getReactModuleInfoProvider() { public ReactModuleInfoProvider getReactModuleInfoProvider() {
return () -> { return new ReactModuleInfoProvider() {
@Override
public Map<String, ReactModuleInfo> getReactModuleInfos() {
final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>(); final Map<String, ReactModuleInfo> moduleInfos = new HashMap<>();
boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; boolean isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
moduleInfos.put( moduleInfos.put(
@@ -40,6 +39,7 @@ public class UpdatePackage extends TurboReactPackage {
isTurboModule // isTurboModule isTurboModule // isTurboModule
)); ));
return moduleInfos; return moduleInfos;
}
}; };
} }
} }

1
endpoints_cresc.json Normal file
View File

@@ -0,0 +1 @@
["https://cresc-server-pthxtmvcnf.ap-southeast-1.fcapp.run"]

View File

@@ -1,11 +0,0 @@
[
{
"Name": "react-native-netinfo",
"License": "MIT License",
"License File": "https://github.com/react-native-netinfo/react-native-netinfo/blob/master/LICENSE",
"Version Number": "11.1.0",
"Owner" : "Matt Oakes <hello@mattoakes.net>"
"Upstream URL": "https://github.com/react-native-netinfo/react-native-netinfo",
"Description": "React Native Network Info API for Android, iOS, macOS, Windows & Web. It allows you to get information on:Connection typeConnection quality"
}
]

View File

@@ -5,14 +5,15 @@
"lockfileVersion": 3, "lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": { "specifiers": {
"rnoh@../../../libs/rnoh": "rnoh@../../../libs/rnoh" "@rnoh/react-native-openharmony@0.72.38": "@rnoh/react-native-openharmony@0.72.38"
}, },
"packages": { "packages": {
"rnoh@../../../libs/rnoh": { "@rnoh/react-native-openharmony@0.72.38": {
"name": "rnoh", "name": "@rnoh/react-native-openharmony",
"version": "0.72.12", "version": "0.72.38",
"resolved": "../../../libs/rnoh", "integrity": "sha512-br5SIrbB0OarSLirenleE7eTOX1lNccMJ7nb/G7qWTyJ7kW4DalmTXVKYpoT2qaOLls1uEE7McD1OjbZZM9jug==",
"registryType": "local" "resolved": "https://ohpm.openharmony.cn/ohpm/@rnoh/react-native-openharmony/-/react-native-openharmony-0.72.38.har",
"registryType": "ohpm"
} }
} }
} }

View File

@@ -7,6 +7,6 @@
"main": "index.ets", "main": "index.ets",
"version": "3.1.0-0.0.7", "version": "3.1.0-0.0.7",
"dependencies": { "dependencies": {
"rnoh": "file:../../../libs/rnoh" "@rnoh/react-native-openharmony":"^0.72.38"
} }
} }

View File

@@ -0,0 +1 @@
../../../../../harmony/oh_modules/.ohpm/@rnoh+react-native-openharmony@0.72.38/oh_modules/@rnoh/react-native-openharmony

View File

@@ -72,16 +72,18 @@ napi_value HdiffPatch(napi_env env, napi_callback_info info) {
// 创建结果buffer // 创建结果buffer
napi_value resultBuffer; napi_value resultBuffer;
uint8_t* outPtr; uint8_t* outPtr;
status = napi_create_buffer(env, newsize, (void**)&outPtr, &resultBuffer); void* data;
status = napi_create_arraybuffer(env, newsize, &data, &resultBuffer);
if (status != napi_ok) { if (status != napi_ok) {
napi_throw_error(env, NULL, "Failed to create result buffer"); napi_throw_error(env, NULL, "Failed to create result buffer");
return NULL; return NULL;
} }
outPtr = (uint8_t*)data;
// 执行patch // 执行patch
_check(kHPatch_ok==hpatch_by_mem(originPtr, originLength, outPtr, newsize, _check(kHPatch_ok==hpatch_by_mem(originPtr, originLength, outPtr, newsize,
patchPtr, patchLength, &patInfo), "hpatch"); patchPtr, patchLength, &patInfo), "hpatch");
return resultBuffer; return resultBuffer;
_clear: _clear:

View File

@@ -288,8 +288,10 @@ export class DownloadTask {
} }
} }
if(entry.filename !== '.DS_Store'){
await zip.decompressFile(entry.filename, params.unzipDirectory); await zip.decompressFile(entry.filename, params.unzipDirectory);
} }
}
if (!foundDiff) { if (!foundDiff) {
throw new Error('diff.json not found'); throw new Error('diff.json not found');

View File

@@ -1,4 +1,4 @@
import { HotReloadConfig, JSBundleProvider, JSBundleProviderError, JSPackagerClientConfig } from 'rnoh'; import { HotReloadConfig, JSBundleProvider, JSBundleProviderError, JSPackagerClientConfig } from '@rnoh/react-native-openharmony';
import fileIo from '@ohos.file.fs'; import fileIo from '@ohos.file.fs';
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import { UpdateContext } from './UpdateContext'; import { UpdateContext } from './UpdateContext';
@@ -40,20 +40,15 @@ export class FileJSBundleProvider extends JSBundleProvider {
} }
throw new Error('Update bundle not found'); throw new Error('Update bundle not found');
} catch (error) { } catch (error) {
throw new JSBundleProviderError(`Couldn't load JSBundle from ${this.filePath}`, error) throw new JSBundleProviderError({
whatHappened: `Couldn't load JSBundle from ${this.filePath}`,
extraData: error,
howCanItBeFixed: [`Check if a bundle exists at "${this.filePath}" on your device.`]
})
} }
} }
getAppKeys(): string[] { getAppKeys(): string[] {
return []; return [];
} }
getHotReloadConfig(): HotReloadConfig | null {
return null;
}
getJSPackagerClientConfig(): JSPackagerClientConfig | null {
return null;
}
} }

View File

@@ -1,5 +1,5 @@
import { RNPackage, TurboModulesFactory } from 'rnoh/ts'; import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
import type { TurboModule, TurboModuleContext } from 'rnoh/ts'; import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
import { PushyTurboModule } from './PushyTurboModule'; import { PushyTurboModule } from './PushyTurboModule';
class PushyTurboModulesFactory extends TurboModulesFactory { class PushyTurboModulesFactory extends TurboModulesFactory {

View File

@@ -1,4 +1,4 @@
import { TurboModule, TurboModuleContext } from 'rnoh/ts'; import { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import dataPreferences from '@ohos.data.preferences'; import dataPreferences from '@ohos.data.preferences';
import { bundleManager } from '@kit.AbilityKit'; import { bundleManager } from '@kit.AbilityKit';

View File

@@ -26,15 +26,15 @@ export class UpdateContext {
this.initPreferences(); this.initPreferences();
} }
private async initPreferences() { private initPreferences() {
try { try {
this.preferences = await preferences.getPreferences(this.context, 'update'); this.preferences = preferences.getPreferencesSync(this.context, {name:'update'});
const packageVersion = await this.getPackageVersion(); const packageVersion = this.getPackageVersion();
const storedVersion = await this.preferences.get('packageVersion', ''); const storedVersion = this.preferences.getSync('packageVersion', '');
if (packageVersion !== storedVersion) { if (packageVersion !== storedVersion) {
await this.preferences.clear(); this.preferences.clear();
await this.preferences.put('packageVersion', packageVersion); this.preferences.putSync('packageVersion', packageVersion);
await this.preferences.flush(); this.preferences.flush();
this.cleanUp(); this.cleanUp();
} }
} catch (e) { } catch (e) {
@@ -42,33 +42,33 @@ export class UpdateContext {
} }
} }
public async setKv(key: string, value: string): Promise<void> { public setKv(key: string, value: string): void {
await this.preferences.put(key, value); this.preferences.putSync(key, value);
await this.preferences.flush(); this.preferences.flush();
} }
public async getKv(key: string): Promise<string> { public getKv(key: string): string {
return await this.preferences.get(key, '') as string; return this.preferences.getSync(key, '') as string;
} }
public async isFirstTime(): Promise<boolean> { public isFirstTime(): boolean {
return await this.preferences.get('firstTime', false) as boolean; return this.preferences.getSync('firstTime', false) as boolean;
} }
public async rolledBackVersion(): Promise<string> { public rolledBackVersion(): string {
return await this.preferences.get('rolledBackVersion', '') as string; return this.preferences.getSync('rolledBackVersion', '') as string;
} }
public async markSuccess(): Promise<void> { public markSuccess(): void {
await this.preferences.put('firstTimeOk', true); this.preferences.putSync('firstTimeOk', true);
const lastVersion = await this.preferences.get('lastVersion', '') as string; const lastVersion = this.preferences.getSync('lastVersion', '') as string;
const curVersion = await this.preferences.get('currentVersion', '') as string; const curVersion = this.preferences.getSync('currentVersion', '') as string;
if (lastVersion && lastVersion !== curVersion) { if (lastVersion && lastVersion !== curVersion) {
await this.preferences.delete('lastVersion'); this.preferences.deleteSync('lastVersion');
await this.preferences.delete(`hash_${lastVersion}`); this.preferences.deleteSync(`hash_${lastVersion}`);
} }
await this.preferences.flush(); this.preferences.flush();
this.cleanUp(); this.cleanUp();
} }
@@ -143,23 +143,23 @@ export class UpdateContext {
} }
} }
public async switchVersion(hash: string): Promise<void> { public switchVersion(hash: string): void {
try { try {
const bundlePath = `${this.rootDir}/${hash}/bundle.harmony.js`; const bundlePath = `${this.rootDir}/${hash}/bundle.harmony.js`;
if (!fileIo.accessSync(bundlePath)) { if (!fileIo.accessSync(bundlePath)) {
throw new Error(`Bundle version ${hash} not found.`); throw new Error(`Bundle version ${hash} not found.`);
} }
const lastVersion = await this.getKv('currentVersion'); const lastVersion = this.getKv('currentVersion');
await this.setKv('currentVersion', hash); this.setKv('currentVersion', hash);
if (lastVersion && lastVersion !== hash) { if (lastVersion && lastVersion !== hash) {
await this.setKv('lastVersion', lastVersion); this.setKv('lastVersion', lastVersion);
} }
await this.setKv('firstTime', 'true'); this.setKv('firstTime', 'true');
await this.setKv('firstTimeOk', 'false'); this.setKv('firstTimeOk', 'false');
await this.setKv('rolledBackVersion', null); this.setKv('rolledBackVersion', null);
} catch (e) { } catch (e) {
console.error('Failed to switch version:', e); console.error('Failed to switch version:', e);
} }
@@ -176,7 +176,7 @@ export class UpdateContext {
return defaultAssetsUrl; return defaultAssetsUrl;
} }
if (!this.isFirstTime()) { if (!this.isFirstTime()) {
if (!this.preferences.get('firstTimeOk', true)) { if (!this.preferences.getSync('firstTimeOk', true)) {
return this.rollBack(); return this.rollBack();
} }
} }

View File

@@ -1,8 +1,5 @@
import { TurboModuleContext } from 'rnoh/ts';
import dataPreferences from '@ohos.data.preferences';
import bundleManager from '@ohos.bundle.bundleManager'; import bundleManager from '@ohos.bundle.bundleManager';
import common from '@ohos.app.ability.common'; import common from '@ohos.app.ability.common';
import { BusinessError } from '@ohos.base';
import { UpdateContext } from './UpdateContext'; import { UpdateContext } from './UpdateContext';
import { DownloadTaskParams } from './DownloadTaskParams'; import { DownloadTaskParams } from './DownloadTaskParams';
import logger from './Logger'; import logger from './Logger';

View File

@@ -78,6 +78,7 @@ RCT_EXPORT_MODULE(RCTPushy);
BOOL needClearPushyInfo = ![curPackageVersion isEqualToString:packageVersion]; BOOL needClearPushyInfo = ![curPackageVersion isEqualToString:packageVersion];
if (needClearPushyInfo) { if (needClearPushyInfo) {
[defaults setObject:nil forKey:keyPushyInfo]; [defaults setObject:nil forKey:keyPushyInfo];
[defaults setObject:nil forKey:keyHashInfo];
[defaults setObject:@(YES) forKey:KeyPackageUpdatedMarked]; [defaults setObject:@(YES) forKey:KeyPackageUpdatedMarked];
// ...need clear files later // ...need clear files later

View File

@@ -1,6 +1,6 @@
{ {
"name": "react-native-update", "name": "react-native-update",
"version": "10.19.5", "version": "10.26.0",
"description": "react-native hot update", "description": "react-native hot update",
"main": "src/index", "main": "src/index",
"scripts": { "scripts": {
@@ -26,7 +26,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/reactnativecn/react-native-pushy.git" "url": "git+https://github.com/reactnativecn/react-native-update.git"
}, },
"keywords": [ "keywords": [
"react-native", "react-native",
@@ -37,13 +37,13 @@
"author": "reactnativecn", "author": "reactnativecn",
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/reactnativecn/react-native-pushy/issues" "url": "https://github.com/reactnativecn/react-native-update/issues"
}, },
"peerDependencies": { "peerDependencies": {
"react": ">=16.8.0", "react": ">=16.8.0",
"react-native": ">=0.59.0" "react-native": ">=0.59.0"
}, },
"homepage": "https://github.com/reactnativecn/react-native-pushy#readme", "homepage": "https://github.com/reactnativecn/react-native-update#readme",
"dependencies": { "dependencies": {
"nanoid": "^3.3.3", "nanoid": "^3.3.3",
"react-native-url-polyfill": "^2.0.0" "react-native-url-polyfill": "^2.0.0"
@@ -74,6 +74,5 @@
"react-native": "0.73", "react-native": "0.73",
"ts-jest": "^29.2.5", "ts-jest": "^29.2.5",
"typescript": "^5.6.3" "typescript": "^5.6.3"
}, }
"packageManager": "yarn@1.22.21+sha1.1959a18351b811cdeedbd484a8f86c3cc3bbaf72"
} }

View File

@@ -4,6 +4,8 @@ new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
package = JSON.parse(File.read(File.join(__dir__, 'package.json'))) package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
podspec_dir = File.dirname(__FILE__)
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = package['name'] s.name = package['name']
s.version = package['version'] s.version = package['version']
@@ -16,13 +18,16 @@ Pod::Spec.new do |s|
s.cocoapods_version = '>= 1.6.0' s.cocoapods_version = '>= 1.6.0'
s.platform = :ios, "8.0" s.platform = :ios, "8.0"
s.platforms = { :ios => "11.0" } s.platforms = { :ios => "11.0" }
s.source = { :git => 'https://github.com/reactnativecn/react-native-pushy.git', :tag => '#{s.version}' } s.source = { :git => 'https://github.com/reactnativecn/react-native-update.git', :tag => '#{s.version}' }
s.source_files = "ios/**/*.{h,m,mm,swift}" s.source_files = "ios/**/*.{h,m,mm,swift}"
s.libraries = 'bz2', 'z' s.libraries = 'bz2', 'z'
s.vendored_libraries = 'RCTPushy/libRCTPushy.a' s.vendored_libraries = 'RCTPushy/libRCTPushy.a'
s.pod_target_xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"$(SRCROOT)/../node_modules/react-native-update/ios"' } s.pod_target_xcconfig = {
'USER_HEADER_SEARCH_PATHS' => "#{podspec_dir}/ios",
"DEFINES_MODULE" => "YES"
}
s.resource = 'ios/pushy_build_time.txt' s.resource = 'ios/pushy_build_time.txt'
s.script_phase = { :name => 'Generate build time', :script => 'set -x;date +%s > ${PODS_ROOT}/../../node_modules/react-native-update/ios/pushy_build_time.txt', :execution_position => :before_compile } s.script_phase = { :name => 'Generate build time', :script => "set -x;date +%s > \"#{podspec_dir}/ios/pushy_build_time.txt\"", :execution_position => :before_compile }
s.dependency 'React' s.dependency 'React'
s.dependency "React-Core" s.dependency "React-Core"
@@ -40,7 +45,7 @@ Pod::Spec.new do |s|
'android/jni/HDiffPatch/file_for_patch.{h,c}', 'android/jni/HDiffPatch/file_for_patch.{h,c}',
'android/jni/lzma/C/LzmaDec.{h,c}', 'android/jni/lzma/C/LzmaDec.{h,c}',
'android/jni/lzma/C/Lzma2Dec.{h,c}'] 'android/jni/lzma/C/Lzma2Dec.{h,c}']
ss.private_header_files = 'ios/RCTPushy/HDiffPatch/**/*.h' ss.public_header_files = 'ios/RCTPushy/HDiffPatch/**/*.h'
end end
if defined?(install_modules_dependencies()) != nil if defined?(install_modules_dependencies()) != nil

View File

@@ -1,5 +1,14 @@
import { CheckResult, PushyOptions, ProgressData, EventType } from './type'; import { CheckResult, ClientOptions, ProgressData, EventType } from './type';
import { emptyObj, joinUrls, log, noop, promiseAny, testUrls } from './utils'; import {
assertDev,
assertWeb,
emptyObj,
joinUrls,
log,
noop,
promiseAny,
testUrls,
} from './utils';
import { EmitterSubscription, Platform } from 'react-native'; import { EmitterSubscription, Platform } from 'react-native';
import { PermissionsAndroid } from './permissions'; import { PermissionsAndroid } from './permissions';
import { import {
@@ -15,31 +24,42 @@ import {
isRolledBack, isRolledBack,
} from './core'; } from './core';
const defaultServer = { const SERVER_PRESETS = {
// cn
Pushy: {
main: 'https://update.react-native.cn/api', main: 'https://update.react-native.cn/api',
backups: ['https://update.reactnative.cn/api'], backups: ['https://update.reactnative.cn/api'],
queryUrls: [ queryUrls: [
'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json', 'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json',
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-pushy@master/endpoints.json', 'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-update@master/endpoints.json',
], ],
},
// i18n
Cresc: {
main: 'https://api.cresc.dev',
backups: ['https://api.cresc.app'],
queryUrls: [
'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-update@master/endpoints_cresc.json',
],
},
}; };
if (Platform.OS === 'web') { assertWeb();
console.warn('react-native-update 不支持 web 端热更,不会执行操作');
}
export class Pushy { const defaultClientOptions: ClientOptions = {
options: PushyOptions = {
appKey: '', appKey: '',
server: defaultServer,
autoMarkSuccess: true, autoMarkSuccess: true,
updateStrategy: __DEV__ ? 'alwaysAlert' : 'alertUpdateAndIgnoreError', updateStrategy: __DEV__ ? 'alwaysAlert' : 'alertUpdateAndIgnoreError',
checkStrategy: 'both', checkStrategy: 'both',
logger: noop, logger: noop,
debug: false, debug: false,
throwError: false, throwError: false,
}; };
// for China users
export class Pushy {
options = defaultClientOptions;
clientType: 'Pushy' | 'Cresc' = 'Pushy';
lastChecking?: number; lastChecking?: number;
lastRespJson?: Promise<any>; lastRespJson?: Promise<any>;
@@ -50,7 +70,7 @@ export class Pushy {
static marked = false; static marked = false;
static applyingUpdate = false; static applyingUpdate = false;
version = cInfo.pushy; version = cInfo.rnu;
loggerPromise = (() => { loggerPromise = (() => {
let resolve: (value?: unknown) => void = () => {}; let resolve: (value?: unknown) => void = () => {};
const promise = new Promise(res => { const promise = new Promise(res => {
@@ -62,12 +82,14 @@ export class Pushy {
}; };
})(); })();
constructor(options: PushyOptions) { constructor(options: ClientOptions, clientType?: 'Pushy' | 'Cresc') {
if (Platform.OS === 'ios' || Platform.OS === 'android') { if (Platform.OS === 'ios' || Platform.OS === 'android') {
if (!options.appKey) { if (!options.appKey) {
throw new Error('appKey is required'); throw new Error('appKey is required');
} }
} }
this.clientType = clientType || 'Pushy';
this.options.server = SERVER_PRESETS[this.clientType];
this.setOptions(options); this.setOptions(options);
if (isRolledBack) { if (isRolledBack) {
this.report({ this.report({
@@ -79,7 +101,7 @@ export class Pushy {
} }
} }
setOptions = (options: Partial<PushyOptions>) => { setOptions = (options: Partial<ClientOptions>) => {
for (const [key, value] of Object.entries(options)) { for (const [key, value] of Object.entries(options)) {
if (value !== undefined) { if (value !== undefined) {
(this.options as any)[key] = value; (this.options as any)[key] = value;
@@ -124,15 +146,24 @@ export class Pushy {
return `${endpoint}/checkUpdate/${this.options.appKey}`; return `${endpoint}/checkUpdate/${this.options.appKey}`;
}; };
static assertHash = (hash: string) => { static assertHash = (hash: string) => {
if (!Pushy.downloadedHash) { if (!this.downloadedHash) {
return; return;
} }
if (hash !== Pushy.downloadedHash) { if (hash !== this.downloadedHash) {
log(`use downloaded hash ${Pushy.downloadedHash} first`); log(`use downloaded hash ${Pushy.downloadedHash} first`);
return; return;
} }
return true; return true;
}; };
assertDebug = () => {
if (__DEV__ && !this.options.debug) {
console.info(
'You are currently in the development environment and have not enabled debug mode. The hot update check will not be performed. If you need to debug hot updates in the development environment, please set debug to true in the client.',
);
return false;
}
return true;
};
markSuccess = () => { markSuccess = () => {
if (Pushy.marked || __DEV__ || !isFirstTime) { if (Pushy.marked || __DEV__ || !isFirstTime) {
return; return;
@@ -142,10 +173,7 @@ export class Pushy {
this.report({ type: 'markSuccess' }); this.report({ type: 'markSuccess' });
}; };
switchVersion = async (hash: string) => { switchVersion = async (hash: string) => {
if (__DEV__) { if (!assertDev('switchVersion()')) {
console.warn(
'您调用了switchVersion方法但是当前是开发环境不会进行任何操作。',
);
return; return;
} }
if (Pushy.assertHash(hash) && !Pushy.applyingUpdate) { if (Pushy.assertHash(hash) && !Pushy.applyingUpdate) {
@@ -156,10 +184,7 @@ export class Pushy {
}; };
switchVersionLater = async (hash: string) => { switchVersionLater = async (hash: string) => {
if (__DEV__) { if (!assertDev('switchVersionLater()')) {
console.warn(
'您调用了switchVersionLater方法但是当前是开发环境不会进行任何操作。',
);
return; return;
} }
if (Pushy.assertHash(hash)) { if (Pushy.assertHash(hash)) {
@@ -168,21 +193,17 @@ export class Pushy {
} }
}; };
checkUpdate = async (extra?: Record<string, any>) => { checkUpdate = async (extra?: Record<string, any>) => {
if (__DEV__ && !this.options.debug) { if (!this.assertDebug()) {
console.info(
'您当前处于开发环境且未启用 debug不会进行热更检查。如需在开发环境中调试热更请在 client 中设置 debug 为 true',
);
return; return;
} }
if (Platform.OS === 'web') { if (!assertWeb()) {
console.warn('web 端不支持热更新检查');
return; return;
} }
if ( if (
this.options.beforeCheckUpdate && this.options.beforeCheckUpdate &&
(await this.options.beforeCheckUpdate()) === false (await this.options.beforeCheckUpdate()) === false
) { ) {
log('beforeCheckUpdate 返回 false, 忽略检查'); log('beforeCheckUpdate returned false, skipping check');
return; return;
} }
const now = Date.now(); const now = Date.now();
@@ -205,7 +226,12 @@ export class Pushy {
// @ts-ignore // @ts-ignore
delete fetchBody.buildTime; delete fetchBody.buildTime;
} }
const body = JSON.stringify(fetchBody); const stringifyBody = JSON.stringify(fetchBody);
// harmony fetch body is not string
let body: any = fetchBody;
if (Platform.OS === 'ios' || Platform.OS === 'android') {
body = stringifyBody;
}
const fetchPayload = { const fetchPayload = {
method: 'POST', method: 'POST',
headers: { headers: {
@@ -218,13 +244,13 @@ export class Pushy {
try { try {
this.report({ this.report({
type: 'checking', type: 'checking',
message: this.options.appKey + ': ' + body, message: this.options.appKey + ': ' + stringifyBody,
}); });
resp = await fetch(this.getCheckUrl(), fetchPayload); resp = await fetch(this.getCheckUrl(), fetchPayload);
} catch (e: any) { } catch (e: any) {
this.report({ this.report({
type: 'errorChecking', type: 'errorChecking',
message: 'Can not connect to update server. Trying backup endpoints.', message: `Can not connect to update server: ${e.message}. Trying backup endpoints.`,
}); });
const backupEndpoints = await this.getBackupEndpoints(); const backupEndpoints = await this.getBackupEndpoints();
if (backupEndpoints) { if (backupEndpoints) {
@@ -306,7 +332,7 @@ export class Pushy {
this.options.beforeDownloadUpdate && this.options.beforeDownloadUpdate &&
(await this.options.beforeDownloadUpdate(info)) === false (await this.options.beforeDownloadUpdate(info)) === false
) { ) {
log('beforeDownloadUpdate 返回 false, 忽略下载'); log('beforeDownloadUpdate returned false, skipping download');
return; return;
} }
if (!info.update || !hash) { if (!info.update || !hash) {
@@ -336,6 +362,7 @@ export class Pushy {
let succeeded = ''; let succeeded = '';
this.report({ type: 'downloading' }); this.report({ type: 'downloading' });
let lastError: any; let lastError: any;
let errorMessages: string[] = [];
const diffUrl = await testUrls(joinUrls(paths, diff)); const diffUrl = await testUrls(joinUrls(paths, diff));
if (diffUrl) { if (diffUrl) {
log('downloading diff'); log('downloading diff');
@@ -347,11 +374,13 @@ export class Pushy {
}); });
succeeded = 'diff'; succeeded = 'diff';
} catch (e: any) { } catch (e: any) {
lastError = e; const errorMessage = `diff error: ${e.message}`;
errorMessages.push(errorMessage);
lastError = new Error(errorMessage);
if (__DEV__) { if (__DEV__) {
succeeded = 'diff'; succeeded = 'diff';
} else { } else {
log(`diff error: ${e.message}, try pdiff`); log(errorMessage);
} }
} }
} }
@@ -365,11 +394,13 @@ export class Pushy {
}); });
succeeded = 'pdiff'; succeeded = 'pdiff';
} catch (e: any) { } catch (e: any) {
lastError = e; const errorMessage = `pdiff error: ${e.message}`;
errorMessages.push(errorMessage);
lastError = new Error(errorMessage);
if (__DEV__) { if (__DEV__) {
succeeded = 'pdiff'; succeeded = 'pdiff';
} else { } else {
log(`pdiff error: ${e.message}, try full patch`); log(errorMessage);
} }
} }
} }
@@ -383,11 +414,13 @@ export class Pushy {
}); });
succeeded = 'full'; succeeded = 'full';
} catch (e: any) { } catch (e: any) {
lastError = e; const errorMessage = `full patch error: ${e.message}`;
errorMessages.push(errorMessage);
lastError = new Error(errorMessage);
if (__DEV__) { if (__DEV__) {
succeeded = 'full'; succeeded = 'full';
} else { } else {
log(`full patch error: ${e.message}`); log(errorMessage);
} }
} }
} }
@@ -402,6 +435,7 @@ export class Pushy {
this.report({ this.report({
type: 'errorUpdate', type: 'errorUpdate',
data: { newVersion: hash }, data: { newVersion: hash },
message: errorMessages.join(';'),
}); });
if (lastError) { if (lastError) {
throw lastError; throw lastError;
@@ -485,3 +519,10 @@ export class Pushy {
} }
}; };
} }
// for international users
export class Cresc extends Pushy {
constructor(options: ClientOptions) {
super(options, 'Cresc');
}
}

View File

@@ -1,6 +1,6 @@
import { createContext, useContext } from 'react'; import { createContext, useContext } from 'react';
import { CheckResult, ProgressData } from './type'; import { CheckResult, ProgressData } from './type';
import { Pushy } from './client'; import { Pushy, Cresc } from './client';
const noop = () => {}; const noop = () => {};
const asyncNoop = () => Promise.resolve(); const asyncNoop = () => Promise.resolve();
@@ -19,8 +19,8 @@ export const defaultContext = {
packageVersion: '', packageVersion: '',
}; };
export const PushyContext = createContext<{ export const UpdateContext = createContext<{
checkUpdate: () => Promise<void>; checkUpdate: () => Promise<void | CheckResult>;
switchVersion: () => Promise<void>; switchVersion: () => Promise<void>;
switchVersionLater: () => Promise<void>; switchVersionLater: () => Promise<void>;
markSuccess: () => void; markSuccess: () => void;
@@ -35,10 +35,14 @@ export const PushyContext = createContext<{
parseTestQrCode: (code: string) => boolean; parseTestQrCode: (code: string) => boolean;
currentHash: string; currentHash: string;
packageVersion: string; packageVersion: string;
client?: Pushy; client?: Pushy | Cresc;
progress?: ProgressData; progress?: ProgressData;
updateInfo?: CheckResult; updateInfo?: CheckResult;
lastError?: Error; lastError?: Error;
}>(defaultContext); }>(defaultContext);
export const usePushy = () => useContext(PushyContext); export const useUpdate = () => useContext(UpdateContext);
export const usePushy = useUpdate;
export const useCresc = useUpdate;

View File

@@ -13,8 +13,12 @@ export const PushyModule =
? require('./NativePushy').default ? require('./NativePushy').default
: NativeModules.Pushy; : NativeModules.Pushy;
export const UpdateModule = PushyModule;
if (!PushyModule) { if (!PushyModule) {
throw new Error('react-native-update 模块无法加载,请对照安装文档检查配置。'); throw new Error(
'Failed to load react-native-update native module, please try to recompile',
);
} }
const PushyConstants = isTurboModuleEnabled const PushyConstants = isTurboModuleEnabled
@@ -31,12 +35,6 @@ export const isRolledBack: boolean = typeof rolledBackVersion === 'string';
export const buildTime: string = PushyConstants.buildTime; export const buildTime: string = PushyConstants.buildTime;
let uuid = PushyConstants.uuid; let uuid = PushyConstants.uuid;
if (Platform.OS === 'android' && !PushyConstants.isUsingBundleUrl) {
throw new Error(
'react-native-update 模块无法加载,请对照文档检查 Bundle URL 的配置',
);
}
export function setLocalHashInfo(hash: string, info: Record<string, any>) { export function setLocalHashInfo(hash: string, info: Record<string, any>) {
PushyModule.setLocalHashInfo(hash, JSON.stringify(info)); PushyModule.setLocalHashInfo(hash, JSON.stringify(info));
} }
@@ -63,7 +61,7 @@ if (!uuid) {
log('uuid: ' + uuid); log('uuid: ' + uuid);
export const cInfo = { export const cInfo = {
pushy: require('../package.json').version, rnu: require('../package.json').version,
rn: RNVersion, rn: RNVersion,
os: Platform.OS + ' ' + Platform.Version, os: Platform.OS + ' ' + Platform.Version,
uuid, uuid,

View File

@@ -1,4 +1,4 @@
export { Pushy } from './client'; export { Pushy, Cresc } from './client';
export { PushyContext, usePushy } from './context'; export { UpdateContext, usePushy, useCresc, useUpdate } from './context';
export { PushyProvider } from './provider'; export { PushyProvider, UpdateProvider } from './provider';
export { PushyModule } from './core'; export { PushyModule, UpdateModule } from './core';

View File

@@ -12,22 +12,24 @@ import {
Platform, Platform,
Linking, Linking,
} from 'react-native'; } from 'react-native';
import { Pushy } from './client'; import { Pushy, Cresc } from './client';
import { currentVersion, packageVersion, getCurrentVersionInfo } from './core'; import { currentVersion, packageVersion, getCurrentVersionInfo } from './core';
import { CheckResult, ProgressData, PushyTestPayload } from './type'; import { CheckResult, ProgressData, UpdateTestPayload } from './type';
import { PushyContext } from './context'; import { UpdateContext } from './context';
import { URL } from 'react-native-url-polyfill'; import { URL } from 'react-native-url-polyfill';
import { isInRollout } from './isInRollout'; import { isInRollout } from './isInRollout';
import { log } from './utils'; import { log } from './utils';
export const PushyProvider = ({ export const UpdateProvider = ({
client, client,
children, children,
}: { }: {
client: Pushy; client: Pushy | Cresc;
children: ReactNode; children: ReactNode;
}) => { }) => {
client = useRef(client).current;
const { options } = client; const { options } = client;
const stateListener = useRef<NativeEventSubscription>(); const stateListener = useRef<NativeEventSubscription>();
const [updateInfo, setUpdateInfo] = useState<CheckResult>(); const [updateInfo, setUpdateInfo] = useState<CheckResult>();
const updateInfoRef = useRef(updateInfo); const updateInfoRef = useRef(updateInfo);
@@ -186,7 +188,7 @@ export const PushyProvider = ({
} else { } else {
Linking.openURL(downloadUrl); Linking.openURL(downloadUrl);
} }
return; return info;
} }
alertUpdate('提示', '您的应用版本已更新,点击更新下载安装新版本', [ alertUpdate('提示', '您的应用版本已更新,点击更新下载安装新版本', [
{ {
@@ -207,7 +209,7 @@ export const PushyProvider = ({
options.updateStrategy === 'silentAndLater' options.updateStrategy === 'silentAndLater'
) { ) {
downloadUpdate(info); downloadUpdate(info);
return; return info;
} }
alertUpdate( alertUpdate(
'提示', '提示',
@@ -224,6 +226,7 @@ export const PushyProvider = ({
], ],
); );
} }
return info;
}, },
[ [
client, client,
@@ -239,10 +242,7 @@ export const PushyProvider = ({
const markSuccess = client.markSuccess; const markSuccess = client.markSuccess;
useEffect(() => { useEffect(() => {
if (__DEV__ && !options.debug) { if (!client.assertDebug()) {
console.info(
'您当前处于开发环境且未启用debug不会进行热更检查。如需在开发环境中调试热更请在client中设置debug为true',
);
return; return;
} }
const { checkStrategy, dismissErrorAfter, autoMarkSuccess } = options; const { checkStrategy, dismissErrorAfter, autoMarkSuccess } = options;
@@ -272,11 +272,11 @@ export const PushyProvider = ({
stateListener.current && stateListener.current.remove(); stateListener.current && stateListener.current.remove();
clearTimeout(dismissErrorTimer); clearTimeout(dismissErrorTimer);
}; };
}, [checkUpdate, options, dismissError, markSuccess]); }, [checkUpdate, options, dismissError, markSuccess, client]);
const parseTestPayload = useCallback( const parseTestPayload = useCallback(
(payload: PushyTestPayload) => { (payload: UpdateTestPayload) => {
if (payload && payload.type && payload.type.startsWith('__rnPushy')) { if (payload && payload.type && payload.type.startsWith('__rnUpdate')) {
const logger = options.logger || (() => {}); const logger = options.logger || (() => {});
options.logger = ({ type, data }) => { options.logger = ({ type, data }) => {
logger({ type, data }); logger({ type, data });
@@ -286,8 +286,8 @@ export const PushyProvider = ({
checkUpdate({ extra: { toHash: payload.data } }).then(() => { checkUpdate({ extra: { toHash: payload.data } }).then(() => {
if (updateInfoRef.current && updateInfoRef.current.upToDate) { if (updateInfoRef.current && updateInfoRef.current.upToDate) {
Alert.alert( Alert.alert(
'提示', 'Info',
'当前尚未检测到更新版本如果是首次扫码请等待服务器端生成补丁包后再试约10秒', 'No update found, please wait 10s for the server to generate the patch package',
); );
} }
options.logger = logger; options.logger = logger;
@@ -301,7 +301,7 @@ export const PushyProvider = ({
); );
const parseTestQrCode = useCallback( const parseTestQrCode = useCallback(
(code: string | PushyTestPayload) => { (code: string | UpdateTestPayload) => {
try { try {
const payload = typeof code === 'string' ? JSON.parse(code) : code; const payload = typeof code === 'string' ? JSON.parse(code) : code;
return parseTestPayload(payload); return parseTestPayload(payload);
@@ -326,16 +326,21 @@ export const PushyProvider = ({
}; };
Linking.getInitialURL().then(parseLinking); Linking.getInitialURL().then(parseLinking);
const linkingListener = Linking.addEventListener('url', ({ url }) => const linkingHandler = ({ url }: { url: string }) => {
parseLinking(url), parseLinking(url);
); };
const linkingListener = Linking.addEventListener('url', linkingHandler);
return () => { return () => {
if ('removeEventListener' in Linking) {
(Linking as any).removeEventListener('url', linkingHandler);
} else {
linkingListener.remove(); linkingListener.remove();
}
}; };
}, [parseTestPayload]); }, [parseTestPayload]);
return ( return (
<PushyContext.Provider <UpdateContext.Provider
value={{ value={{
checkUpdate, checkUpdate,
switchVersion, switchVersion,
@@ -354,6 +359,8 @@ export const PushyProvider = ({
parseTestQrCode, parseTestQrCode,
}}> }}>
{children} {children}
</PushyContext.Provider> </UpdateContext.Provider>
); );
}; };
export const PushyProvider = UpdateProvider;

View File

@@ -44,7 +44,7 @@ export type EventType =
export interface EventData { export interface EventData {
currentVersion: string; currentVersion: string;
cInfo: { cInfo: {
pushy: string; rnu: string;
rn: string; rn: string;
os: string; os: string;
uuid: string; uuid: string;
@@ -65,15 +65,15 @@ export type UpdateEventsLogger = ({
data: EventData; data: EventData;
}) => void; }) => void;
export interface PushyServerConfig { export interface UpdateServerConfig {
main: string; main: string;
backups?: string[]; backups?: string[];
queryUrls?: string[]; queryUrls?: string[];
} }
export interface PushyOptions { export interface ClientOptions {
appKey: string; appKey: string;
server?: PushyServerConfig; server?: UpdateServerConfig;
logger?: UpdateEventsLogger; logger?: UpdateEventsLogger;
updateStrategy?: updateStrategy?:
| 'alwaysAlert' | 'alwaysAlert'
@@ -90,7 +90,7 @@ export interface PushyOptions {
beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean>; beforeDownloadUpdate?: (info: CheckResult) => Promise<boolean>;
} }
export interface PushyTestPayload { export interface UpdateTestPayload {
type: '__rnPushyVersionHash' | string | null; type: '__rnPushyVersionHash' | string | null;
data: any; data: any;
} }

View File

@@ -1,7 +1,7 @@
import { Platform } from 'react-native'; import { Platform } from 'react-native';
export function log(...args: any[]) { export function log(...args: any[]) {
console.log('pushy: ', ...args); console.log('react-native-update: ', ...args);
} }
export function promiseAny<T>(promises: Promise<T>[]) { export function promiseAny<T>(promises: Promise<T>[]) {
@@ -84,3 +84,23 @@ export const testUrls = async (urls?: string[]) => {
log('all ping failed, use first url:', urls[0]); log('all ping failed, use first url:', urls[0]);
return urls[0]; return urls[0];
}; };
export const assertWeb = () => {
if (Platform.OS === 'web') {
console.warn(
'react-native-update does not support the Web platform and will not perform any operations',
);
return false;
}
return true;
};
export const assertDev = (matter: string) => {
if (__DEV__) {
console.warn(
`${matter} is not supported in development environment; no action taken.`,
);
return false;
}
return true;
};