From 822602add98e8c3b74935ddffd279b700624dafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B3=A2=E4=BB=94=E7=B3=95?= Date: Thu, 26 Dec 2024 12:11:52 +0800 Subject: [PATCH] =?UTF-8?q?react-native-pushy=E9=80=82=E9=85=8Dharmony=20?= =?UTF-8?q?=20(#461)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * init * update * udpate * update * update * update * add pushy build time logic --- .gitignore | 1 + .gitmodules | 6 + Example/harmony_use_pushy/.bundle/config | 2 + Example/harmony_use_pushy/.eslintrc.js | 4 + Example/harmony_use_pushy/.prettierrc.js | 7 + Example/harmony_use_pushy/.watchmanconfig | 1 + Example/harmony_use_pushy/App.tsx | 221 + Example/harmony_use_pushy/Gemfile | 6 + Example/harmony_use_pushy/README.md | 34 + Example/harmony_use_pushy/TestConsole.js | 274 + .../harmony_use_pushy/__tests__/App.test.tsx | 17 + .../android/app/build.gradle | 123 + .../android/app/debug.keystore | Bin 0 -> 2257 bytes .../android/app/proguard-rules.pro | 10 + .../android/app/src/debug/AndroidManifest.xml | 13 + .../harmony_use_pushy/ReactNativeFlipper.java | 75 + .../android/app/src/main/AndroidManifest.xml | 25 + .../com/harmony_use_pushy/MainActivity.java | 32 + .../harmony_use_pushy/MainApplication.java | 62 + .../res/drawable/rn_edit_text_material.xml | 36 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 9 + .../harmony_use_pushy/ReactNativeFlipper.java | 20 + .../harmony_use_pushy/android/build.gradle | 21 + .../android/gradle.properties | 44 + .../android/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 61574 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + Example/harmony_use_pushy/android/gradlew | 244 + Example/harmony_use_pushy/android/gradlew.bat | 92 + .../harmony_use_pushy/android/settings.gradle | 4 + Example/harmony_use_pushy/app.json | 4 + Example/harmony_use_pushy/assets/shezhi.png | Bin 0 -> 696 bytes .../harmony_use_pushy/assets/shezhi@2x.png | Bin 0 -> 1257 bytes .../harmony_use_pushy/assets/shezhi@3x.png | Bin 0 -> 1859 bytes Example/harmony_use_pushy/assets/shoucang.png | Bin 0 -> 521 bytes .../harmony_use_pushy/assets/shoucang@2x.png | Bin 0 -> 928 bytes .../harmony_use_pushy/assets/shoucang@3x.png | Bin 0 -> 1320 bytes Example/harmony_use_pushy/babel.config.js | 3 + Example/harmony_use_pushy/demo.png | Bin 0 -> 345010 bytes Example/harmony_use_pushy/harmony/.gitignore | 12 + .../harmony/AppScope/app.json5 | 10 + .../resources/base/element/string.json | 8 + .../resources/base/media/app_icon.png | Bin 0 -> 2777 bytes .../harmony/build-profile.json5 | 49 + .../harmony/code-linter.json5 | 20 + .../harmony/entry/.gitignore | 6 + .../harmony/entry/build-profile.json5 | 33 + .../harmony/entry/hvigorfile.ts | 32 + .../harmony/entry/obfuscation-rules.txt | 23 + .../harmony/entry/oh-package-lock.json5 | 28 + .../harmony/entry/oh-package.json5 | 13 + .../harmony/entry/src/main/cpp/.gitignore | 1 + .../harmony/entry/src/main/cpp/CMakeLists.txt | 15 + .../entry/src/main/cpp/PackageProvider.cpp | 9 + .../entry/src/main/ets/RNPackagesFactory.ts | 6 + .../main/ets/entryability/EntryAbility.ets | 11 + .../entrybackupability/EntryBackupAbility.ets | 12 + .../entry/src/main/ets/pages/Index.ets | 61 + .../harmony/entry/src/main/module.json5 | 71 + .../main/resources/base/element/color.json | 8 + .../main/resources/base/element/string.json | 28 + .../main/resources/base/media/background.png | Bin 0 -> 57364 bytes .../main/resources/base/media/foreground.png | Bin 0 -> 12430 bytes .../resources/base/media/layered_image.json | 7 + .../main/resources/base/media/startIcon.png | Bin 0 -> 20093 bytes .../resources/base/profile/backup_config.json | 3 + .../resources/base/profile/main_pages.json | 5 + .../main/resources/en_US/element/string.json | 16 + .../rawfile/assets/assets/shezhi.png | Bin 0 -> 1859 bytes .../main/resources/rawfile/bundle.harmony.js | 459 + .../main/resources/zh_CN/element/string.json | 16 + .../harmony/entry/src/mock/mock-config.json5 | 2 + .../src/ohosTest/ets/test/Ability.test.ets | 35 + .../entry/src/ohosTest/ets/test/List.test.ets | 5 + .../harmony/entry/src/ohosTest/module.json5 | 13 + .../harmony/entry/src/test/List.test.ets | 5 + .../harmony/entry/src/test/LocalUnit.test.ets | 33 + .../harmony/hvigor/hvigor-config.json5 | 22 + .../harmony_use_pushy/harmony/hvigorfile.ts | 6 + .../harmony/oh-package-lock.json5 | 27 + .../harmony/oh-package.json5 | 17 + Example/harmony_use_pushy/index.js | 9 + Example/harmony_use_pushy/ios/.xcode.env | 11 + Example/harmony_use_pushy/ios/Podfile | 62 + .../project.pbxproj | 702 + .../xcschemes/harmony_use_pushy.xcscheme | 88 + .../ios/harmony_use_pushy/AppDelegate.h | 6 + .../ios/harmony_use_pushy/AppDelegate.mm | 26 + .../AppIcon.appiconset/Contents.json | 53 + .../Images.xcassets/Contents.json | 6 + .../ios/harmony_use_pushy/Info.plist | 55 + .../harmony_use_pushy/LaunchScreen.storyboard | 47 + .../ios/harmony_use_pushy/main.m | 10 + .../ios/harmony_use_pushyTests/Info.plist | 24 + .../harmony_use_pushyTests.m | 66 + Example/harmony_use_pushy/jest.config.js | 3 + Example/harmony_use_pushy/metro.config.js | 24 + Example/harmony_use_pushy/package-lock.json | 12423 ++++++++++++++++ Example/harmony_use_pushy/package.json | 42 + Example/harmony_use_pushy/sync.png | Bin 0 -> 153097 bytes Example/harmony_use_pushy/tsconfig.json | 3 + Example/harmony_use_pushy/update.json | 14 + Example/harmony_use_pushy/yarn.lock | 7245 +++++++++ bun.lockb | Bin harmony/BuildProfile.ets | 17 + harmony/OAT.xml | 38 + harmony/README.OpenSource | 11 + harmony/README.md | 0 harmony/build-profile.json5 | 8 + harmony/hvigorfile.ts | 1 + harmony/index.ets | 2 + harmony/oh-package-lock.json5 | 18 + harmony/oh-package.json5 | 12 + harmony/src/main/cpp/CMakeLists.txt | 36 + harmony/src/main/cpp/HDiffPatch | 1 + harmony/src/main/cpp/PushyPackage.h | 55 + harmony/src/main/cpp/PushyTurboModule.cpp | 142 + harmony/src/main/cpp/PushyTurboModule.h | 38 + harmony/src/main/cpp/hpatch.c | 137 + harmony/src/main/cpp/hpatch.h | 44 + harmony/src/main/cpp/lzma | 1 + harmony/src/main/cpp/pushy.c | 115 + harmony/src/main/cpp/pushy.h | 8 + harmony/src/main/ets/DownloadTask.ts | 492 + harmony/src/main/ets/DownloadTaskParams.ts | 25 + harmony/src/main/ets/EventHub.ts | 38 + harmony/src/main/ets/FileJSBundleProvider.ets | 59 + harmony/src/main/ets/Logger.ts | 35 + harmony/src/main/ets/PushyPackage.ts | 22 + harmony/src/main/ets/PushyTurboModule.ts | 123 + harmony/src/main/ets/UpdateContext.ts | 251 + harmony/src/main/ets/UpdateModuleImpl.ts | 200 + harmony/src/main/module.json5 | 7 + .../main/resources/base/element/string.json | 8 + .../main/resources/en_US/element/string.json | 8 + .../main/resources/zh_CN/element/string.json | 8 + harmony/ts.ts | 3 + ios/RCTPushy/RCTPushy.mm | 2 +- package.json | 2 +- src/index.ts | 1 + yarn.lock | 2 +- 151 files changed, 25412 insertions(+), 3 deletions(-) create mode 100644 Example/harmony_use_pushy/.bundle/config create mode 100644 Example/harmony_use_pushy/.eslintrc.js create mode 100644 Example/harmony_use_pushy/.prettierrc.js create mode 100644 Example/harmony_use_pushy/.watchmanconfig create mode 100644 Example/harmony_use_pushy/App.tsx create mode 100644 Example/harmony_use_pushy/Gemfile create mode 100644 Example/harmony_use_pushy/README.md create mode 100644 Example/harmony_use_pushy/TestConsole.js create mode 100644 Example/harmony_use_pushy/__tests__/App.test.tsx create mode 100644 Example/harmony_use_pushy/android/app/build.gradle create mode 100644 Example/harmony_use_pushy/android/app/debug.keystore create mode 100644 Example/harmony_use_pushy/android/app/proguard-rules.pro create mode 100644 Example/harmony_use_pushy/android/app/src/debug/AndroidManifest.xml create mode 100644 Example/harmony_use_pushy/android/app/src/debug/java/com/harmony_use_pushy/ReactNativeFlipper.java create mode 100644 Example/harmony_use_pushy/android/app/src/main/AndroidManifest.xml create mode 100644 Example/harmony_use_pushy/android/app/src/main/java/com/harmony_use_pushy/MainActivity.java create mode 100644 Example/harmony_use_pushy/android/app/src/main/java/com/harmony_use_pushy/MainApplication.java create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/drawable/rn_edit_text_material.xml create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/values/strings.xml create mode 100644 Example/harmony_use_pushy/android/app/src/main/res/values/styles.xml create mode 100644 Example/harmony_use_pushy/android/app/src/release/java/com/harmony_use_pushy/ReactNativeFlipper.java create mode 100644 Example/harmony_use_pushy/android/build.gradle create mode 100644 Example/harmony_use_pushy/android/gradle.properties create mode 100644 Example/harmony_use_pushy/android/gradle/wrapper/gradle-wrapper.jar create mode 100644 Example/harmony_use_pushy/android/gradle/wrapper/gradle-wrapper.properties create mode 100755 Example/harmony_use_pushy/android/gradlew create mode 100644 Example/harmony_use_pushy/android/gradlew.bat create mode 100644 Example/harmony_use_pushy/android/settings.gradle create mode 100644 Example/harmony_use_pushy/app.json create mode 100644 Example/harmony_use_pushy/assets/shezhi.png create mode 100644 Example/harmony_use_pushy/assets/shezhi@2x.png create mode 100644 Example/harmony_use_pushy/assets/shezhi@3x.png create mode 100644 Example/harmony_use_pushy/assets/shoucang.png create mode 100644 Example/harmony_use_pushy/assets/shoucang@2x.png create mode 100644 Example/harmony_use_pushy/assets/shoucang@3x.png create mode 100644 Example/harmony_use_pushy/babel.config.js create mode 100644 Example/harmony_use_pushy/demo.png create mode 100644 Example/harmony_use_pushy/harmony/.gitignore create mode 100644 Example/harmony_use_pushy/harmony/AppScope/app.json5 create mode 100644 Example/harmony_use_pushy/harmony/AppScope/resources/base/element/string.json create mode 100644 Example/harmony_use_pushy/harmony/AppScope/resources/base/media/app_icon.png create mode 100644 Example/harmony_use_pushy/harmony/build-profile.json5 create mode 100644 Example/harmony_use_pushy/harmony/code-linter.json5 create mode 100644 Example/harmony_use_pushy/harmony/entry/.gitignore create mode 100644 Example/harmony_use_pushy/harmony/entry/build-profile.json5 create mode 100644 Example/harmony_use_pushy/harmony/entry/hvigorfile.ts create mode 100644 Example/harmony_use_pushy/harmony/entry/obfuscation-rules.txt create mode 100644 Example/harmony_use_pushy/harmony/entry/oh-package-lock.json5 create mode 100644 Example/harmony_use_pushy/harmony/entry/oh-package.json5 create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/cpp/.gitignore create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/cpp/CMakeLists.txt create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/cpp/PackageProvider.cpp create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/ets/RNPackagesFactory.ts create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/ets/entryability/EntryAbility.ets create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/ets/entrybackupability/EntryBackupAbility.ets create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/ets/pages/Index.ets create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/module.json5 create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/base/element/color.json create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/base/element/string.json create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/base/media/background.png create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/base/media/foreground.png create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/base/media/layered_image.json create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/base/media/startIcon.png create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/base/profile/backup_config.json create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/base/profile/main_pages.json create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/en_US/element/string.json create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/rawfile/assets/assets/shezhi.png create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/rawfile/bundle.harmony.js create mode 100644 Example/harmony_use_pushy/harmony/entry/src/main/resources/zh_CN/element/string.json create mode 100644 Example/harmony_use_pushy/harmony/entry/src/mock/mock-config.json5 create mode 100644 Example/harmony_use_pushy/harmony/entry/src/ohosTest/ets/test/Ability.test.ets create mode 100644 Example/harmony_use_pushy/harmony/entry/src/ohosTest/ets/test/List.test.ets create mode 100644 Example/harmony_use_pushy/harmony/entry/src/ohosTest/module.json5 create mode 100644 Example/harmony_use_pushy/harmony/entry/src/test/List.test.ets create mode 100644 Example/harmony_use_pushy/harmony/entry/src/test/LocalUnit.test.ets create mode 100644 Example/harmony_use_pushy/harmony/hvigor/hvigor-config.json5 create mode 100644 Example/harmony_use_pushy/harmony/hvigorfile.ts create mode 100644 Example/harmony_use_pushy/harmony/oh-package-lock.json5 create mode 100644 Example/harmony_use_pushy/harmony/oh-package.json5 create mode 100644 Example/harmony_use_pushy/index.js create mode 100644 Example/harmony_use_pushy/ios/.xcode.env create mode 100644 Example/harmony_use_pushy/ios/Podfile create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushy.xcodeproj/project.pbxproj create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushy.xcodeproj/xcshareddata/xcschemes/harmony_use_pushy.xcscheme create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushy/AppDelegate.h create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushy/AppDelegate.mm create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushy/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushy/Images.xcassets/Contents.json create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushy/Info.plist create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushy/LaunchScreen.storyboard create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushy/main.m create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushyTests/Info.plist create mode 100644 Example/harmony_use_pushy/ios/harmony_use_pushyTests/harmony_use_pushyTests.m create mode 100644 Example/harmony_use_pushy/jest.config.js create mode 100644 Example/harmony_use_pushy/metro.config.js create mode 100644 Example/harmony_use_pushy/package-lock.json create mode 100644 Example/harmony_use_pushy/package.json create mode 100644 Example/harmony_use_pushy/sync.png create mode 100644 Example/harmony_use_pushy/tsconfig.json create mode 100644 Example/harmony_use_pushy/update.json create mode 100644 Example/harmony_use_pushy/yarn.lock mode change 100755 => 100644 bun.lockb create mode 100644 harmony/BuildProfile.ets create mode 100644 harmony/OAT.xml create mode 100644 harmony/README.OpenSource create mode 100644 harmony/README.md create mode 100644 harmony/build-profile.json5 create mode 100644 harmony/hvigorfile.ts create mode 100644 harmony/index.ets create mode 100644 harmony/oh-package-lock.json5 create mode 100644 harmony/oh-package.json5 create mode 100644 harmony/src/main/cpp/CMakeLists.txt create mode 160000 harmony/src/main/cpp/HDiffPatch create mode 100644 harmony/src/main/cpp/PushyPackage.h create mode 100644 harmony/src/main/cpp/PushyTurboModule.cpp create mode 100644 harmony/src/main/cpp/PushyTurboModule.h create mode 100644 harmony/src/main/cpp/hpatch.c create mode 100644 harmony/src/main/cpp/hpatch.h create mode 160000 harmony/src/main/cpp/lzma create mode 100644 harmony/src/main/cpp/pushy.c create mode 100644 harmony/src/main/cpp/pushy.h create mode 100644 harmony/src/main/ets/DownloadTask.ts create mode 100644 harmony/src/main/ets/DownloadTaskParams.ts create mode 100644 harmony/src/main/ets/EventHub.ts create mode 100644 harmony/src/main/ets/FileJSBundleProvider.ets create mode 100644 harmony/src/main/ets/Logger.ts create mode 100644 harmony/src/main/ets/PushyPackage.ts create mode 100644 harmony/src/main/ets/PushyTurboModule.ts create mode 100644 harmony/src/main/ets/UpdateContext.ts create mode 100644 harmony/src/main/ets/UpdateModuleImpl.ts create mode 100644 harmony/src/main/module.json5 create mode 100644 harmony/src/main/resources/base/element/string.json create mode 100644 harmony/src/main/resources/en_US/element/string.json create mode 100644 harmony/src/main/resources/zh_CN/element/string.json create mode 100644 harmony/ts.ts diff --git a/.gitignore b/.gitignore index 07ed026..819d856 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,4 @@ Example/testHotUpdate/.yarn android/bin Example/testHotUpdate/harmony Example/testHotUpdate/android/app/.cxx +Example/harmony_use_pushy/libs diff --git a/.gitmodules b/.gitmodules index 1bcca5b..51168f3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,9 @@ [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 diff --git a/Example/harmony_use_pushy/.bundle/config b/Example/harmony_use_pushy/.bundle/config new file mode 100644 index 0000000..848943b --- /dev/null +++ b/Example/harmony_use_pushy/.bundle/config @@ -0,0 +1,2 @@ +BUNDLE_PATH: "vendor/bundle" +BUNDLE_FORCE_RUBY_PLATFORM: 1 diff --git a/Example/harmony_use_pushy/.eslintrc.js b/Example/harmony_use_pushy/.eslintrc.js new file mode 100644 index 0000000..187894b --- /dev/null +++ b/Example/harmony_use_pushy/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: '@react-native', +}; diff --git a/Example/harmony_use_pushy/.prettierrc.js b/Example/harmony_use_pushy/.prettierrc.js new file mode 100644 index 0000000..2b54074 --- /dev/null +++ b/Example/harmony_use_pushy/.prettierrc.js @@ -0,0 +1,7 @@ +module.exports = { + arrowParens: 'avoid', + bracketSameLine: true, + bracketSpacing: false, + singleQuote: true, + trailingComma: 'all', +}; diff --git a/Example/harmony_use_pushy/.watchmanconfig b/Example/harmony_use_pushy/.watchmanconfig new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/Example/harmony_use_pushy/.watchmanconfig @@ -0,0 +1 @@ +{} diff --git a/Example/harmony_use_pushy/App.tsx b/Example/harmony_use_pushy/App.tsx new file mode 100644 index 0000000..85fdf8c --- /dev/null +++ b/Example/harmony_use_pushy/App.tsx @@ -0,0 +1,221 @@ +/* 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'; + +import TestConsole from './TestConsole'; + +import _updateConfig from './update.json'; +import {PushyProvider, Pushy, usePushy} from 'react-native-update'; +const {appKey} = _updateConfig.harmony; + +function App() { + const { + client, + checkUpdate, + downloadUpdate, + switchVersionLater, + switchVersion, + updateInfo, + packageVersion, + currentHash, + progress: {received, total} = {}, + } = usePushy(); + const [useDefaultAlert, setUseDefaultAlert] = useState(false); + const [showTestConsole, setShowTestConsole] = useState(false); + const [showUpdateBanner, setShowUpdateBanner] = useState(false); + const [showUpdateSnackbar, setShowUpdateSnackbar] = useState(false); + // if (updateInfo) { + // updateInfo!.name = 'name'; + // updateInfo!.update = true; + // } + const snackbarVisible = + !useDefaultAlert && showUpdateSnackbar && updateInfo?.update; + + if (showTestConsole) { + return ( + setShowTestConsole(false)} /> + ); + } + + return ( + + 欢迎使用Pushy热更新服务 + {/* 😁hdiffFromAPP更新成功!!! */} + {/* 😁hdiffFromPPk更新成功!!! */} + + { + client?.setOptions({ + updateStrategy: !useDefaultAlert ? null : 'alwaysAlert', + }); + setShowUpdateSnackbar(useDefaultAlert); + setUseDefaultAlert(!useDefaultAlert); + }} + style={{ + flexDirection: 'row', + alignItems: 'center', + }}> + + {useDefaultAlert && } + + + {' '} + {useDefaultAlert ? '当前使用' : '当前不使用'}默认的alert更新提示 + + + + + + 这是版本一 {'\n'} + 当前原生包版本号: {packageVersion} + {'\n'} + 当前热更新版本Hash: {currentHash || '(空)'} + {'\n'} + + + 下载进度:{received} / {total} + + { + checkUpdate(); + setShowUpdateSnackbar(true); + }}> + 点击这里检查更新 + + + { + setShowTestConsole(true); + }}> + + react-native-update版本:{client?.version} + + + {snackbarVisible && ( + + + + 有新版本({updateInfo.name})可用,是否更新? + + + setShowUpdateSnackbar(false)} + style={{marginRight: 10}}> + 取消 + + { + setShowUpdateSnackbar(false); + await downloadUpdate(); + setShowUpdateBanner(true); + }}> + 更新 + + + + + )} + {showUpdateBanner && ( + + + + 更新已完成,是否立即重启? + + + { + switchVersionLater(); + setShowUpdateBanner(false); + }} + style={{marginRight: 20}}> + 下次再说 + + + 立即重启 + + + + + )} + + ); +} + +const styles = StyleSheet.create({ + overlay: { + position: 'absolute', + top: 0, + left: 0, + right: 0, + bottom: 0, + backgroundColor: 'rgba(0, 0, 0, 0.5)', + justifyContent: 'center', + alignItems: 'center', + }, + container: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + backgroundColor: '#F5FCFF', + }, + welcome: { + fontSize: 20, + textAlign: 'center', + margin: 10, + }, + instructions: { + textAlign: 'center', + color: '#333333', + marginBottom: 5, + }, + image: {}, +}); + +const pushyClient = new Pushy({ + appKey, + debug: true, +}); + +export default function Root() { + return ( + + + + ); +} diff --git a/Example/harmony_use_pushy/Gemfile b/Example/harmony_use_pushy/Gemfile new file mode 100644 index 0000000..1fa2c2e --- /dev/null +++ b/Example/harmony_use_pushy/Gemfile @@ -0,0 +1,6 @@ +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' diff --git a/Example/harmony_use_pushy/README.md b/Example/harmony_use_pushy/README.md new file mode 100644 index 0000000..c243fdf --- /dev/null +++ b/Example/harmony_use_pushy/README.md @@ -0,0 +1,34 @@ +## 运行harmony_use_pushy项目步骤 + +### 1.将项目克隆到本地后在项目根目录创建libs文件夹。 + +### 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 +``` + +### 4. 确保在react-native-update根目录已经执行过yarn submodule命令。 +说明:这个命令会在harmony/src/main/cpp目录生成HDiffPatch和lzma的C++模块依赖。 + +### 5. 在项目根目录执行下面命令安装第三方依赖。 +``` +yarn install +``` + +### 6. 在项目根目录执行下面命令生成bundle包文件。 +``` +yarn build +``` +说明:这个命令会在harmony/entry/src/main/resources/rawfile目录生成Hbundle.harmony.js和assets文件,同时会基于该内容在.pushy/output目录生成ppk包。 + +**注意⚠️**:在使用pushy bundle --platform harmony命令进行打包的默认bundle包名是Hbundle.harmony.js,不要随意修改包名,因为diff是匹配该包名进行生成的。 + +### 7. 使用DevEco Studio IDE打开harmony目录然后执行sync运行项目 +![image](./sync.png) + +### 8 运行效果图 +![image](./demo.png) \ No newline at end of file diff --git a/Example/harmony_use_pushy/TestConsole.js b/Example/harmony_use_pushy/TestConsole.js new file mode 100644 index 0000000..c05fa5d --- /dev/null +++ b/Example/harmony_use_pushy/TestConsole.js @@ -0,0 +1,274 @@ +/* eslint-disable react-native/no-inline-styles */ +/* eslint-disable react/react-in-jsx-scope */ +import {useCallback, useMemo, useState} from 'react'; +import { + ActivityIndicator, + TextInput, + Button, + StyleSheet, + SafeAreaView, + Text, + View, + TouchableOpacity, +} from 'react-native'; + +import {PushyModule} from 'react-native-update'; +const Hash = '9D5CE6EBA420717BE7E7D308B11F8207681B066C951D68F3994D19828F342474'; +const UUID = '00000000-0000-0000-0000-000000000000'; +const DownloadUrl = 'https://localhost:3000/diff.ppk-patch'; +const AppPatchDownloadUrl = 'https://github.com/bozaigao/test_pushy_server/raw/refs/heads/main/hdiff.app-patch'; +const AppPatchHash = 'f5ba92c7c04250d4b8a446c8267ef459'; +const PPKDownloadUrl = 'https://github.com/bozaigao/test_pushy_server/raw/refs/heads/main/hdiff.ppk-patch'; +const PPKPatchHash = '6b3d26b7d868d1f67aedadb7f0b342d9'; +const OriginHash = 'f5ba92c7c04250d4b8a446c8267ef459'; + + +const CustomDialog = ({title, visible, onConfirm}) => { + if (!visible) { + return null; + } + + return ( + + + {title} + + 确认 + + + + ); +}; +export default function TestConsole({visible, onClose}) { + const [text, setText] = useState(''); + const [running, setRunning] = useState(false); + const [options, setOptions] = useState(); + const [alertVisible, setAlertVisible] = useState(false); + const [alertMsg, setAlertMsg] = useState(''); + const NativeTestMethod = useMemo(() => { + return [ + { + name: 'setLocalHashInfo', + invoke: () => { + setText( + `setLocalHashInfo\n${Hash}\n{\"version\":\"1.0.0\",\"size\":\"19M\"}`, + ); + }, + }, + { + name: 'getLocalHashInfo', + invoke: () => { + setText(`getLocalHashInfo\n${Hash}`); + }, + }, + { + name: 'setUuid', + invoke: () => { + setText(`setUuid\n${UUID}`); + }, + }, + { + name: 'reloadUpdate', + invoke: () => { + setText('reloadUpdate'); + setOptions({hash: Hash}); + }, + }, + { + name: 'setNeedUpdateForApp', + invoke: () => { + setText('setNeedUpdate'); + setOptions({hash: AppPatchHash}); + }, + }, + { + name: 'setNeedUpdateForPPK', + invoke: () => { + setText('setNeedUpdate'); + setOptions({hash: PPKPatchHash}); + }, + }, + { + name: 'markSuccess', + invoke: () => { + setText('markSuccess'); + setOptions(undefined); + }, + }, + { + name: 'downloadPatchFromPpk', + invoke: () => { + setText('downloadPatchFromPpk'); + setOptions({updateUrl: PPKDownloadUrl, hash: PPKPatchHash, originHash: OriginHash}); + }, + }, + { + name: 'downloadPatchFromPackage', + invoke: () => { + setText('downloadPatchFromPackage'); + setOptions({updateUrl: AppPatchDownloadUrl, hash: AppPatchHash}); + }, + }, + { + name: 'downloadFullUpdate', + invoke: () => { + setText('downloadFullUpdate'); + setOptions({updateUrl: DownloadUrl, hash: Hash}); + }, + }, + { + name: 'downloadAndInstallApk', + invoke: () => { + setText('downloadAndInstallApk'); + setOptions({url: DownloadUrl, target: Hash, hash: Hash}); + }, + }, + ]; + }, []); + + const renderTestView = useCallback(() => { + const views = []; + for (let i = 0; i < NativeTestMethod.length; i++) { + views.push( + { + NativeTestMethod[i].invoke(); + }}> + {NativeTestMethod[i].name} + , + ); + } + return {views}; + }, [NativeTestMethod]); + if (!visible) { + return null; + } + + return ( + + + 调试Pushy方法(方法名,参数,值换行) +