@ohos-cpf/3rdloop 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (219) hide show
  1. package/README.md +25 -0
  2. package/lib/cli.js +22 -5
  3. package/lib/doctor.js +111 -10
  4. package/lib/mcp.js +498 -0
  5. package/package.json +6 -2
  6. package/vendor/Archive/data/.index/meta.json +7 -0
  7. package/vendor/Archive/data/.index/search.db +0 -0
  8. package/vendor/Archive/data/docs/experiences/arkts-check-tool-pitfalls-baseline-comparison.md +13 -0
  9. package/vendor/Archive/data/docs/experiences/arkts-deep-path-import-recognition.md +31 -0
  10. package/vendor/Archive/data/docs/experiences/arkts-demo-coverage-entry-file-case-mismatch.md +25 -0
  11. package/vendor/Archive/data/docs/experiences/arkts-demo-coverage-import-trailing-slash.md +20 -0
  12. package/vendor/Archive/data/docs/experiences/arkts-library-source-files-may-be-ts.md +18 -0
  13. package/vendor/Archive/data/docs/experiences/arkts-typedarray-buffer-interface-cast-compile-fixes.md +36 -0
  14. package/vendor/Archive/data/docs/experiences/arkts-xts-compile-error-clustering-fix.md +24 -0
  15. package/vendor/Archive/data/docs/experiences/arkts-xts-doc-expected-value-runtime-probe.md +35 -0
  16. package/vendor/Archive/data/docs/experiences/arkts-xts-fixture-rawfile-testability-injection.md +33 -0
  17. package/vendor/Archive/data/docs/experiences/code-linter-chinese-comment-false-positive.md +16 -0
  18. package/vendor/Archive/data/docs/experiences/esobject-new-expression-variable-tracking.md +33 -0
  19. package/vendor/Archive/data/docs/experiences/filesystem-case-sensitivity-module-resolution.md +31 -0
  20. package/vendor/Archive/data/docs/experiences/gitcode-clone-redirect-warning-normal.md +13 -0
  21. package/vendor/Archive/data/docs/experiences/kn_msgvq1w585ec8319.md +77 -0
  22. package/vendor/Archive/data/docs/experiences/kn_msovnm6rd46de72c.md +98 -0
  23. package/vendor/Archive/data/docs/experiences/kn_mspt8vntfe708576.md +87 -0
  24. package/vendor/Archive/data/docs/experiences/kn_mspu1ei77adbbb48.md +133 -0
  25. package/vendor/Archive/data/docs/experiences/kn_mspubgak8d30bfce.md +128 -0
  26. package/vendor/Archive/data/docs/experiences/kn_mspug2de3cb1f7c3.md +115 -0
  27. package/vendor/Archive/data/docs/experiences/kn_skill_opt_001.md +38 -0
  28. package/vendor/Archive/data/docs/experiences/loop-artifacts-verification-evidence-triangle.md +19 -0
  29. package/vendor/Archive/data/docs/experiences/macos-bash-replace-build-ps1.md +19 -0
  30. package/vendor/Archive/data/docs/experiences/macos-bsd-diff-q-illegal-option.md +15 -0
  31. package/vendor/Archive/data/docs/experiences/migrate-cjs-compatible-api-version-map-limit.md +17 -0
  32. package/vendor/Archive/data/docs/experiences/mp3agic-arkts-library-behavior-quirks.md +21 -0
  33. package/vendor/Archive/data/docs/experiences/ohos-face-detection-scan-api-mapping.md +15 -0
  34. package/vendor/Archive/data/docs/experiences/pr-metadata-and-diff-integrity-verification.md +12 -0
  35. package/vendor/Archive/data/docs/experiences/rn-coverage-index-signature-pseudo-member-false-negative.md +32 -0
  36. package/vendor/Archive/data/docs/experiences/rn-memory-check-severity-calibration.md +21 -0
  37. package/vendor/Archive/data/docs/experiences/rn-platform-specific-api-exclusion-evidence.md +24 -0
  38. package/vendor/Archive/data/docs/experiences/rn-upstream-version-diff-pitfalls.md +17 -0
  39. package/vendor/Archive/data/docs/experiences/rn-version-gap-risk-rating-rules.md +13 -0
  40. package/vendor/Archive/data/docs/experiences/rn-view-lib-native-contract-diff-fabric-spec.md +16 -0
  41. package/vendor/Archive/data/docs/experiences/rnoh-adapter-package-version-field-semantics.md +18 -0
  42. package/vendor/Archive/data/docs/experiences/rnoh-arkts-sqlite-rows-array-format.md +18 -0
  43. package/vendor/Archive/data/docs/experiences/rnoh-dependency-residue-scan-strategy.md +18 -0
  44. package/vendor/Archive/data/docs/experiences/rnoh-example-local-lib-dep-use-tgz.md +53 -0
  45. package/vendor/Archive/data/docs/experiences/rnoh-example-prereserve-rntesterlist.md +17 -0
  46. package/vendor/Archive/data/docs/experiences/rnoh-example-template-compatiblesdkversion-upgrade.md +29 -0
  47. package/vendor/Archive/data/docs/experiences/rnoh-example-turbomodule-shell-adaptation-checklist.md +41 -0
  48. package/vendor/Archive/data/docs/experiences/rnoh-mcp-build-project-tool-risk.md +18 -0
  49. package/vendor/Archive/data/docs/experiences/rnoh-npm-devdependencies-version-precheck.md +29 -0
  50. package/vendor/Archive/data/docs/experiences/rnoh-repo-baseline-version-verification.md +13 -0
  51. package/vendor/Archive/data/docs/experiences/rnoh-repo-upstream-directory-mapping.md +18 -0
  52. package/vendor/Archive/data/docs/experiences/rnoh-stateless-library-zero-leak-verification.md +31 -0
  53. package/vendor/Archive/data/docs/experiences/rnoh-template-npmrc-credential-removal.md +15 -0
  54. package/vendor/Archive/data/docs/experiences/rnoh-turbomodule-codegen-wiring-verification.md +19 -0
  55. package/vendor/Archive/data/docs/experiences/rnoh-turbomodule-cpp-methodmap-compatibility-check.md +20 -0
  56. package/vendor/Archive/data/docs/experiences/scenario-doc-vs-source-signature-diff-four-patterns.md +24 -0
  57. package/vendor/Archive/data/docs/experiences/static-analysis-grep-cross-validation.md +29 -0
  58. package/vendor/Archive/demo.js +489 -0
  59. package/vendor/Archive/index.js +43 -0
  60. package/vendor/Archive/package.json +16 -0
  61. package/vendor/Archive/src/constants.js +83 -0
  62. package/vendor/Archive/src/data/stopwords.txt +110 -0
  63. package/vendor/Archive/src/data/synonyms.json +25 -0
  64. package/vendor/Archive/src/data/terms.txt +59 -0
  65. package/vendor/Archive/src/db/sqlite-backend.js +312 -0
  66. package/vendor/Archive/src/db/sqlite-schema.js +64 -0
  67. package/vendor/Archive/src/engine.js +501 -0
  68. package/vendor/Archive/src/index/index-manager.js +203 -0
  69. package/vendor/Archive/src/index/index-state.js +94 -0
  70. package/vendor/Archive/src/index/search-text-builder.js +106 -0
  71. package/vendor/Archive/src/index.js +22 -0
  72. package/vendor/Archive/src/parser/api-identifiers.js +121 -0
  73. package/vendor/Archive/src/parser/api-suffixes.js +48 -0
  74. package/vendor/Archive/src/parser/heading-normalize.js +40 -0
  75. package/vendor/Archive/src/parser/markdown-splitter.js +215 -0
  76. package/vendor/Archive/src/search/catalog-routing.js +87 -0
  77. package/vendor/Archive/src/search/fts-search.js +289 -0
  78. package/vendor/Archive/src/search/query-normalizer.js +159 -0
  79. package/vendor/Archive/src/search/query-rewriter.js +72 -0
  80. package/vendor/Archive/src/search/search-engine.js +72 -0
  81. package/vendor/Archive/src/search/snippet.js +64 -0
  82. package/vendor/Archive/src/store/dir-store.js +103 -0
  83. package/vendor/Archive/src/store/doc-store.js +36 -0
  84. package/vendor/Archive/src/tokenizer/lexicon.js +151 -0
  85. package/vendor/Archive/src/tokenizer/tokenizer.js +167 -0
  86. package/vendor/Archive/src/types.js +86 -0
  87. package/vendor/Archive/src/utils/hash.js +16 -0
  88. package/vendor/Archive/src/utils/lock.js +73 -0
  89. package/vendor/Archive/src/utils/path-safety.js +96 -0
  90. package/vendor/Archive/src/utils/paths.js +39 -0
  91. package/vendor/BadCase/rn/INDEX.md +127 -0
  92. package/vendor/BadCase/rn/cases/KI-001-webview/350/247/206/351/242/221/346/227/240/346/263/225/346/250/252/345/261/217.md +52 -0
  93. package/vendor/BadCase/rn/cases/KI-002-fastImage/347/203/255/346/233/264/346/226/260/345/233/276/347/211/207/345/244/261/350/264/245.md +37 -0
  94. package/vendor/BadCase/rn/cases/KI-003-wechat/347/274/251/347/225/245/345/233/276/346/234/254/345/234/260/345/233/276/347/211/207.md +62 -0
  95. package/vendor/BadCase/rn/cases/KI-004-wechat/345/233/236/350/260/203/346/227/266/345/272/217.md +47 -0
  96. package/vendor/BadCase/rn/cases/KI-005-geolocation/345/257/274/345/205/245/350/267/257/345/276/204/345/220/216/347/274/200.md +31 -0
  97. package/vendor/BadCase/rn/cases/KI-006-SmartRefreshLayout/346/231/272/350/203/275/346/214/207/351/222/210/345/264/251/346/272/203.md +55 -0
  98. package/vendor/BadCase/rn/cases/KI-007-orientation-locker/344/274/240/346/204/237/345/231/250/345/210/235/345/247/213/345/214/226.md +58 -0
  99. package/vendor/BadCase/rn/cases/KI-008-orientation-locker/344/274/240/346/204/237/345/231/250/345/274/225/347/224/250/350/256/241/346/225/260.md +47 -0
  100. package/vendor/BadCase/rn/cases/KI-009-pager-view/345/265/214/345/245/227/346/273/221/345/212/250.md +38 -0
  101. package/vendor/BadCase/rn/cases/KI-010-screens/346/211/213/345/212/277/345/206/262/347/252/201.md +48 -0
  102. package/vendor/BadCase/rn/cases/KI-011-spring-scrollview/346/211/213/345/212/277/351/207/215/345/244/215/347/273/221/345/256/232.md +49 -0
  103. package/vendor/BadCase/rn/cases/KI-012-qr-camera/346/250/252/345/261/217/351/200/202/351/205/215.md +59 -0
  104. package/vendor/BadCase/rn/cases/KI-013-webview/346/267/261/350/211/262/346/250/241/345/274/217/350/203/214/346/231/257/350/211/262.md +37 -0
  105. package/vendor/BadCase/rn/cases/KI-014-amap-geolocation/345/233/236/350/260/203/347/274/272/345/244/261.md +42 -0
  106. package/vendor/BadCase/rn/cases/KI-015-reanimated/350/277/220/350/241/214/346/227/266/346/236/220/346/236/204/345/264/251/346/272/203.md +54 -0
  107. package/vendor/BadCase/rn/cases/KI-016-fs/346/226/207/344/273/266/350/257/273/345/217/226/347/274/226/347/240/201.md +58 -0
  108. package/vendor/BadCase/rn/cases/KI-017-blob-util/345/217/202/346/225/260/347/274/226/347/240/201/351/224/231/350/257/257.md +39 -0
  109. package/vendor/BadCase/rn/cases/KI-018-modal/345/274/271/347/252/227/351/227/252/347/203/201.md +53 -0
  110. package/vendor/BadCase/rn/cases/KI-019-code-push/351/207/215/345/220/257/351/200/273/350/276/221/345/244/261/346/225/210.md +79 -0
  111. package/vendor/BadCase/rn/cases/KI-020-netinfo/346/225/217/346/204/237/344/277/241/346/201/257/346/263/204/351/234/262.md +60 -0
  112. package/vendor/BadCase/rn/cases/KI-021-video/346/234/254/345/234/260/350/247/206/351/242/221/346/222/255/346/224/276/345/274/202/345/270/270.md +79 -0
  113. package/vendor/BadCase/rn/cases/KI-022-audio-recorder-player/346/236/232/344/270/276/347/274/272/345/244/261.md +38 -0
  114. package/vendor/BadCase/rn/cases/KI-023-svg/346/270/220/345/217/230/347/273/247/346/211/277/345/244/261/346/225/210.md +62 -0
  115. package/vendor/BadCase/rn/generalization-log.md +55 -0
  116. package/vendor/BadCase/rn/pr-info/rntpc_react-native-SmartRefreshLayout-32.json +328 -0
  117. package/vendor/BadCase/rn/pr-info/rntpc_react-native-SmartRefreshLayout-32.md +382 -0
  118. package/vendor/BadCase/rn/pr-info/rntpc_react-native-amap-geolocation-27.json +1351 -0
  119. package/vendor/BadCase/rn/pr-info/rntpc_react-native-amap-geolocation-27.md +1176 -0
  120. package/vendor/BadCase/rn/pr-info/rntpc_react-native-audio-recorder-player-22.json +538 -0
  121. package/vendor/BadCase/rn/pr-info/rntpc_react-native-audio-recorder-player-22.md +1488 -0
  122. package/vendor/BadCase/rn/pr-info/rntpc_react-native-blob-util-23.json +211 -0
  123. package/vendor/BadCase/rn/pr-info/rntpc_react-native-blob-util-23.md +35 -0
  124. package/vendor/BadCase/rn/pr-info/rntpc_react-native-code-push-17.json +2048 -0
  125. package/vendor/BadCase/rn/pr-info/rntpc_react-native-code-push-17.md +3866 -0
  126. package/vendor/BadCase/rn/pr-info/rntpc_react-native-fast-image-102.json +198 -0
  127. package/vendor/BadCase/rn/pr-info/rntpc_react-native-fast-image-102.md +40 -0
  128. package/vendor/BadCase/rn/pr-info/rntpc_react-native-fs-38.json +751 -0
  129. package/vendor/BadCase/rn/pr-info/rntpc_react-native-fs-38.md +883 -0
  130. package/vendor/BadCase/rn/pr-info/rntpc_react-native-geolocation-24.json +1544 -0
  131. package/vendor/BadCase/rn/pr-info/rntpc_react-native-geolocation-24.md +2598 -0
  132. package/vendor/BadCase/rn/pr-info/rntpc_react-native-modal-20.json +246 -0
  133. package/vendor/BadCase/rn/pr-info/rntpc_react-native-modal-20.md +554 -0
  134. package/vendor/BadCase/rn/pr-info/rntpc_react-native-netinfo-31.json +211 -0
  135. package/vendor/BadCase/rn/pr-info/rntpc_react-native-netinfo-31.md +54 -0
  136. package/vendor/BadCase/rn/pr-info/rntpc_react-native-orientation-locker-45.json +1626 -0
  137. package/vendor/BadCase/rn/pr-info/rntpc_react-native-orientation-locker-45.md +2213 -0
  138. package/vendor/BadCase/rn/pr-info/rntpc_react-native-orientation-locker-51.json +208 -0
  139. package/vendor/BadCase/rn/pr-info/rntpc_react-native-orientation-locker-51.md +77 -0
  140. package/vendor/BadCase/rn/pr-info/rntpc_react-native-pager-view-32.json +377 -0
  141. package/vendor/BadCase/rn/pr-info/rntpc_react-native-pager-view-32.md +174 -0
  142. package/vendor/BadCase/rn/pr-info/rntpc_react-native-qr-decode-image-camera-37.json +232 -0
  143. package/vendor/BadCase/rn/pr-info/rntpc_react-native-qr-decode-image-camera-37.md +194 -0
  144. package/vendor/BadCase/rn/pr-info/rntpc_react-native-reanimated-82.json +198 -0
  145. package/vendor/BadCase/rn/pr-info/rntpc_react-native-reanimated-82.md +67 -0
  146. package/vendor/BadCase/rn/pr-info/rntpc_react-native-screens-87.json +198 -0
  147. package/vendor/BadCase/rn/pr-info/rntpc_react-native-screens-87.md +38 -0
  148. package/vendor/BadCase/rn/pr-info/rntpc_react-native-screens-93.json +208 -0
  149. package/vendor/BadCase/rn/pr-info/rntpc_react-native-screens-93.md +34 -0
  150. package/vendor/BadCase/rn/pr-info/rntpc_react-native-spring-scrollview-38.json +222 -0
  151. package/vendor/BadCase/rn/pr-info/rntpc_react-native-spring-scrollview-38.md +56 -0
  152. package/vendor/BadCase/rn/pr-info/rntpc_react-native-svg-117.json +463 -0
  153. package/vendor/BadCase/rn/pr-info/rntpc_react-native-svg-117.md +383 -0
  154. package/vendor/BadCase/rn/pr-info/rntpc_react-native-video-66.json +464 -0
  155. package/vendor/BadCase/rn/pr-info/rntpc_react-native-video-66.md +565 -0
  156. package/vendor/BadCase/rn/pr-info/rntpc_react-native-webview-112.json +198 -0
  157. package/vendor/BadCase/rn/pr-info/rntpc_react-native-webview-112.md +47 -0
  158. package/vendor/BadCase/rn/pr-info/rntpc_react-native-webview-121.json +232 -0
  159. package/vendor/BadCase/rn/pr-info/rntpc_react-native-webview-121.md +422 -0
  160. package/vendor/BadCase/rn/pr-info/rntpc_react-native-wechat-lib-15.json +295 -0
  161. package/vendor/BadCase/rn/pr-info/rntpc_react-native-wechat-lib-15.md +1038 -0
  162. package/vendor/BadCase/rn/rules/R-01-/345/205/250/345/261/217/347/252/227/345/217/243/347/212/266/346/200/201/347/256/241/347/220/206/345/256/214/346/225/264/346/200/247.md +20 -0
  163. package/vendor/BadCase/rn/rules/R-02-/350/265/204/346/272/220URI/345/275/242/346/200/201/345/210/206/346/224/257/350/246/206/347/233/226.md +21 -0
  164. package/vendor/BadCase/rn/rules/R-03-/351/231/204/345/261/236/346/223/215/344/275/234/345/244/261/350/264/245/351/230/273/346/226/255/344/270/273/346/265/201/347/250/213.md +20 -0
  165. package/vendor/BadCase/rn/rules/R-04-/345/274/202/346/255/245/345/233/236/350/260/203/346/263/250/345/206/214/346/227/266/345/272/217.md +20 -0
  166. package/vendor/BadCase/rn/rules/R-05-/346/250/241/345/235/227/345/257/274/345/205/245/350/267/257/345/276/204/350/247/204/350/214/203.md +19 -0
  167. package/vendor/BadCase/rn/rules/R-06-/344/274/240/346/204/237/345/231/250/347/241/254/344/273/266/346/235/203/351/231/220/346/214/211/351/234/200/350/216/267/345/217/226.md +21 -0
  168. package/vendor/BadCase/rn/rules/R-07-/346/231/272/350/203/275/346/214/207/351/222/210/347/224/237/345/221/275/345/221/250/346/234/237/347/256/241/347/220/206.md +20 -0
  169. package/vendor/BadCase/rn/rules/R-08-/346/211/213/345/212/277/344/272/213/344/273/266/346/263/250/345/206/214/344/270/216/345/206/262/347/252/201/345/244/204/347/220/206.md +22 -0
  170. package/vendor/BadCase/rn/rules/R-09-/346/250/252/347/253/226/345/261/217/345/244/232/345/275/242/346/200/201/345/270/203/345/261/200/351/200/202/351/205/215.md +20 -0
  171. package/vendor/BadCase/rn/rules/R-10-/346/267/261/350/211/262/346/250/241/345/274/217/344/270/273/351/242/230/351/242/234/350/211/262/351/200/202/351/205/215.md +19 -0
  172. package/vendor/BadCase/rn/rules/R-11-/346/216/245/345/217/243/345/233/236/350/260/203/345/256/236/347/216/260/345/256/214/346/225/264/346/200/247.md +20 -0
  173. package/vendor/BadCase/rn/rules/R-12-/345/216/237/347/224/237/350/277/220/350/241/214/346/227/266/350/265/204/346/272/220/346/236/220/346/236/204/346/227/266/345/272/217.md +20 -0
  174. package/vendor/BadCase/rn/rules/R-13-/346/226/207/344/273/266/346/225/260/346/215/256/347/274/226/347/240/201/344/270/216/346/240/274/345/274/217/345/205/274/345/256/271.md +21 -0
  175. package/vendor/BadCase/rn/rules/R-14-/345/212/250/347/224/273/345/210/235/345/247/213/345/214/226/346/227/266/345/272/217/344/270/216/347/212/266/346/200/201/345/220/214/346/255/245.md +20 -0
  176. package/vendor/BadCase/rn/rules/R-15-/347/212/266/346/200/201/346/214/201/344/271/205/345/214/226/344/270/216/351/207/215/345/220/257/351/200/273/350/276/221/344/270/200/350/207/264/346/200/247.md +20 -0
  177. package/vendor/BadCase/rn/rules/R-16-/346/225/217/346/204/237/344/277/241/346/201/257/346/227/245/345/277/227/346/263/204/351/234/262.md +19 -0
  178. package/vendor/BadCase/rn/rules/R-17-/345/252/222/344/275/223/350/265/204/346/272/220/347/224/237/345/221/275/345/221/250/346/234/237/344/270/216/351/224/231/350/257/257/345/244/204/347/220/206.md +21 -0
  179. package/vendor/BadCase/rn/rules/R-18-/350/203/275/345/212/233/346/236/232/344/270/276/351/205/215/347/275/256/345/256/214/346/225/264/346/200/247.md +19 -0
  180. package/vendor/BadCase/rn/rules/R-19-/345/233/276/345/275/242/346/270/262/346/237/223/345/261/236/346/200/247/347/273/247/346/211/277/344/270/216/351/207/215/347/275/256.md +19 -0
  181. package/vendor/MCP/README.md +490 -0
  182. package/vendor/MCP/config.json +29 -0
  183. package/vendor/MCP/package.json +23 -0
  184. package/vendor/MCP/scripts/analyze-demo-coverage.cjs +1203 -0
  185. package/vendor/MCP/scripts/analyze-xts-coverage.cjs +1245 -0
  186. package/vendor/MCP/scripts/deveco_docs.js +247 -0
  187. package/vendor/MCP/scripts/extract-interfaces.cjs +1487 -0
  188. package/vendor/MCP/scripts/flutter-analyze-demo-coverage.cjs +666 -0
  189. package/vendor/MCP/scripts/flutter-analyze-xts-coverage.cjs +684 -0
  190. package/vendor/MCP/scripts/flutter-extract-interfaces.cjs +1251 -0
  191. package/vendor/MCP/scripts/flutter-render-spec-doc.cjs +351 -0
  192. package/vendor/MCP/scripts/render-spec-doc.cjs +347 -0
  193. package/vendor/MCP/scripts/rn-analyze-demo-coverage.cjs +645 -0
  194. package/vendor/MCP/scripts/rn-analyze-test-coverage.cjs +614 -0
  195. package/vendor/MCP/scripts/rn-extract-interfaces.cjs +1462 -0
  196. package/vendor/MCP/scripts/rn-render-spec-doc.cjs +327 -0
  197. package/vendor/MCP/scripts/rn-scan-exports.cjs +1336 -0
  198. package/vendor/MCP/src/client/MCPClientPool.js +220 -0
  199. package/vendor/MCP/src/config/ConfigLoader.js +189 -0
  200. package/vendor/MCP/src/executor/ScriptExecutor.js +110 -0
  201. package/vendor/MCP/src/gateway/Gateway.js +451 -0
  202. package/vendor/MCP/src/index.js +87 -0
  203. package/vendor/MCP/src/library/KBToolProvider.js +229 -0
  204. package/vendor/MCP/src/library/logger.js +60 -0
  205. package/vendor/MCP/src/registry/ScriptRegistry.js +238 -0
  206. package/vendor/MCP/src/registry/ToolRegistry.js +111 -0
  207. package/vendor/MCP/src/types.js +115 -0
  208. package/vendor/Server/Skills/arkts-library-test-coverage-check/references/MCP_TOOL_USAGE.md +4 -2
  209. package/vendor/Server/Skills/arkts-library-xts-coverage/SKILL.md +3 -3
  210. package/vendor/Server/Skills/knowledge-import/SKILL.md +1 -1
  211. package/vendor/Server/Skills/knowledge-import/references/MCP_TOOL_USAGE.md +12 -4
  212. package/vendor/Server/Skills/ohos-lib-pr-push/SKILL.md +5 -4
  213. package/vendor/Server/Skills/rn-library-issue-generalizer/SKILL.md +2 -2
  214. package/vendor/Server/Skills/rn-library-known-issue-check/SKILL.md +2 -2
  215. package/vendor/Server/Skills/rnoh-lib-demo-coverage/SKILL.md +1 -2
  216. package/vendor/Server/Skills/rnoh-lib-test-align/references/port-test-demo-guide.md +1 -1
  217. package/vendor/Server/Skills/rnoh-lib-xts-coverage/SKILL.md +1 -2
  218. package/vendor/Server/package.json +5 -1
  219. package/vendor/VERSION +3 -3
@@ -0,0 +1,3866 @@
1
+ # PR #17: fix:修复restartApp无法触发的问题
2
+
3
+ - **状态**: merged
4
+ - **作者**: chenbaodi123
5
+ - **创建时间**: 2026-06-27T14:21:52+08:00
6
+ - **分支**: br_rnoh0.72 → br_rnoh0.72
7
+ - **变更文件数**: 76
8
+ - **⚠️ 注意**: diff 过大已截断,变更文件列表完整保留
9
+
10
+ ## PR 描述
11
+
12
+ 问题原因:在CodePush.sync的installMode设置ON_NEXT_RESTART时,调用CodePush.restartApp方法失效
13
+ 解决方案:跟上流社区保持一致,无论installMode设置什么模式,CodePush.restartApp都可以正常触发
14
+
15
+ ## 变更文件
16
+
17
+ | 文件 | 变更 | +行 | -行 |
18
+ |------|------|-----|-----|
19
+ | `OAT.xml` | ? | +43 | -6 |
20
+ | `README.md` | ? | +619 | -7 |
21
+ | `README_en.md` | added | +627 | -0 |
22
+ | `buildEnv.sh` | added | +8 | -0 |
23
+ | `example/.eslintrc` | added | +13 | -0 |
24
+ | `example/.gitignore` | added | +71 | -0 |
25
+ | `example/.node-version` | added | +1 | -0 |
26
+ | `example/.prettierrc.js` | added | +7 | -0 |
27
+ | `example/.watchmanconfig` | added | +1 | -0 |
28
+ | `example/app.json` | added | +4 | -0 |
29
+ | `example/babel.config.js` | added | +5 | -0 |
30
+ | `example/contexts.ts` | added | +26 | -0 |
31
+ | `example/harmony/.gitignore` | added | +24 | -0 |
32
+ | `example/harmony/AppScope/app.json5` | added | +10 | -0 |
33
+ | `example/harmony/AppScope/resources/base/element/string.json` | added | +8 | -0 |
34
+ | `example/harmony/AppScope/resources/base/media/app_icon.png` | added | +0 | -0 |
35
+ | `example/harmony/build-profile.template.json5` | added | +39 | -0 |
36
+ | `example/harmony/codelinter.json` | added | +32 | -0 |
37
+ | `example/harmony/entry/.gitignore` | added | +7 | -0 |
38
+ | `example/harmony/entry/build-profile.json5` | added | +19 | -0 |
39
+ | `example/harmony/entry/hvigorfile.ts` | added | +17 | -0 |
40
+ | `example/harmony/entry/oh-package.json5` | added | +11 | -0 |
41
+ | `example/harmony/entry/src/main/cpp/.gitignore` | added | +2 | -0 |
42
+ | `example/harmony/entry/src/main/cpp/CMakeLists.txt` | added | +35 | -0 |
43
+ | `example/harmony/entry/src/main/cpp/PackageProvider.cpp` | added | +35 | -0 |
44
+ | `example/harmony/entry/src/main/ets/RNPackagesFactory.ets` | added | +32 | -0 |
45
+ | `example/harmony/entry/src/main/ets/assets/fonts/Pacifico-Regular.ttf` | added | +0 | -0 |
46
+ | `example/harmony/entry/src/main/ets/assets/fonts/StintUltraCondensed-Regular.ttf` | added | +0 | -0 |
47
+ | `example/harmony/entry/src/main/ets/entryability/EntryAbility.ets` | added | +37 | -0 |
48
+ | `example/harmony/entry/src/main/ets/pages/Index.ets` | added | +136 | -0 |
49
+ | `example/harmony/entry/src/main/ets/pages/SurfaceDeadlockTest.ets` | added | +153 | -0 |
50
+ | `example/harmony/entry/src/main/ets/pages/TouchDisplayer.ets` | added | +60 | -0 |
51
+ | `example/harmony/entry/src/main/module.json5` | added | +52 | -0 |
52
+ | `example/harmony/entry/src/main/resources/.gitignore` | added | +1 | -0 |
53
+ | `example/harmony/entry/src/main/resources/base/element/color.json` | added | +8 | -0 |
54
+ | `example/harmony/entry/src/main/resources/base/element/string.json` | added | +16 | -0 |
55
+ | `example/harmony/entry/src/main/resources/base/media/icon.png` | added | +0 | -0 |
56
+ | `example/harmony/entry/src/main/resources/base/profile/main_pages.json` | added | +5 | -0 |
57
+ | `example/harmony/entry/src/main/resources/rawfile/1.txt` | added | +1 | -0 |
58
+ | `example/harmony/format.ps1` | added | +12 | -0 |
59
+ | `example/harmony/hvigor/.gitignore` | added | +1 | -0 |
60
+ | `example/harmony/hvigor/hvigor-config.json5` | added | +21 | -0 |
61
+ | `example/harmony/hvigorfile.ts` | added | +2 | -0 |
62
+ | `example/harmony/oh-package.json5` | added | +12 | -0 |
63
+ | `example/index.js` | added | +28 | -0 |
64
+ | `example/jest.config.js` | added | +5 | -0 |
65
+ | `example/metro.config.js` | added | +24 | -0 |
66
+ | `example/package.json` | added | +68 | -0 |
67
+ | `example/react-native.config.js` | added | +5 | -0 |
68
+ | `example/scripts/create-build-profile.js` | added | +39 | -0 |
69
+ | `example/src/codepush.tsx` | added | +126 | -0 |
70
+ | `example/tsconfig.json` | added | +14 | -0 |
71
+ | `harmony/codePush/index.ets` | ? | +22 | -4 |
72
+ | `harmony/codePush/src/main/ets/CodePush.ts` | ? | +22 | -4 |
73
+ | `harmony/codePush/src/main/ets/CodePushBuilder.ts` | ? | +22 | -4 |
74
+ | `harmony/codePush/src/main/ets/CodePushConstants.ts` | ? | +22 | -4 |
75
+ | `harmony/codePush/src/main/ets/CodePushInstallMode.ts` | ? | +22 | -4 |
76
+ | `harmony/codePush/src/main/ets/CodePushInvalidPublicKeyException.ts` | ? | +22 | -4 |
77
+ | `harmony/codePush/src/main/ets/CodePushInvalidUpdateException.ts` | ? | +22 | -4 |
78
+ | `harmony/codePush/src/main/ets/CodePushMalformedDataException.ts` | ? | +22 | -4 |
79
+ | `harmony/codePush/src/main/ets/CodePushNativeModule.ts` | ? | +63 | -24 |
80
+ | `harmony/codePush/src/main/ets/CodePushNotInitializedException.ts` | ? | +22 | -4 |
81
+ | `harmony/codePush/src/main/ets/CodePushPackage.ets` | ? | +22 | -4 |
82
+ | `harmony/codePush/src/main/ets/CodePushTelemetryManager.ts` | ? | +22 | -4 |
83
+ | `harmony/codePush/src/main/ets/CodePushUnknownException.ts` | ? | +22 | -4 |
84
+ | `harmony/codePush/src/main/ets/CodePushUpdateManager.ts` | ? | +22 | -4 |
85
+ | `harmony/codePush/src/main/ets/CodePushUpdateState.ts` | ? | +22 | -4 |
86
+ | `harmony/codePush/src/main/ets/CodePushUpdateUtils.ts` | ? | +22 | -4 |
87
+ | `harmony/codePush/src/main/ets/CodePushUtils.ts` | ? | +22 | -4 |
88
+ | `harmony/codePush/src/main/ets/FileUtils.ts` | ? | +22 | -4 |
89
+ | `harmony/codePush/src/main/ets/Logger.ts` | ? | +22 | -4 |
90
+ | `harmony/codePush/src/main/ets/SettingsManager.ts` | ? | +22 | -4 |
91
+ | `harmony/codePush/src/main/ets/generated/turboModules/RTNCodePush.ts` | ? | +0 | -2 |
92
+ | `harmony/codePush/ts.ets` | ? | +22 | -4 |
93
+ | `package.json` | ? | +1 | -0 |
94
+ | `src/NativeCodePush.ts` | ? | +22 | -4 |
95
+
96
+ ## Diff
97
+
98
+ ### `OAT.xml`
99
+
100
+ ```diff
101
+ @@ -48,12 +48,25 @@
102
+ <filteritem type="filepath" name="harmony/codePush/oh-package-lock.json5" desc="工程配置文件,不添加许可证头"/>
103
+ <filteritem type="filepath" name="harmony/codePush/oh-package.json5" desc="工程配置文件,不添加许可证头"/>
104
+ <filteritem type="filepath" name="harmony/codePush/src/main/module.json5" desc="工程配置文件,不添加许可证头"/>
105
+ -
106
+ + <filteritem type="filepath" name="buildEnv.sh" desc="工程模板,不添加许可证头"/>
107
+ + <filteritem type="filepath" name="example/harmony/entry/src/main/resources/rawfile/bundle.harmony.js" desc="编译生成文件"/>
108
+ + <filteritem type="filepath" name="example/.prettierrc.js" desc="工程模板,不添加许可证头"/>
109
+ + <filteritem type="filepath" name="example/.watchmanconfig" desc="工程模板,不添加许可证头"/>
110
+ + <filteritem type="filepath" name="example/babel.config.js" desc="工程模板,不添加许可证头"/>
111
+ + <filteritem type="filepath" name="example/harmony/.clang-tidy" desc="工程模板,不添加许可证头"/>
112
+ + <filteritem type="filepath" name="example/harmony/.clangd" desc="工程模板,不添加许可证头"/>
113
+ + <filteritem type="filepath" name="harmony/codePush/src/main/cpp/generated/.*" desc="Codegen生成文件,不手动修改"/>
114
+ + <filteritem type="filepath" name="harmony/codePush/src/main/ets/generated/.*" desc="Codegen生成文件,不手动修改"/>
115
+ + <filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
116
+ + <filteritem type="filename" name="*/*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
117
+ + <filteritem type="filepath" name="example/scripts/.*" desc="脚本文件,不添加许可证头"/>
118
+ + <filteritem type="filepath" name="example/harmony/format.ps1" desc="工程模板,不添加许可证头"/>
119
+ + <filteritem type="filepath" name="example/harmony/hvigorfile.ts" desc="工程模板,不添加许可证头"/>
120
+ + <filteritem type="filepath" name="example/.eslintrc" desc="工程模板,不添加许可证头"/>
121
+ + <filteritem type="filepath" name="example/jest.config.js" desc="工程模板,不添加许可证头"/>
122
+ + <filteritem type="filepath" name="example/metro.config.js" desc="工程模板,不添加许可证头"/>
123
+ + <filteritem type="filepath" name="example/.node-version" desc="工程模板,不添加许可证头"/>
124
+ </filefilter>
125
+ - <filefilter name="binaryFileTypePolicyFilter" desc="Filters for copyright header policies">
126
+ - <filteritem type="filepath" name="harmony/codePush.har" desc="项目打包文件"/>
127
+ - </filefilter>
128
+ -
129
+ <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
130
+ <filteritem type="filename" name=".npmignore" desc="工程配置文件,不添加版权头"/>
131
+ <filteritem type="filename" name="LICENSE.md" desc="许可证说明文件,不添加版权头"/>
132
+ @@ -71,7 +84,31 @@
133
+ <filteritem type="filepath" name="harmony/codePush/oh-package-lock.json5" desc="工程配置文件,不添加许可证头"/>
134
+ <filteritem type="filepath" name="harmony/codePush/oh-package.json5" desc="工程配置文件,不添加许可证头"/>
135
+ <filteritem type="filepath" name="harmony/codePush/src/main/module.json5" desc="工程配置文件,不添加许可证头"/>
136
+ -
137
+ + <filteritem type="filepath" name="buildEnv.sh" desc="工程模板,不添加许可证头"/>
138
+ + <filteritem type="filepath" name="example/harmony/entry/src/main/resources/rawfile/bundle.harmony.js" desc="编译生成文件"/>
139
+ + <filteritem type="filepath" name="example/.prettierrc.js" desc="工程模板,不添加许可证头"/>
140
+ + <filteritem type="filepath" name="example/.watchmanconfig" desc="工程模板,不添加许可证头"/>
141
+ + <filteritem type="filepath" name="example/babel.config.js" desc="工程模板,不添加许可证头"/>
142
+ + <filteritem type="filepath" name="example/harmony/.clang-tidy" desc="工程模板,不添加许可证头"/>
143
+ + <filteritem type="filepath" name="example/harmony/.clangd" desc="工程模板,不添加许可证头"/>
144
+ + <filteritem type="filepath" name="harmony/codePush/src/main/cpp/generated/.*" desc="Codegen生成文件,不手动修改"/>
145
+ + <filteritem type="filepath" name="harmony/codePush/src/main/ets/generated/.*" desc="Codegen生成文件,不手动修改"/>
146
+ + <filteritem type="filename" name="*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
147
+ + <filteritem type="filename" name="*/*.json5" desc="hvigor配置文件,DevEco Studio自动生成,不手动修改"/>
148
+ + <filteritem type="filepath" name="example/scripts/.*" desc="脚本文件,不添加许可证头"/>
149
+ + <filteritem type="filepath" name="example/harmony/format.ps1" desc="工程模板,不添加许可证头"/>
150
+ + <filteritem type="filepath" name="example/harmony/hvigorfile.ts" desc="工程模板,不添加许可证头"/>
151
+ + <filteritem type="filepath" name="example/.eslintrc" desc="工程模板,不添加许可证头"/>
152
+ + <filteritem type="filepath" name="example/jest.config.js" desc="工程模板,不添加许可证头"/>
153
+ + <filteritem type="filepath" name="example/metro.config.js" desc="工程模板,不添加许可证头"/>
154
+ + <filteritem type="filepath" name="example/.node-version" desc="工程模板,不添加许可证头"/>
155
+ + </filefilter>
156
+ + <filefilter name="binaryFileTypePolicyFilter" desc="Filters for copyright header policies">
157
+ + <filteritem type="filepath" name="harmony/codePush.har" desc="项目打包文件"/>
158
+ + <filteritem type="filepath" name="example/harmony/entry/src/main/resources/base/media/.*" desc="资源文件"/>
159
+ + <filteritem type="filepath" name="example/harmony/entry/src/main/ets/assets/fonts/.*" desc="字体资源文件"/>
160
+ + <filteritem type="filepath" name="example/harmony/AppScope/resources/base/media/.*" desc="资源文件"/>
161
+ + <filteritem type="filepath" name=" example/harmony/entry/src/main/resources/rawfile/assets/.*" desc="资源文件"/>
162
+ </filefilter>
163
+ </filefilterlist>
164
+ </oatconfig>
165
+
166
+ ```
167
+
168
+ ### `README.md`
169
+
170
+ ```diff
171
+ @@ -1,13 +1,625 @@
172
+ -# @react-native-ohos/react-native-code-push
173
+
174
+ -This project is based on [react-native-code-push](https://github.com/microsoft/react-native-code-push)@9.0.1
175
+ +> 模板版本:v0.2.2
176
+
177
+ -## Documentation
178
+ +<p align="center">
179
+ + <h1 align="center"> <code>react-native-code-push</code> </h1>
180
+ +</p>
181
+ +<p align="center">
182
+ + <a href="https://github.com/microsoft/react-native-code-push">
183
+ + <img src="https://img.shields.io/badge/platforms-android%20|%20ios%20|%20windows%20|%20harmony%20-lightgrey.svg" alt="Supported platforms" />
184
+ + </a>
185
+ + <a href="https://github.com/microsoft/react-native-code-push/blob/master/LICENSE.md">
186
+ + <img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" />
187
+ + <!-- <img src="https://img.shields.io/badge/license-Apache-blue.svg" alt="License" /> -->
188
+ + </a>
189
+ +</p>
190
+
191
+ -[中文](https://gitcode.com/OpenHarmony-RN/usage-docs/blob/master/zh-cn/react-native-code-push.md)
192
+ +> [!TIP] [Github 地址](https://github.com/react-native-oh-library/react-native-code-push)
193
+
194
+ -[English](https://gitcode.com/OpenHarmony-RN/usage-docs/blob/master/en/react-native-code-push.md)
195
+ +该第三方库的仓库已迁移至 Gitcode,且支持直接从 npm 下载,新的包名为:`@react-native-ohos/react-native-code-push`,具体版本所属关系如下:
196
+
197
+ -## License
198
+ +| Version | Package Name | Repository | Release |Supported RN Version |
199
+ +| ------------------------------ | ---------------- | ------------------- | ------------------- | -------------------- |
200
+ +| <= 8.2.2-0.0.10@deprecated |@react-native-oh-tpl/react-native-code-push|[Github](https://github.com/react-native-oh-library/react-native-code-push/releases) | [Github Releases](https://github.com/react-native-oh-library/react-native-code-push/releases) | 0.72 |
201
+ +| 8.2.3 | @react-native-ohos/react-native-code-push|[GitCode](https://gitcode.com/openharmony-sig/rntpc_react-native-code-push) | [GitCode Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-code-push/releases) | 0.72 |
202
+ +| 9.0.2 | @react-native-ohos/react-native-code-push|[GitCode](https://gitcode.com/openharmony-sig/rntpc_react-native-code-push) | [GitCode Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-code-push/releases) | 0.77 |
203
+
204
+ -This project is based on [MIT License (MIT)](https://github.com/microsoft/react-native-code-push/blob/master/LICENSE.md)
205
+
206
+ +## 前期准备
207
+ +
208
+ +### code-push-cli
209
+ +
210
+ +1. 克隆 [code-push-cli](https://github.com/react-native-oh-library/code-push-cli) 到本地
211
+ +2. 在 code-push-cli 目录下执行 `npm install`
212
+ +3. 在 code-push-cli 目录下执行 `npm run start`,用于生成 `bin` 目录
213
+ +4. npm install -g <code-push-cli文件夹目录>
214
+ +5. 重开一个终端,执行 `code-push -v`,如正常输出版本号即安装成功
215
+ +
216
+ +code-push-cli常用命令:
217
+ +
218
+ +```
219
+ +code-push -v
220
+ +code-push login <服务器地址>
221
+ +code-push app list //列出账号下面的所有app
222
+ +code-push app add <apppname> harmony react-native //创建应用
223
+ +code-push release <AppName> <bundle.harmony.js> "<版本号>" --description "<v1.0.0 测试更新>" -m //发包命令,加-m是强制更新, * 代表所有版本,例如:code-push release CodePush_Local ./bundle.harmony.js "*" --description "v1.0.0 测试更新"
224
+ +```
225
+ +```
226
+ +在工程目录下执行如下
227
+ +
228
+ +code-push login <服务器地址> //前提为先启动服务器(公网)
229
+ +会拉起网页 输入账户和密码 账户默认为admin 密码123456
230
+ +点击获取token
231
+ +复制token到命令行窗口
232
+ +提示登录成功
233
+ +
234
+ +# 确保 bundle 文件有微小修改
235
+ +echo "// Force update for 1.0.0 pending fix - $(date)" >> ./bundles/bundle.harmony.js
236
+ +
237
+ +"// Force update for 1.0.0 pending fix - $(date)"修改这里的字符即可
238
+ +
239
+ +# 发布针对 1.0.0 的强制更新
240
+ +code-push release MyApp-Harmony ./bundles/bundle.harmony.js 1.0.0 -d Staging --description "强制解决问题" --mandatory
241
+ +
242
+ +# 发布针对 1.0.0 的非强制更新
243
+ +code-push release MyApp-Harmony ./bundles/bundle.harmony.js 1.0.0 -d Staging --description "非强制解决问题"
244
+ +
245
+ +```
246
+ +
247
+ +### code-push-server
248
+ +
249
+ +#### 推荐在服务器搭建
250
+ +
251
+ +1. 克隆 [code-push-server](https://github.com/react-native-oh-library/code-push-server) 到本地
252
+ +2. 在 code-push-server 目录下执行 `npm install`
253
+ +4. 安装 mysql、redis
254
+ +5. 修改 `code-push-server/src/core/config.ts` 配置文件
255
+ +3. 在 code-push-server 目录下执行 `npm run dev`,用于生成 `bin` 目录
256
+ +6. 在 code-push-server 目录下执行 `npm run start` 启动服务
257
+ +
258
+ +```
259
+ +安装mysql
260
+ +# Ubuntu/Debian
261
+ +sudo apt update
262
+ +sudo apt install mysql-server
263
+ +# 启动服务
264
+ +sudo systemctl start mysql
265
+ +sudo mysql_secure_installation
266
+ +# 按照提示设置:
267
+ +# 1. 设置 root 密码
268
+ +# 2. 移除匿名用户
269
+ +# 3. 禁止远程 root 登录
270
+ +# 4. 移除测试数据库
271
+ +# 5. 重新加载权限表
272
+ +先全部输入y/yes
273
+ +
274
+ +# 先登录MySQL(不需要密码)
275
+ +sudo mysql
276
+ +# 在MySQL命令行中执行:
277
+ +ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的强密码';
278
+ +FLUSH PRIVILEGES;
279
+ +EXIT;
280
+ +
281
+ +# 现在需要用密码登录
282
+ +mysql -u root -p
283
+ +输入密码
284
+ +EXIT;
285
+ +
286
+ +# 编辑配置文件
287
+ +sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
288
+ +# 找到 bind-address 并修改
289
+ +# bind-address = 0.0.0.0
290
+ +# 允许所有IP访问
291
+ +# Ctrl+S 保存并自动退出
292
+ +# 重启 MySQL
293
+ +
294
+ +sudo systemctl restart mysql
295
+ +
296
+ +安装redis
297
+ +sudo apt update
298
+ +sudo apt install redis-server -y
299
+ +
300
+ +# 启动并启用服务
301
+ +sudo systemctl start redis-server
302
+ +# 测试
303
+ +redis-cli ping
304
+ +回复PONG
305
+ +# 编辑Redis配置文件
306
+ +sudo nano /etc/redis/redis.conf
307
+ +
308
+ +# 找到并修改以下行:
309
+ +# bind 0.0.0.0 # 如果需要远程访问
310
+ +# protected-mode no # 如果设置bind 0.0.0.0,需要关闭保护模式
311
+ +# Ctrl+S 保存并自动退出
312
+ +# 重启Redis
313
+ +sudo systemctl restart redis-server
314
+ +```
315
+ +
316
+ +```
317
+ +修改文档部分
318
+ +code-push-server目录 code-push-server/src/core/config.ts <127.0.0.1> 改为服务器地址
319
+ +
320
+ +code-push-server/src/db.ts 例如 .example(
321
+ + '$0 init --dbname codepush --dbhost localhost(替换为服务器地址) --dbuser root --dbpassword <password>(替换为数据库密码) --dbport 3306 --force',
322
+ + '初始化code-push-server数据库',
323
+ + )
324
+ +在该文件中出现 localhost 字符 统一修改为服务器地址
325
+ +
326
+ +创建bin目录(可能会提示数据库codepush未创建)
327
+ +npm run dev (提示没有数据库codepush)Ctrl+C 强制退出
328
+ +执行
329
+ +npm run init 成功返回 success 创建数据库codepush
330
+ +执行
331
+ +npm run dev
332
+ +```
333
+ +
334
+ +## 安装与使用
335
+ +
336
+ +对于未发布到npm的旧版本,请参考[安装指南](./tgz-usage.md)安装tgz包。
337
+ +
338
+ +进入到工程目录并输入以下命令:
339
+ +
340
+ +<!-- tabs:start -->
341
+ +
342
+ +#### **npm**
343
+ +
344
+ +```bash
345
+ +npm install @react-native-ohos/react-native-code-push
346
+ +```
347
+ +
348
+ +#### **yarn**
349
+ +
350
+ +```bash
351
+ +yarn add @react-native-ohos/react-native-code-push
352
+ +```
353
+ +
354
+ +<!-- tabs:end -->
355
+ +
356
+ +下面的代码展示了这个库的基本使用场景:
357
+ +
358
+ +> [!WARNING] 使用时 import 的库名不变。
359
+ +
360
+ +```js
361
+ +
362
+ +import React, {Component} from 'react'
363
+ +import {View, Text, StyleSheet, TouchableOpacity} from 'react-native'
364
+ +import CodePush from 'react-native-code-push';
365
+ +class App extends Component<any,any>{
366
+ + constructor(props:any) {
367
+ + super(props);
368
+ + this.state={
369
+ + syncMessage:'',
370
+ + progress:{}
371
+ + }
372
+ + }
373
+ + componentDidMount() {
374
+ + console.log('开始检查更新')
375
+ + this.syncImmediate(); //开始检查更新
376
+ + }
377
+ + syncImmediate() {
378
+ + CodePush.sync(
379
+ + {
380
+ + updateDialog: {
381
+ + appendReleaseDescription: true, //是否显示更新description,默认为false
382
+ + descriptionPrefix: '更新内容:', //更新说明的前缀。 默认是” Description:
383
+ + mandatoryContinueButtonLabel: '立即更新', //强制更新的按钮文字,默认为continue
384
+ + mandatoryUpdateMessage: '', //- 强制更新时,更新通知. Defaults to “An update is available that must be installed.”.
385
+ + optionalIgnoreButtonLabel: '稍后', //非强制更新时,取消按钮文字,默认是ignore
386
+ + optionalInstallButtonLabel: '后台更新', //非强制更新时,确认文字. Defaults to “Install”
387
+ + optionalUpdateMessage: '有新版本了,是否更新?', //非强制更新时,更新通知. Defaults to “An update is available. Would you like to install it?”.
388
+ + title: '更新提示', //要显示的更新通知的标题. Defaults to “Update available”.
389
+ + },
390
+ + },
391
+ + this.codePushStatusDidChange.bind(this),
392
+ + this.codePushDownloadDidProgress.bind(this),
393
+ + );
394
+ + }
395
+ +
396
+ + codePushStatusDidChange(syncStatus:string|number) {
397
+ + switch (syncStatus) {
398
+ + case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
399
+ + this.setState({syncMessage: 'Checking for update.'});
400
+ + break;
401
+ + case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
402
+ + this.setState({syncMessage: 'Downloading package.',progressModalVisible:true});
403
+ + break;
404
+ + case CodePush.SyncStatus.AWAITING_USER_ACTION:
405
+ + this.setState({syncMessage: 'Awaiting user action.'});
406
+ + break;
407
+ + case CodePush.SyncStatus.INSTALLING_UPDATE:
408
+ + this.setState({syncMessage: 'Installing update.',progressModalVisible:true});
409
+ + break;
410
+ + case CodePush.SyncStatus.UP_TO_DATE:
411
+ + this.setState({syncMessage: 'App up to date.', progress: false});
412
+ + break;
413
+ + case CodePush.SyncStatus.UPDATE_IGNORED:
414
+ + this.setState({syncMessage: 'Update cancelled by user.', progress: false,});
415
+ + break;
416
+ + case CodePush.SyncStatus.UPDATE_INSTALLED:
417
+ + this.setState({syncMessage: 'Update installed and will be applied on restart.', progress: false,});
418
+ + break;
419
+ + case CodePush.SyncStatus.UNKNOWN_ERROR:
420
+ + this.setState({syncMessage: 'An unknown error occurred.', progress: false,});
421
+ + break;
422
+ + }
423
+ + }
424
+ +
425
+ + codePushDownloadDidProgress(progress:any) {
426
+ + this.setState({progress});
427
+ + }
428
+ +
429
+ + render(){
430
+ + return(
431
+ + <View style={styles.container}>
432
+ + <Text style={styles.welcome}>欢迎使用热更新--test!</Text>
433
+ + <Text>SyncStatus: { this.state.syncMessage}</Text>
434
+ + <Text>{this.state.progressModalVisible.toString()}</Text>
435
+ + <TouchableOpacity onPress={this.syncImmediate.bind(this)}>
436
+ + <Text style={styles.syncButton}>Press for dialog-driven sync</Text>
437
+ + </TouchableOpacity>
438
+ + </View>
439
+ + )
440
+ + }
441
+ +}
442
+ +
443
+ +const styles = StyleSheet.create({
444
+ + container:{
445
+ + flex: 1,
446
+ + alignItems: 'center',
447
+ + backgroundColor: '#F5FCFF',
448
+ + paddingTop: 10,
449
+ + },
450
+ + welcome:{
451
+ + fontSize: 20,
452
+ + textAlign: 'center',
453
+ + margin: 10,
454
+ + },
455
+ + syncButton: {
456
+ + color: 'green',
457
+ + fontSize: 17,
458
+ + },
459
+ +})
460
+ +
461
+ +let codePushOptions = {checkFrequency: CodePush.CheckFrequency.MANUAL};
462
+ +
463
+ +
464
+ +export default CodePush(codePushOptions)(App);
465
+ +
466
+ +```
467
+ +
468
+ +## 使用 Codegen
469
+ +
470
+ +本库已经适配了 `Codegen` ,在使用前需要主动执行生成三方库桥接代码,详细请参考[ Codegen 使用文档](./codegen.md)。
471
+ +
472
+ +## Link
473
+ +
474
+ +| | 是否支持autolink | RN框架版本 |
475
+ +|--------------------------------------|-----------------|------------|
476
+ +| ~9.0.2 | No | 0.77 |
477
+ +| ~8.2.3 | Yes | 0.72 |
478
+ +| <= 8.2.2-0.0.10@deprecated | No | 0.72 |
479
+ +
480
+ +使用AutoLink的工程需要根据该文档配置,Autolink框架指导文档:https://gitcode.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md
481
+ +
482
+ +如您使用的版本支持 Autolink,并且工程已接入 Autolink,可跳过ManualLink配置。
483
+ +<details>
484
+ + <summary>ManualLink: 此步骤为手动配置原生依赖项的指导</summary>
485
+ +
486
+ +首先需要使用 DevEco Studio 打开项目里的 HarmonyOS 工程 `harmony`
487
+ +
488
+ +### 1.在工程根目录的 `oh-package.json5` 添加 overrides 字段
489
+ +
490
+ +```json
491
+ +{
492
+ + ...
493
+ + "overrides": {
494
+ + "@rnoh/react-native-openharmony" : "./react_native_openharmony"
495
+ + }
496
+ +}
497
+ +```
498
+ +
499
+ +### 2.引入原生端代码
500
+ +
501
+ +目前有两种方法:
502
+ +
503
+ +1. 通过 har 包引入(在 IDE 完善相关功能后该方法会被遗弃,目前首选此方法);
504
+ +2. 直接链接源码。
505
+ +
506
+ +方法一:通过 har 包引入(推荐)
507
+ +
508
+ +> [!TIP] har 包位于三方库安装路径的 `harmony` 文件夹下。
509
+ +
510
+ +打开 `entry/oh-package.json5`,添加以下依赖
511
+ +
512
+ +```json
513
+ +"dependencies": {
514
+ + "@rnoh/react-native-openharmony": "file:../react_native_openharmony",
515
+ + "@react-native-ohos/react-native-code-push": "file:../../node_modules/@react-native-ohos/react-native-code-push/harmony/codePush.har"
516
+ + }
517
+ +```
518
+ +
519
+ +点击右上角的 `sync` 按钮
520
+ +
521
+ +或者在终端执行:
522
+ +
523
+ +```bash
524
+ +cd entry
525
+ +ohpm install
526
+ +```
527
+ +
528
+ +方法二:直接链接源码
529
+ +
530
+ +> [!TIP] 如需使用直接链接源码,请参考[直接链接源码说明](./link-source-code.md)
531
+ +
532
+ +### 3.在 ArkTs 侧引入 CodePushPackage
533
+ +
534
+ +打开 `entry/src/main/ets/RNPackagesFactory.ts`,添加:
535
+ +
536
+ +```diff
537
+ + ...
538
+ ++ import { CodePushPackage } from "@react-native-ohos/react-native-code-push/ts";
539
+ +
540
+ +export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
541
+ + return [
542
+ + new SamplePackage(ctx),
543
+ ++ new CodePushPackage(ctx)
544
+ + ];
545
+ +}
546
+ +```
547
+ +### 4.配置 CMakeLists 和引入 CodePushPackage
548
+ +
549
+ +> 若使用的是 <= 8.2.2-0.0.10 版本,请跳过本章。
550
+ +
551
+ +打开 `entry/src/main/cpp/CMakeLists.txt`,添加:
552
+ +
553
+ +```diff
554
+ +project(rnapp)
555
+ +cmake_minimum_required(VERSION 3.4.1)
556
+ +set(CMAKE_SKIP_BUILD_RPATH TRUE)
557
+ +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
558
+ +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
559
+ ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
560
+ +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
561
+ +set(LOG_VERBOSITY_LEVEL 1)
562
+ +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
563
+ +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
564
+ +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
565
+ +add_compile_definitions(WITH_HITRACE_SYSTRACE)
566
+ +
567
+ +add_subdirectory("${RNOH_CPP_DIR}" ./rn)
568
+ +
569
+ +# RNOH_BEGIN: manual_package_linking_1
570
+ +add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
571
+ ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-code-push/src/main/cpp" ./codePush)
572
+ +
573
+ +# RNOH_END: manual_package_linking_1
574
+ +
575
+ +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp")
576
+ +
577
+ +add_library(rnoh_app SHARED
578
+ + ${GENERATED_CPP_FILES}
579
+ + "./PackageProvider.cpp"
580
+ + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
581
+ +)
582
+ +target_link_libraries(rnoh_app PUBLIC rnoh)
583
+ +
584
+ +# RNOH_BEGIN: manual_package_linking_2
585
+ +target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
586
+ ++ target_link_libraries(rnoh_app PUBLIC rnoh_code_push)
587
+ +# RNOH_END: manual_package_linking_2
588
+ +```
589
+ +打开 `entry/src/main/cpp/PackageProvider.cpp`,添加:
590
+ +
591
+ +```diff
592
+ +#include "RNOH/PackageProvider.h"
593
+ +#include "generated/RNOHGeneratedPackage.h"
594
+ +#include "SamplePackage.h"
595
+ ++ #include "CodePushPackage.h"
596
+ +
597
+ +using namespace rnoh;
598
+ +
599
+ +std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
600
+ + return {
601
+ + std::make_shared<RNOHGeneratedPackage>(ctx),
602
+ + std::make_shared<SamplePackage>(ctx),
603
+ ++ std::make_shared<CodePushPackage>(ctx)
604
+ + };
605
+ +}
606
+ +```
607
+ +### 5.在 ArkTs 侧引入 comparingVersion 方法
608
+ +
609
+ +打开 `entry/src/main/ets/pages/index.ets`,调用 comparingVersion 方法比对code-push版本号,用于覆盖安装时清除沙箱历史资源
610
+ +
611
+ +```diff
612
+ ++ import { comparingVersion } from "@react-native-ohos/react-native-code-push";
613
+ +
614
+ +@Entry
615
+ +@Component
616
+ +struct Index {
617
+ +
618
+ + aboutToAppear() {
619
+ ++ comparingVersion(context);
620
+ + }
621
+ +}
622
+ +```
623
+ +</details>
624
+ +
625
+ +## 运行
626
+ +
627
+ +点击右上角的 `sync` 按钮
628
+ +
629
+ +或者在终端执行:
630
+ +
631
+ +```bash
632
+ +cd entry
633
+ +ohpm install
634
+ +```
635
+ +
636
+ +修改`entry\src\main\ets\pages\Index.ets`文件
637
+ +
638
+ +```diff
639
+ +...
640
+ ++ import common from '@ohos.app.ability.common';
641
+ ++ import BuildProfile from 'BuildProfile';
642
+ ++ let context = getContext(this) as common.UIAbilityContext;
643
+ ++ interface CodePushConfig{
644
+ ++ Staging:String;
645
+ ++ Production:String;
646
+ ++ ServerUrl:String;
647
+ ++ PublicKey:String;
648
+ ++ }
649
+ +struct Index {
650
+ + @StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
651
+ + @State shouldShow: boolean = false
652
+ + private logger!: RNOHLogger
653
+ ++ bundlePath:string = 'bundle.harmony.js'
654
+ +aboutToAppear() {
655
+ + ...
656
+ ++ this.setCodeConfig()
657
+ + this.shouldShow = true
658
+ + stopTracing()
659
+ + }
660
+ ++ setCodeConfig(){
661
+ ++ const CodePushConfig: CodePushConfig = {
662
+ ++ Staging:BuildProfile.Staging,
663
+ ++ Production:BuildProfile.Production,
664
+ ++ ServerUrl:BuildProfile.ServerUrl,
665
+ ++ PublicKey:BuildProfile.PublicKey
666
+ ++ }
667
+ ++ AppStorage.SetOrCreate('CodePushConfig',CodePushConfig)
668
+ ++ }
669
+ +build() {
670
+ + Column() {
671
+ + ...
672
+ + RNApp({
673
+ + jsBundleProvider:new TraceJSBundleProviderDecorator(
674
+ + new AnyJSBundleProvider([
675
+ + new MetroJSBundleProvider(),
676
+ + // NOTE: to load the bundle from file, place it in
677
+ + // `/data/app/el2/100/base/com.rnoh.tester/files/bundle.harmony.js`
678
+ + // on your device. The path mismatch is due to app sandboxing on HarmonyOS
679
+ ++ new FileJSBundleProvider(context.filesDir + '/Bundles/' + this.bundlePath),
680
+ + new FileJSBundleProvider('/data/storage/el2/base/files/bundle.harmony.js'),
681
+ + new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
682
+ + new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
683
+ + ]),
684
+ + this.rnohCoreContext.logger),
685
+ + })
686
+ +
687
+ + }
688
+ +
689
+ +}
690
+ +```
691
+ +
692
+ +打开`entry/build-profile.json5`,添加配置
693
+ +
694
+ +```diff
695
+ +{
696
+ + "apiType": 'stageMode',
697
+ + "buildOption": {
698
+ + "externalNativeOptions": {
699
+ + "path": "./src/main/cpp/CMakeLists.txt",
700
+ + "arguments": "",
701
+ + "cppFlags": "-s",
702
+ + },
703
+ ++ "arkOptions": {
704
+ ++ "buildProfileFields": {
705
+ ++ "Staging": "", //测试环境Key
706
+ ++ "Production": "",//生产环境Key
707
+ ++ "ServerUrl": "",//服务端地址
708
+ ++ "PublicKey": "PublicKey"
709
+ + }
710
+ + }
711
+ + },
712
+ + "targets": [
713
+ + {
714
+ + "name": "default",
715
+ + "runtimeOS": "HarmonyOS"
716
+ + },
717
+ + {
718
+ + "name": "ohosTest",
719
+ + }
720
+ + ]
721
+ +}
722
+ +```
723
+ +
724
+ +然后编译、运行即可。
725
+ +
726
+ +## 约束与限制
727
+ +
728
+ +### 兼容性
729
+ +
730
+ +要使用此库,需要使用正确的 React-Native 和 RNOH 版本。另外,还需要使用配套的 DevEco Studio 和 手机 ROM。
731
+ +
732
+ +在以下版本验证通过:
733
+ +
734
+ +1. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
735
+ +2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio: 5.0.3.900; ROM: Next.0.0.71;
736
+ +3. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
737
+ +
738
+ +## API
739
+ +
740
+ +| Name | Description | Type | Required | Platform | HarmonyOS Support |
741
+ +| ----------------- | ---------------------------------------------------------------------------------------------------------------------------- | -------- | -------- | --------------------------------------- | ----------------- |
742
+ +| sync | sync方法,自动模式更新 | function | yes | Android IOS | yes |
743
+ +| getUpdateMetadata | 获取当前已安装更新的元数据(RemotePackage),当使用sync方法时,不需要调用本方法,因为sync会自动调用 | function | no | Android iOS | yes |
744
+ +| restartApp | 重启App,当使用sync方法时,不需要调用本方法,因为sync会自动调用 | function | no | Android iOS | yes |
745
+ +| getCurrentPackage | 获取应用版本信息,当使用sync方法时,不需要调用本方法,因为sync会自动调用 | function | no | Android iOS | yes |
746
+ +| getConfiguration | 获取应用配置信息,appVersion(版本号),deploymentKey(deploymentKey),serverUrl(服务器地址),clientUniqueId(唯一标识码),当使用sync方法时,不需要调用本方法,因为sync会自动调用 | function | no | Android iOS | yes |
747
+ +
748
+ +**updateDialog**
749
+ +
750
+ +当使用**CodePush.updateDialog**方法时,updateDialog以下参数都是可选的,代表更新的对话框,默认是null,
751
+ +
752
+ +| Name | Description | Type | Required | Platform | HarmonyOS Support |
753
+ +| ---------------------------- | -------------------------------------------------------------------------------- | ------- | -------- | ----------- | ----------------- |
754
+ +| appendReleaseDescription | 是否显示更新description,默认为false | boolean | no | Android iOS | yes |
755
+ +| descriptionPrefix | 更新说明的前缀。 默认是” Description: | string | no | Android iOS | yes |
756
+ +| mandatoryContinueButtonLabel | 强制更新的按钮文字,默认为continue | string | no | Android iOS | yes |
757
+ +| mandatoryUpdateMessage | 强制更新时,更新通知. Defaults to “An update is available that must be installed.” | string | no | Android iOS | yes
758
+ ... [diff 已截断]
759
+ ```
760
+
761
+ ### `README_en.md`
762
+
763
+ ```diff
764
+ @@ -0,0 +1,627 @@
765
+ +> Template version: v0.2.2
766
+ +
767
+ +<p align="center">
768
+ + <h1 align="center"> <code>react-native-code-push</code> </h1>
769
+ +</p>
770
+ +<p align="center">
771
+ + <a href="https://github.com/microsoft/react-native-code-push">
772
+ + <img src="https://img.shields.io/badge/platforms-android%20|%20ios%20|%20windows%20|%20harmony%20-lightgrey.svg" alt="Supported platforms" />
773
+ + </a>
774
+ + <a href="https://github.com/microsoft/react-native-code-push/blob/master/LICENSE.md">
775
+ + <img src="https://img.shields.io/badge/license-MIT-green.svg" alt="License" />
776
+ + <!-- <img src="https://img.shields.io/badge/license-Apache-blue.svg" alt="License" /> -->
777
+ + </a>
778
+ +</p>
779
+ +
780
+ +> [!TIP] [Github address](https://github.com/react-native-oh-library/react-native-code-push)
781
+ +
782
+ +The repository for this third-party library has been migrated to Gitcode, and it now supports direct download from npm. The new package name is: `@react-native-ohos/react-native-code-push`. The specific version relationships are as follows:
783
+ +
784
+ +| Version | Package Name | Repository | Release |Supported RN Version |
785
+ +| ------------------------------ | ---------------- | ------------------- | ------------------- | -------------------- |
786
+ +| <= 8.2.2-0.0.10@deprecated |@react-native-oh-tpl/react-native-code-push|[Github](https://github.com/react-native-oh-library/react-native-code-push/releases) | [Github Releases](https://github.com/react-native-oh-library/react-native-code-push/releases) | 0.72 |
787
+ +| 8.2.3 | @react-native-ohos/react-native-code-push|[GitCode](https://gitcode.com/openharmony-sig/rntpc_react-native-code-push) | [GitCode Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-code-push/releases) | 0.72 |
788
+ +| 9.0.2 | @react-native-ohos/react-native-code-push|[GitCode](https://gitcode.com/openharmony-sig/rntpc_react-native-code-push) | [GitCode Releases](https://gitcode.com/openharmony-sig/rntpc_react-native-code-push/releases) | 0.77 |
789
+ +
790
+ +## Pre-preparation
791
+ +
792
+ +### code-push-cli
793
+ +
794
+ +1. Clone the [code-push-cli](https://github.com/react-native-oh-library/code-push-cli) to the local host.
795
+ +2. Run the `npm install` command in the code-push-cli directory.
796
+ +3. Run the `npm run start` command in the code-push-cli directory to generate the `bin` directory.
797
+ +4. npm install -g <code-push-cli directory>
798
+ +5. Restart a terminal and run the `code-push -v` command. If the version number is displayed, the installation is successful.
799
+ +
800
+ +Common commands for code-push-cli are as follows:
801
+ +
802
+ +```
803
+ +code-push -v
804
+ +code-push login
805
+ +code-push app list //List all apps under the account.
806
+ +code-push app add <apppname> harmony react-native // Creating an Application
807
+ +code-push release <AppName> <bundle.harmony.js> "< version number > "--description "<v1.0.0 test update >" -m //Packet sending command. Add -m to forcibly update the version. The asterisk (*) indicates all versions, for example, code-push release CodePush_Local ./bundle.harmony.js "*" --description "v1.0.0 Test Update"
808
+ +```
809
+ +```
810
+ +Execute the following commands in the project directory:
811
+ +
812
+ +code-push login <server_address> // Prerequisite: Server must be started (public network accessible)
813
+ +This will open a webpage. Enter account and password (default account: admin, password: 123456)
814
+ +Click "Get token"
815
+ +Copy the token to the command line window
816
+ +Prompt shows login successful
817
+ +
818
+ +# Ensure the bundle file has minor modifications
819
+ +echo "// Force update for 1.0.0 pending fix - $(date)" >> ./bundles/bundle.harmony.js
820
+ +
821
+ +Modify the characters in "// Force update for 1.0.0 pending fix - $(date)" as needed
822
+ +
823
+ +# Publish a mandatory update for version 1.0.0
824
+ +code-push release MyApp-Harmony ./bundles/bundle.harmony.js 1.0.0 -d Staging --description "Force fix for issues" --mandatory
825
+ +
826
+ +# Publish a non-mandatory update for version 1.0.0
827
+ +code-push release MyApp-Harmony ./bundles/bundle.harmony.js 1.0.0 -d Staging --description "Non-mandatory fix for issues"
828
+ +
829
+ +```
830
+ +### code-push-server
831
+ +
832
+ +1. Clone the [code-push-server](https://github.com/react-native-oh-library/code-push-server) to the local host.
833
+ +2. Run the `npm install` command in the code-push-server directory.
834
+ +3. Install the MySQL and Redis.
835
+ +4. Modifying the `code-push-server/src/core/config.ts` Configuration File
836
+ +5. Run the `npm run dev` command in the code-push-server directory to generate the `bin` directory.
837
+ +6. Run the `npm run start` command in the code-push-server directory to start the service.
838
+ +```
839
+ +Install MySQL
840
+ +# Ubuntu/Debian
841
+ +sudo apt update
842
+ +sudo apt install mysql-server
843
+ +# Start service
844
+ +sudo systemctl start mysql
845
+ +sudo mysql_secure_installation
846
+ +# Follow the prompts to set up:
847
+ +# 1. Set root password
848
+ +# 2. Remove anonymous users
849
+ +# 3. Disallow remote root login
850
+ +# 4. Remove test database
851
+ +# 5. Reload privilege tables
852
+ +First enter y/yes for all
853
+ +
854
+ +# First log in to MySQL (no password required)
855
+ +sudo mysql
856
+ +# Execute in MySQL command line:
857
+ +ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_strong_password';
858
+ +FLUSH PRIVILEGES;
859
+ +EXIT;
860
+ +
861
+ +# Now log in with password
862
+ +mysql -u root -p
863
+ +Enter password
864
+ +EXIT;
865
+ +
866
+ +# Edit configuration file
867
+ +sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
868
+ +# Find bind-address and modify
869
+ +# bind-address = 0.0.0.0
870
+ +# Allow all IP access
871
+ +# Ctrl+S to save and exit automatically
872
+ +# Restart MySQL
873
+ +
874
+ +sudo systemctl restart mysql
875
+ +
876
+ +Install Redis
877
+ +sudo apt update
878
+ +sudo apt install redis-server -y
879
+ +
880
+ +# Start and enable service
881
+ +sudo systemctl start redis-server
882
+ +# Test
883
+ +redis-cli ping
884
+ +Should reply PONG
885
+ +# Edit Redis configuration file
886
+ +sudo nano /etc/redis/redis.conf
887
+ +
888
+ +# Find and modify the following lines:
889
+ +# bind 0.0.0.0 # If remote access is needed
890
+ +# protected-mode no # If bind is set to 0.0.0.0, need to turn off protected mode
891
+ +# Ctrl+S to save and exit automatically
892
+ +# Restart Redis
893
+ +sudo systemctl restart redis-server
894
+ +```
895
+ +
896
+ +```
897
+ +Modify document sections
898
+ +In the code-push-server directory, modify code-push-server/src/core/config.ts <127.0.0.1> Change to server address
899
+ +
900
+ +In code-push-server/src/db.ts, for example:
901
+ + .example(
902
+ + '$0 init --dbname codepush --dbhost localhost (replace with server address) --dbuser root --dbpassword <password> (replace with database password) --dbport 3306 --force',
903
+ + 'Initialize code-push-server database',
904
+ + )
905
+ +In this file, replace all occurrences of 'localhost' with server address
906
+ +
907
+ +Create bin directory (might prompt that database codepush is not created)
908
+ +npm run dev (prompts that database codepush doesn't exist) Ctrl+C to force exit
909
+ +Execute
910
+ +npm run init Success returns "success" and creates database codepush
911
+ +Execute
912
+ +npm run dev
913
+ +```
914
+ +
915
+ +## Installation and Usage
916
+ +
917
+ +For older versions not published on npm, please refer to the [Installation Guide](./tgz-usage-en.md) to install the tgz package.
918
+ +
919
+ +Go to the project directory and execute the following instruction:
920
+ +
921
+ +
922
+ +
923
+ +<!-- tabs:start -->
924
+ +
925
+ +#### **npm**
926
+ +
927
+ +```bash
928
+ +npm install @react-native-ohos/react-native-code-push
929
+ +```
930
+ +
931
+ +#### **yarn**
932
+ +
933
+ +```bash
934
+ +yarn add @react-native-ohos/react-native-code-push
935
+ +```
936
+ +
937
+ +<!-- tabs:end -->
938
+ +
939
+ +The following code shows the basic use scenario of the repository:
940
+ +
941
+ +> [!WARNING] The name of the imported repository remains unchanged.
942
+ +
943
+ +```js
944
+ +import React, { Component } from "react";
945
+ +import { View, Text, StyleSheet, TouchableOpacity } from "react-native";
946
+ +import CodePush from "react-native-code-push";
947
+ +class App extends Component<any, any> {
948
+ + constructor(props: any) {
949
+ + super(props);
950
+ + this.state = {
951
+ + syncMessage: "",
952
+ + progress: {},
953
+ + };
954
+ + }
955
+ + componentDidMount() {
956
+ + console.log("Begin checking for updates.");
957
+ + this.syncImmediate();
958
+ + }
959
+ + syncImmediate() {
960
+ + CodePush.sync(
961
+ + {
962
+ + updateDialog: {
963
+ + appendReleaseDescription: true,
964
+ + descriptionPrefix: "Update content:",
965
+ + mandatoryContinueButtonLabel: "Update immediately.",
966
+ + mandatoryUpdateMessage: "",
967
+ + optionalIgnoreButtonLabel: "later",
968
+ + optionalInstallButtonLabel: "Background update.",
969
+ + optionalUpdateMessage: "There's a new version available. Would you like to update?",
970
+ + title: "Update notification.",
971
+ + },
972
+ + },
973
+ + this.codePushStatusDidChange.bind(this),
974
+ + this.codePushDownloadDidProgress.bind(this)
975
+ + );
976
+ + }
977
+ +
978
+ + codePushStatusDidChange(syncStatus: string | number) {
979
+ + switch (syncStatus) {
980
+ + case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
981
+ + this.setState({ syncMessage: "Checking for update." });
982
+ + break;
983
+ + case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
984
+ + this.setState({
985
+ + syncMessage: "Downloading package.",
986
+ + progressModalVisible: true,
987
+ + });
988
+ + break;
989
+ + case CodePush.SyncStatus.AWAITING_USER_ACTION:
990
+ + this.setState({ syncMessage: "Awaiting user action." });
991
+ + break;
992
+ + case CodePush.SyncStatus.INSTALLING_UPDATE:
993
+ + this.setState({
994
+ + syncMessage: "Installing update.",
995
+ + progressModalVisible: true,
996
+ + });
997
+ + break;
998
+ + case CodePush.SyncStatus.UP_TO_DATE:
999
+ + this.setState({ syncMessage: "App up to date.", progress: false });
1000
+ + break;
1001
+ + case CodePush.SyncStatus.UPDATE_IGNORED:
1002
+ + this.setState({
1003
+ + syncMessage: "Update cancelled by user.",
1004
+ + progress: false,
1005
+ + });
1006
+ + break;
1007
+ + case CodePush.SyncStatus.UPDATE_INSTALLED:
1008
+ + this.setState({
1009
+ + syncMessage: "Update installed and will be applied on restart.",
1010
+ + progress: false,
1011
+ + });
1012
+ + break;
1013
+ + case CodePush.SyncStatus.UNKNOWN_ERROR:
1014
+ + this.setState({
1015
+ + syncMessage: "An unknown error occurred.",
1016
+ + progress: false,
1017
+ + });
1018
+ + break;
1019
+ + }
1020
+ + }
1021
+ +
1022
+ + codePushDownloadDidProgress(progress: any) {
1023
+ + this.setState({ progress });
1024
+ + }
1025
+ +
1026
+ + render() {
1027
+ + return (
1028
+ + <View style={styles.container}>
1029
+ + <Text style={styles.welcome}>Welcome to the hot update--test!</Text>
1030
+ + <Text>SyncStatus: {this.state.syncMessage}</Text>
1031
+ + <Text>{this.state.progressModalVisible.toString()}</Text>
1032
+ + <TouchableOpacity onPress={this.syncImmediate.bind(this)}>
1033
+ + <Text style={styles.syncButton}>Press for dialog-driven sync</Text>
1034
+ + </TouchableOpacity>
1035
+ + </View>
1036
+ + );
1037
+ + }
1038
+ +}
1039
+ +
1040
+ +const styles = StyleSheet.create({
1041
+ + container: {
1042
+ + flex: 1,
1043
+ + alignItems: "center",
1044
+ + backgroundColor: "#F5FCFF",
1045
+ + paddingTop: 10,
1046
+ + },
1047
+ + welcome: {
1048
+ + fontSize: 20,
1049
+ + textAlign: "center",
1050
+ + margin: 10,
1051
+ + },
1052
+ + syncButton: {
1053
+ + color: "green",
1054
+ + fontSize: 17,
1055
+ + },
1056
+ +});
1057
+ +
1058
+ +let codePushOptions = { checkFrequency: CodePush.CheckFrequency.MANUAL };
1059
+ +
1060
+ +export default CodePush(codePushOptions)(App);
1061
+ +```
1062
+ +
1063
+ +## Use Codegen
1064
+ +
1065
+ +This library has been adapted for `Codegen`. Before using it, you need to proactively generate the bridge code for the third-party library. For details, please refer to the [Codegen Usage Documentation](./codegen.md).
1066
+ +
1067
+ +## Link
1068
+ +
1069
+ +| | Is supported autolink | Supported RN Version |
1070
+ +|--------------------------------------|-----------------------|----------------------|
1071
+ +| ~9.0.2 | No | 0.77 |
1072
+ +| ~8.2.3 | Yes | 0.72 |
1073
+ +| <= 8.2.2-0.0.10@deprecated | No | 0.72 |
1074
+ +
1075
+ +Using AutoLink need to be configured according to this document, Autolink Framework Guide Documentation: https://gitcode.com/openharmony-sig/ohos_react_native/blob/master/docs/zh-cn/Autolinking.md
1076
+ +
1077
+ +If the version you use supports Autolink and the project has been connected to Autolink, skip the ManualLink configuration.
1078
+ +<details>
1079
+ + <summary>ManualLink: this step is a guide to manually configure native dependencies.</summary>
1080
+ +
1081
+ +Open the `harmony` directory of the HarmonyOS project in DevEco Studio.
1082
+ +
1083
+ +### 1. Adding the overrides Field to oh-package.json5 File in the Root Directory of the Project
1084
+ +
1085
+ +```json
1086
+ +{
1087
+ + ...
1088
+ + "overrides": {
1089
+ + "@rnoh/react-native-openharmony" : "./react_native_openharmony"
1090
+ + }
1091
+ +}
1092
+ +```
1093
+ +
1094
+ +### 2. Introducing Native Code
1095
+ +
1096
+ +Currently, two methods are available:
1097
+ +
1098
+ +Method 1 (recommended): Use the HAR file.
1099
+ +
1100
+ +> [!TIP] The HAR file is stored in the `harmony` directory in the installation path of the third-party library.
1101
+ +
1102
+ +Open `entry/oh-package.json5` file and add the following dependencies:
1103
+ +
1104
+ +```json
1105
+ +"dependencies": {
1106
+ + "@rnoh/react-native-openharmony": "file:../react_native_openharmony",
1107
+ + "@react-native-ohos/react-native-code-push": "file:../../node_modules/@react-native-ohos/react-native-code-push/harmony/codePush.har"
1108
+ + }
1109
+ +```
1110
+ +
1111
+ +Click the `sync` button in the upper right corner.
1112
+ +
1113
+ +Alternatively, run the following instruction on the terminal:
1114
+ +
1115
+ +```bash
1116
+ +cd entry
1117
+ +ohpm install
1118
+ +```
1119
+ +
1120
+ +Method 2: Directly link to the source code.
1121
+ +
1122
+ +> [!TIP] For details, see [Directly Linking Source Code](./link-source-code.md).
1123
+ +
1124
+ +### 3. Introducing CodePushPackage to ArkTS
1125
+ +
1126
+ +Open the `entry/src/main/ets/RNPackagesFactory.ts` file and add the following code:
1127
+ +
1128
+ +```diff
1129
+ + ...
1130
+ ++ import { CodePushPackage } from "@react-native-ohos/react-native-code-push/ts";
1131
+ +
1132
+ +export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
1133
+ + return [
1134
+ + new SamplePackage(ctx),
1135
+ ++ new CodePushPackage(ctx)
1136
+ + ];
1137
+ +}
1138
+ +```
1139
+ +
1140
+ +### 4. Configuring CMakeLists and Introducing CodePushPackage
1141
+ +
1142
+ +> If you are using version <= 8.2.2-0.0.10, please skip this chapter.
1143
+ +
1144
+ +Open `entry/src/main/cpp/CMakeLists.txt` and add the following code:
1145
+ +
1146
+ +```diff
1147
+ +project(rnapp)
1148
+ +cmake_minimum_required(VERSION 3.4.1)
1149
+ +set(CMAKE_SKIP_BUILD_RPATH TRUE)
1150
+ +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
1151
+ +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
1152
+ ++ set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
1153
+ +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../react-native-harmony/harmony/cpp")
1154
+ +set(LOG_VERBOSITY_LEVEL 1)
1155
+ +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
1156
+ +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
1157
+ +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
1158
+ +add_compile_definitions(WITH_HITRACE_SYSTRACE)
1159
+ +
1160
+ +add_subdirectory("${RNOH_CPP_DIR}" ./rn)
1161
+ +
1162
+ +# RNOH_BEGIN: manual_package_linking_1
1163
+ +add_subdirectory("../../../../sample_package/src/main/cpp" ./sample-package)
1164
+ ++ add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-code-push/src/main/cpp" ./codePush)
1165
+ +
1166
+ +# RNOH_END: manual_package_linking_1
1167
+ +
1168
+ +file(GLOB GENERATED_CPP_FILES "./generated/*.cpp")
1169
+ +
1170
+ +add_library(rnoh_app SHARED
1171
+ + ${GENERATED_CPP_FILES}
1172
+ + "./PackageProvider.cpp"
1173
+ + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
1174
+ +)
1175
+ +target_link_libraries(rnoh_app PUBLIC rnoh)
1176
+ +
1177
+ +# RNOH_BEGIN: manual_package_linking_2
1178
+ +target_link_libraries(rnoh_app PUBLIC rnoh_sample_package)
1179
+ ++ target_link_libraries(rnoh_app PUBLIC rnoh_code_push)
1180
+ +# RNOH_END: manual_package_linking_2
1181
+ +```
1182
+ +
1183
+ +Open `entry/src/main/cpp/PackageProvider.cpp` and add the following code:
1184
+ +
1185
+ +```diff
1186
+ +#include "RNOH/PackageProvider.h"
1187
+ +#include "generated/RNOHGeneratedPackage.h"
1188
+ +#include "SamplePackage.h"
1189
+ ++ #include "CodePushPackage.h"
1190
+ +
1191
+ +using namespace rnoh;
1192
+ +
1193
+ +std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
1194
+ + return {
1195
+ + std::make_shared<RNOHGeneratedPackage>(ctx),
1196
+ + std::make_shared<SamplePackage>(ctx),
1197
+ ++ std::make_shared<CodePushPackage>(ctx)
1198
+ + };
1199
+ +}
1200
+ +```
1201
+ +
1202
+ +### 5. Introduce the comparingVersion method on the ArkTs side
1203
+ +
1204
+ +Open `entry/src/main/ets/pages/index.ets` and invoke the comparingVersion method to compare the code-push version number to clear historical sandbox resources during installation.
1205
+ +
1206
+ +```diff
1207
+ ++ import { comparingVersion } from "@react-native-ohos/react-native-code-push";
1208
+ +
1209
+ +@Entry
1210
+ +@Component
1211
+ +struct Index {
1212
+ +
1213
+ + aboutToAppear() {
1214
+ ++ comparingVersion(context);
1215
+ + }
1216
+ +}
1217
+ +```
1218
+ +</details>
1219
+ +
1220
+ +## Running
1221
+ +
1222
+ +Click the `sync` button in the upper right corner.
1223
+ +
1224
+ +Alternatively, run the following instruction on the terminal:
1225
+ +
1226
+ +```bash
1227
+ +cd entry
1228
+ +ohpm install
1229
+ +```
1230
+ +
1231
+ +Modifying the `entry\src\main\ets\pages\Index.ets` file.
1232
+ +
1233
+ +```diff
1234
+ +...
1235
+ ++ import common from '@ohos.app.ability.common';
1236
+ ++ import BuildProfile from 'BuildProfile';
1237
+ ++ let context = getContext(this) as common.UIAbilityContext;
1238
+ ++ interface CodePushConfig{
1239
+ ++ Staging:String;
1240
+ ++ Production:String;
1241
+ ++ ServerUrl:String;
1242
+ ++ PublicKey:String;
1243
+ ++ }
1244
+ +struct Index {
1245
+ + @StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
1246
+ + @State shouldShow: boolean = false
1247
+ + private logger!: RNOHLogger
1248
+ ++ bundlePath:string = 'bundle.harmony.js'
1249
+ +aboutToAppear() {
1250
+ + ...
1251
+ ++ this.setCodeConfig()
1252
+ + this.shouldShow = true
1253
+ + stopTracing()
1254
+ + }
1255
+ ++ setCodeConfig(){
1256
+ ++ const CodePushConfig: CodePushConfig = {
1257
+ ++ Staging:BuildProfile.Staging,
1258
+ ++ Production:BuildProfile.Production,
1259
+ ++ ServerUrl:BuildProfile.ServerUrl,
1260
+ ++ PublicKey:BuildProfile.PublicKey
1261
+ ++ }
1262
+ ++ AppStorage.SetOrCreate('CodePushConfig',CodePushConfig)
1263
+ ++ }
1264
+ +build() {
1265
+ + Column() {
1266
+ + ...
1267
+ + RNApp({
1268
+ + jsBundleProvider:new TraceJSBundleProviderDecorator(
1269
+ + new AnyJSBundleProvider([
1270
+ + new MetroJSBundleProvider(),
1271
+ + // NOTE: to load the bundle from file, place it in
1272
+ + // `/data/app/el2/100/base/com.rnoh.tester/files/bundle.harmony.js`
1273
+ + // on your device. The path mismatch is due to app sandboxing on HarmonyOS
1274
+ ++ new FileJSBundleProvider(context.filesDir + '/Bundles/' + this.bundlePath),
1275
+ + new FileJSBundleProvider('/data/storage/el2/base/files/bundle.harmony.js'),
1276
+ + new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
1277
+ + new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
1278
+ + ]),
1279
+ + this.rnohCoreContext.logger),
1280
+ + })
1281
+ +
1282
+ + }
1283
+ +
1284
+ +}
1285
+ +```
1286
+ +
1287
+ +Open `entry/build-profile.json5` and add configuration
1288
+ +
1289
+ +```diff
1290
+ +{
1291
+ + "apiType": 'stageMode',
1292
+ + "buildOption": {
1293
+ + "externalNativeOptions": {
1294
+ + "path": "./src/main/cpp/CMakeLists.txt",
1295
+ + "arguments": "",
1296
+ + "cppFlags": "-s",
1297
+ + },
1298
+ ++ "arkOptions": {
1299
+ ++ "buildProfileFields": {
1300
+ ++ "Staging": "", //Test Environment Key
1301
+ ++ "Production": "",//Production Environment Key
1302
+ ++ "ServerUrl": "",//Server address
1303
+ ++ "PublicKey": "PublicKey"
1304
+ + }
1305
+ + }
1306
+ + },
1307
+ + "targets": [
1308
+ + {
1309
+ + "name": "default",
1310
+ + "runtimeOS": "HarmonyOS"
1311
+ + },
1312
+ + {
1313
+ + "name": "ohosTest",
1314
+ + }
1315
+ + ]
1316
+ +}
1317
+ +```
1318
+ +
1319
+ +Then build and run the code.
1320
+ +
1321
+ +## Constraints
1322
+ +
1323
+ +### Compatibility
1324
+ +
1325
+ +
1326
+ +To use this repository, you need to use the correct React-Native and RNOH versions. In addition, you need to use DevEco Studio and the ROM on your phone.
1327
+ +
1328
+ +Verified in the following versions.
1329
+ +
1330
+ +1. RNOH: 0.72.96; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
1331
+ +2. RNOH: 0.72.33; SDK: HarmonyOS NEXT B1; IDE: DevEco Studio: 5.0.3.900; ROM: Next.0.0.71;
1332
+ +3. RNOH: 0.77.18; SDK: HarmonyOS 6.0.0 Release SDK; IDE: DevEco Studio 6.0.0.858; ROM: 6.0.0.112;
1333
+ +
1334
+ +
1335
+ +## API
1336
+ +
1337
+ +| Name | Description | Type | Required | Platform | HarmonyOS Support |
1338
+ +| ----------------- | ----------------------------------------------------------------------------
1339
+ ... [diff 已截断]
1340
+ ```
1341
+
1342
+ ### `buildEnv.sh`
1343
+
1344
+ ```diff
1345
+ @@ -0,0 +1,8 @@
1346
+ +#!/bin/bash
1347
+ +BUILD_PKG_DIR=example
1348
+ +BUILD_SAMPLE_DIR=example/harmony
1349
+ +BUILD_THIRD_PARTY_DIR=harmony/
1350
+ +
1351
+ +# BUILD_PKG_DIR: 用来打 tgz 包的工程目录
1352
+ +# BUILD_SAMPLE_DIR:用来打 har 包的目录
1353
+ +# BUILD_THIRD_PARTY_DIR:库模块源码目录
1354
+
1355
+ ```
1356
+
1357
+ ### `example/.eslintrc`
1358
+
1359
+ ```diff
1360
+ @@ -0,0 +1,13 @@
1361
+ +{
1362
+ + "extends": "@react-native",
1363
+ + "rules": {
1364
+ + "react-native/no-inline-styles": "off",
1365
+ + "react/no-unstable-nested-components": "off",
1366
+ + "react/react-in-jsx-scope": "off",
1367
+ + "@typescript-eslint/no-unused-vars": "warn",
1368
+ + "react-hooks/exhaustive-deps": "off",
1369
+ + "radix": "off",
1370
+ + "prettier/prettier": "warn",
1371
+ + "max-lines": "off"
1372
+ + }
1373
+ +}
1374
+
1375
+
1376
+ ```
1377
+
1378
+ ### `example/.gitignore`
1379
+
1380
+ ```diff
1381
+ @@ -0,0 +1,71 @@
1382
+ +.husky
1383
+ +bundle.harmony.js
1384
+ +package-lock.json
1385
+ +*.hbc
1386
+ +lintCppResult.txt
1387
+ +
1388
+ +# ---
1389
+ +
1390
+ +# OSX
1391
+ +#
1392
+ +.DS_Store
1393
+ +
1394
+ +# Xcode
1395
+ +#
1396
+ +build/
1397
+ +*.pbxuser
1398
+ +!default.pbxuser
1399
+ +*.mode1v3
1400
+ +!default.mode1v3
1401
+ +*.mode2v3
1402
+ +!default.mode2v3
1403
+ +*.perspectivev3
1404
+ +!default.perspectivev3
1405
+ +xcuserdata
1406
+ +*.xccheckout
1407
+ +*.moved-aside
1408
+ +DerivedData
1409
+ +*.hmap
1410
+ +*.ipa
1411
+ +*.xcuserstate
1412
+ +
1413
+ +# Android/IntelliJ
1414
+ +#
1415
+ +build/
1416
+ +.idea
1417
+ +.gradle
1418
+ +local.properties
1419
+ +*.iml
1420
+ +*.hprof
1421
+ +.cxx/
1422
+ +*.keystore
1423
+ +!debug.keystore
1424
+ +BuildProfile.ets
1425
+ +
1426
+ +# node.js
1427
+ +#
1428
+ +node_modules/
1429
+ +npm-debug.log
1430
+ +yarn-error.log
1431
+ +
1432
+ +# fastlane
1433
+ +#
1434
+ +# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
1435
+ +# screenshots whenever they are needed.
1436
+ +# For more information about the recommended setup visit:
1437
+ +# https://docs.fastlane.tools/best-practices/source-control/
1438
+ +
1439
+ +**/fastlane/report.xml
1440
+ +**/fastlane/Preview.html
1441
+ +**/fastlane/screenshots
1442
+ +**/fastlane/test_output
1443
+ +
1444
+ +# Bundle artifact
1445
+ +*.jsbundle
1446
+ +
1447
+ +# Ruby / CocoaPods
1448
+ +/vendor/bundle/
1449
+ +
1450
+ +# Temporary files created by Metro to check the health of the file watcher
1451
+ +.metro-health-check*
1452
+ +*.htrace
1453
+
1454
+
1455
+ ```
1456
+
1457
+ ### `example/.node-version`
1458
+
1459
+ ```diff
1460
+ @@ -0,0 +1 @@
1461
+ +18
1462
+
1463
+ ```
1464
+
1465
+ ### `example/.prettierrc.js`
1466
+
1467
+ ```diff
1468
+ @@ -0,0 +1,7 @@
1469
+ +module.exports = {
1470
+ + arrowParens: 'avoid',
1471
+ + bracketSameLine: true,
1472
+ + bracketSpacing: true,
1473
+ + singleQuote: true,
1474
+ + trailingComma: 'all',
1475
+ +};
1476
+
1477
+ ```
1478
+
1479
+ ### `example/.watchmanconfig`
1480
+
1481
+ ```diff
1482
+ @@ -0,0 +1 @@
1483
+ +{}
1484
+
1485
+
1486
+ ```
1487
+
1488
+ ### `example/app.json`
1489
+
1490
+ ```diff
1491
+ @@ -0,0 +1,4 @@
1492
+ +{
1493
+ + "name": "app_name",
1494
+ + "displayName": "tester"
1495
+ +}
1496
+
1497
+
1498
+ ```
1499
+
1500
+ ### `example/babel.config.js`
1501
+
1502
+ ```diff
1503
+ @@ -0,0 +1,5 @@
1504
+ +module.exports = {
1505
+ + presets: ['module:metro-react-native-babel-preset'],
1506
+ + plugins: [
1507
+ + ],
1508
+ +};
1509
+
1510
+ ```
1511
+
1512
+ ### `example/contexts.ts`
1513
+
1514
+ ```diff
1515
+ @@ -0,0 +1,26 @@
1516
+ +/**
1517
+ + * MIT License
1518
+ + *
1519
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
1520
+ + *
1521
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
1522
+ + * of this software and associated documentation files (the "Software"), to deal
1523
+ + * in the Software without restriction, including without limitation the rights
1524
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1525
+ + * copies of the Software, and to permit persons to whom the Software is
1526
+ + * furnished to do so, subject to the following conditions:
1527
+ + *
1528
+ + * The above copyright notice and this permission notice shall be included in all
1529
+ + * copies or substantial portions of the Software.
1530
+ + *
1531
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1532
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1533
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1534
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1535
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1536
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1537
+ + * SOFTWARE.
1538
+ + */
1539
+ +mport React from 'react';
1540
+ +
1541
+ +export const AppParamsContext = React.createContext(undefined);
1542
+
1543
+ ```
1544
+
1545
+ ### `example/harmony/.gitignore`
1546
+
1547
+ ```diff
1548
+ @@ -0,0 +1,24 @@
1549
+ +# it may cause some issues when building the project when switching branches
1550
+ +package-lock.json
1551
+ +# we add this because we want to keep the signing configs out of git
1552
+ +/build-profile.json5
1553
+ +
1554
+ +rnoh_modules
1555
+ +
1556
+ +**/oh-package-lock.json5
1557
+ +# ---
1558
+ +
1559
+ +/node_modules
1560
+ +/local.properties
1561
+ +/.idea
1562
+ +**/build
1563
+ +/.hvigor
1564
+ +.cxx
1565
+ +/.clangd
1566
+ +/.clang-format
1567
+ +/.clang-tidy
1568
+ +/oh_modules
1569
+ +hvigorw
1570
+ +hvigorw.bat
1571
+ +hvigor/hvigor-wrapper.js
1572
+ +
1573
+
1574
+ ```
1575
+
1576
+ ### `example/harmony/AppScope/app.json5`
1577
+
1578
+ ```diff
1579
+ @@ -0,0 +1,10 @@
1580
+ +{
1581
+ + "app": {
1582
+ + "bundleName": "com.harmony.wechat.lib.demo",
1583
+ + "vendor": "example",
1584
+ + "versionCode": 1000000,
1585
+ + "versionName": "1.0.0",
1586
+ + "icon": "$media:app_icon",
1587
+ + "label": "$string:app_name"
1588
+ + }
1589
+ +}
1590
+
1591
+ ```
1592
+
1593
+ ### `example/harmony/AppScope/resources/base/element/string.json`
1594
+
1595
+ ```diff
1596
+ @@ -0,0 +1,8 @@
1597
+ +{
1598
+ + "string": [
1599
+ + {
1600
+ + "name": "app_name",
1601
+ + "value": "RN Tester"
1602
+ + }
1603
+ + ]
1604
+ +}
1605
+
1606
+ ```
1607
+
1608
+ ### `example/harmony/AppScope/resources/base/media/app_icon.png`
1609
+
1610
+ ```diff
1611
+ Binary files no preview for this file type
1612
+ ```
1613
+
1614
+ ### `example/harmony/build-profile.template.json5`
1615
+
1616
+ ```diff
1617
+ @@ -0,0 +1,39 @@
1618
+ +{
1619
+ + "app": {
1620
+ + "products": [
1621
+ + {
1622
+ + "name": 'default',
1623
+ + "signingConfig": 'default',
1624
+ + compatibleSdkVersion: '5.0.0(12)',
1625
+ + "runtimeOS": 'HarmonyOS'
1626
+ + },
1627
+ + ],
1628
+ + "buildModeSet": [
1629
+ + {
1630
+ + "name": 'debug',
1631
+ + },
1632
+ + {
1633
+ + "name": 'release',
1634
+ + },
1635
+ + ],
1636
+ + "signingConfigs": []
1637
+ + },
1638
+ + "modules": [
1639
+ + {
1640
+ + "name": 'entry',
1641
+ + "srcPath": './entry',
1642
+ + "targets": [
1643
+ + {
1644
+ + "name": 'default',
1645
+ + "applyToProducts": [
1646
+ + 'default'
1647
+ + ],
1648
+ + },
1649
+ + ],
1650
+ + },
1651
+ + {
1652
+ + "name": "codePush",
1653
+ + "srcPath": '../../harmony/codePush'
1654
+ + }
1655
+ + ],
1656
+ +}
1657
+
1658
+
1659
+ ```
1660
+
1661
+ ### `example/harmony/codelinter.json`
1662
+
1663
+ ```diff
1664
+ @@ -0,0 +1,32 @@
1665
+ +{
1666
+ + "files": ["**/*.ts", "**/*.ets"],
1667
+ + "ignore": [
1668
+ + "**/ohosTest/**/*",
1669
+ + "**/node_modules/**/*",
1670
+ + "**/hvigorfile.ts",
1671
+ + "**/node_modules/**/*",
1672
+ + "**/oh_modules/**/*",
1673
+ + "**/build/**/*",
1674
+ + "**/.preview/**/*"
1675
+ + ],
1676
+ + "plugins": ["@typescript-eslint"],
1677
+ + "ruleSet": [],
1678
+ + "rules": {
1679
+ + "@typescript-eslint/await-thenable": "warn",
1680
+ + "@typescript-eslint/consistent-type-imports": "warn",
1681
+ + "@typescript-eslint/explicit-function-return-type": "warn",
1682
+ + "@typescript-eslint/explicit-module-boundary-types": "warn",
1683
+ + "@typescript-eslint/no-dynamic-delete": "warn",
1684
+ + "@typescript-eslint/no-explicit-any": "warn",
1685
+ + "@typescript-eslint/no-for-in-array": "warn",
1686
+ + "@typescript-eslint/no-this-alias": "warn",
1687
+ + "@typescript-eslint/no-unnecessary-type-constraint": "warn",
1688
+ + "@typescript-eslint/no-unsafe-argument": "warn",
1689
+ + "@typescript-eslint/no-unsafe-assignment": "warn",
1690
+ + "@typescript-eslint/no-unsafe-call": "warn",
1691
+ + "@typescript-eslint/no-unsafe-member-access": "warn",
1692
+ + "@typescript-eslint/no-unsafe-return": "warn",
1693
+ + "@typescript-eslint/prefer-literal-enum-member": "warn"
1694
+ + },
1695
+ + "overrides": []
1696
+ +}
1697
+
1698
+ ```
1699
+
1700
+ ### `example/harmony/entry/.gitignore`
1701
+
1702
+ ```diff
1703
+ @@ -0,0 +1,7 @@
1704
+ +/node_modules
1705
+ +/.preview
1706
+ +/build
1707
+ +/.cxx
1708
+ +package-lock.json
1709
+ +/oh_modules
1710
+ +/assets
1711
+
1712
+ ```
1713
+
1714
+ ### `example/harmony/entry/build-profile.json5`
1715
+
1716
+ ```diff
1717
+ @@ -0,0 +1,19 @@
1718
+ +{
1719
+ + "apiType": 'stageMode',
1720
+ + "buildOption": {
1721
+ + "externalNativeOptions": {
1722
+ + "path": "./src/main/cpp/CMakeLists.txt",
1723
+ + "arguments": "",
1724
+ + "cppFlags": "-s",
1725
+ + },
1726
+ + },
1727
+ + "targets": [
1728
+ + {
1729
+ + "name": "default",
1730
+ + "runtimeOS": "HarmonyOS"
1731
+ + },
1732
+ + {
1733
+ + "name": "ohosTest",
1734
+ + }
1735
+ + ]
1736
+ +}
1737
+
1738
+
1739
+ ```
1740
+
1741
+ ### `example/harmony/entry/hvigorfile.ts`
1742
+
1743
+ ```diff
1744
+ @@ -0,0 +1,17 @@
1745
+ +/*
1746
+ + * Copyright (c) 2024 Huawei Device Co., Ltd.
1747
+ + * Licensed under the Apache License, Version 2.0 (the "License");
1748
+ + * you may not use this file except in compliance with the License.
1749
+ + * You may obtain a copy of the License at
1750
+ + *
1751
+ + * http://www.apache.org/licenses/LICENSE-2.0
1752
+ + *
1753
+ + * Unless required by applicable law or agreed to in writing, software
1754
+ + * distributed under the License is distributed on an "AS IS" BASIS,
1755
+ + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1756
+ + * See the License for the specific language governing permissions and
1757
+ + * limitations under the License.
1758
+ + */
1759
+ +
1760
+ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
1761
+ +export { hapTasks } from '@ohos/hvigor-ohos-plugin';
1762
+
1763
+ ```
1764
+
1765
+ ### `example/harmony/entry/oh-package.json5`
1766
+
1767
+ ```diff
1768
+ @@ -0,0 +1,11 @@
1769
+ +{
1770
+ + "license": "ISC",
1771
+ + "devDependencies": {},
1772
+ + "name": "entry",
1773
+ + "description": "example description",
1774
+ + "version": "1.0.0",
1775
+ + "dependencies": {
1776
+ + "@rnoh/react-native-openharmony": "file:../../node_modules/react-native-harmony/react_native_openharmony.har",
1777
+ + "@react-native-ohos/react-native-code-push": "file:../../node_modules/@react-native-ohos/react-native-code-push/harmony/codePush.har",
1778
+ + }
1779
+ +}
1780
+
1781
+
1782
+ ```
1783
+
1784
+ ### `example/harmony/entry/src/main/cpp/.gitignore`
1785
+
1786
+ ```diff
1787
+ @@ -0,0 +1,2 @@
1788
+ +jsbundle.h
1789
+ +generated/
1790
+
1791
+ ```
1792
+
1793
+ ### `example/harmony/entry/src/main/cpp/CMakeLists.txt`
1794
+
1795
+ ```diff
1796
+ @@ -0,0 +1,35 @@
1797
+ +project(rnapp)
1798
+ +cmake_minimum_required(VERSION 3.4.1)
1799
+ +set(CMAKE_SKIP_BUILD_RPATH TRUE)
1800
+ +set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
1801
+ +set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
1802
+ +set(OH_MODULE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
1803
+ +set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules/@rnoh/react-native-openharmony/src/main/cpp")
1804
+ +set(RNOH_GENERATED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/generated")
1805
+ +set(LOG_VERBOSITY_LEVEL 1)
1806
+ +set(CMAKE_ASM_FLAGS "-Wno-error=unused-command-line-argument -Qunused-arguments")
1807
+ +set(CMAKE_CXX_FLAGS "-fstack-protector-strong -Wl,-z,relro,-z,now,-z,noexecstack -s -fPIE -pie")
1808
+ +set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
1809
+ +
1810
+ +set(WITH_HITRACE_SYSTRACE 1) # for other CMakeLists.txt files to use
1811
+ +add_compile_definitions(WITH_HITRACE_SYSTRACE)
1812
+ +
1813
+ +add_subdirectory("${RNOH_CPP_DIR}" ./rn)
1814
+ +
1815
+ +# RNOH_BEGIN: manual_package_linking_1
1816
+ +add_subdirectory("${OH_MODULES}/@react-native-ohos/react-native-code-push/src/main/cpp" ./rnoh_code_push)
1817
+ +# RNOH_END: manual_package_linking_1
1818
+ +
1819
+ +file(GLOB GENERATED_CPP_FILES "${CMAKE_CURRENT_SOURCE_DIR}/generated/*.cpp") # this line is needed by codegen v1
1820
+ +
1821
+ +add_library(rnoh_app SHARED
1822
+ + ${GENERATED_CPP_FILES}
1823
+ + "./PackageProvider.cpp"
1824
+ + "${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
1825
+ +)
1826
+ +target_link_libraries(rnoh_app PUBLIC rnoh)
1827
+ +
1828
+ +# RNOH_BEGIN: manual_package_linking_2
1829
+ +target_link_libraries(rnoh_app PUBLIC rnoh_code_push)
1830
+ +
1831
+ +# RNOH_END: manual_package_linking_2
1832
+
1833
+ ```
1834
+
1835
+ ### `example/harmony/entry/src/main/cpp/PackageProvider.cpp`
1836
+
1837
+ ```diff
1838
+ @@ -0,0 +1,35 @@
1839
+ +/**
1840
+ + * MIT License
1841
+ + *
1842
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
1843
+ + *
1844
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
1845
+ + * of this software and associated documentation files (the "Software"), to deal
1846
+ + * in the Software without restriction, including without limitation the rights
1847
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1848
+ + * copies of the Software, and to permit persons to whom the Software is
1849
+ + * furnished to do so, subject to the following conditions:
1850
+ + *
1851
+ + * The above copyright notice and this permission notice shall be included in all
1852
+ + * copies or substantial portions of the Software.
1853
+ + *
1854
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1855
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1856
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1857
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1858
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1859
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1860
+ + * SOFTWARE.
1861
+ + */
1862
+ +#include "RNOH/PackageProvider.h"
1863
+ +#include "generated/RNOHGeneratedPackage.h"
1864
+ +#include "CodePushPackage.h"
1865
+ +
1866
+ +using namespace rnoh;
1867
+ +
1868
+ +std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
1869
+ + return {
1870
+ + std::make_shared<RNOHGeneratedPackage>(ctx), // generated by codegen v1
1871
+ + std::make_shared<CodePushPackage>(ctx)
1872
+ + };
1873
+ +}
1874
+
1875
+
1876
+ ```
1877
+
1878
+ ### `example/harmony/entry/src/main/ets/RNPackagesFactory.ets`
1879
+
1880
+ ```diff
1881
+ @@ -0,0 +1,32 @@
1882
+ +/**
1883
+ + * MIT License
1884
+ + *
1885
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
1886
+ + *
1887
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
1888
+ + * of this software and associated documentation files (the "Software"), to deal
1889
+ + * in the Software without restriction, including without limitation the rights
1890
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1891
+ + * copies of the Software, and to permit persons to whom the Software is
1892
+ + * furnished to do so, subject to the following conditions:
1893
+ + *
1894
+ + * The above copyright notice and this permission notice shall be included in all
1895
+ + * copies or substantial portions of the Software.
1896
+ + *
1897
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1898
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1899
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1900
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1901
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1902
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1903
+ + * SOFTWARE.
1904
+ + */
1905
+ +
1906
+ +import type {RNPackageContext, RNPackage} from '@rnoh/react-native-openharmony/ts';
1907
+ +import CodePushPackage from '@react-native-ohos/react-native-code-push';
1908
+ +
1909
+ +export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
1910
+ + return [
1911
+ + new CodePushPackage(ctx)
1912
+ + ];
1913
+ +}
1914
+
1915
+ ```
1916
+
1917
+ ### `example/harmony/entry/src/main/ets/assets/fonts/Pacifico-Regular.ttf`
1918
+
1919
+ ```diff
1920
+ Binary files no preview for this file type
1921
+ ```
1922
+
1923
+ ### `example/harmony/entry/src/main/ets/assets/fonts/StintUltraCondensed-Regular.ttf`
1924
+
1925
+ ```diff
1926
+ Binary files no preview for this file type
1927
+ ```
1928
+
1929
+ ### `example/harmony/entry/src/main/ets/entryability/EntryAbility.ets`
1930
+
1931
+ ```diff
1932
+ @@ -0,0 +1,37 @@
1933
+ +/**
1934
+ + * MIT License
1935
+ + *
1936
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
1937
+ + *
1938
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
1939
+ + * of this software and associated documentation files (the "Software"), to deal
1940
+ + * in the Software without restriction, including without limitation the rights
1941
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1942
+ + * copies of the Software, and to permit persons to whom the Software is
1943
+ + * furnished to do so, subject to the following conditions:
1944
+ + *
1945
+ + * The above copyright notice and this permission notice shall be included in all
1946
+ + * copies or substantial portions of the Software.
1947
+ + *
1948
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1949
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1950
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1951
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1952
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1953
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1954
+ + * SOFTWARE.
1955
+ + */
1956
+ +
1957
+ +import {RNAbility} from '@rnoh/react-native-openharmony';
1958
+ +import { AbilityConstant, Want } from '@kit.AbilityKit';
1959
+ +
1960
+ +export default class EntryAbility extends RNAbility {
1961
+ +
1962
+ + onCreate(want: Want) {
1963
+ + super.onCreate(want)
1964
+ + }
1965
+ +
1966
+ + getPagePath() {
1967
+ + return 'pages/Index';
1968
+ + }
1969
+ +}
1970
+
1971
+ ```
1972
+
1973
+ ### `example/harmony/entry/src/main/ets/pages/Index.ets`
1974
+
1975
+ ```diff
1976
+ @@ -0,0 +1,136 @@
1977
+ +/**
1978
+ + * MIT License
1979
+ + *
1980
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
1981
+ + *
1982
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
1983
+ + * of this software and associated documentation files (the "Software"), to deal
1984
+ + * in the Software without restriction, including without limitation the rights
1985
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1986
+ + * copies of the Software, and to permit persons to whom the Software is
1987
+ + * furnished to do so, subject to the following conditions:
1988
+ + *
1989
+ + * The above copyright notice and this permission notice shall be included in all
1990
+ + * copies or substantial portions of the Software.
1991
+ + *
1992
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1993
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1994
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1995
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1996
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1997
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1998
+ + * SOFTWARE.
1999
+ + */
2000
+ +
2001
+ +import {
2002
+ + AnyJSBundleProvider,
2003
+ + ComponentBuilderContext,
2004
+ + FileJSBundleProvider,
2005
+ + MetroJSBundleProvider,
2006
+ + ResourceJSBundleProvider,
2007
+ + RNApp,
2008
+ + RNOHErrorDialog,
2009
+ + RNOHLogger,
2010
+ + TraceJSBundleProviderDecorator,
2011
+ + RNOHCoreContext
2012
+ +} from '@rnoh/react-native-openharmony';
2013
+ +import font from '@ohos.font';
2014
+ +import { createRNPackages } from '../RNPackagesFactory';
2015
+ +
2016
+ +const arkTsComponentNames: Array<string> = [
2017
+ +];
2018
+ +
2019
+ +@Builder
2020
+ +export function buildCustomRNComponent(ctx: ComponentBuilderContext) {
2021
+ + // There seems to be a problem with the placement of ArkTS components in mixed mode. Nested Stack temporarily avoided.
2022
+ + Stack() {
2023
+ + }
2024
+ + .position({ x: 0, y: 0 })
2025
+ +
2026
+ +}
2027
+ +
2028
+ +const wrappedCustomRNComponentBuilder = wrapBuilder(buildCustomRNComponent)
2029
+ +
2030
+ +/**
2031
+ + * If you want to use custom fonts, you need to register them here.
2032
+ + * We should support react-native-asset to handle registering fonts automatically.
2033
+ + */
2034
+ +const fonts: font.FontOptions[] = [
2035
+ + {
2036
+ + familyName: 'Pacifico-Regular',
2037
+ + familySrc: '/assets/fonts/Pacifico-Regular.ttf'
2038
+ + },
2039
+ + {
2040
+ + familyName: 'StintUltraCondensed-Regular',
2041
+ + familySrc: '/assets/fonts/StintUltraCondensed-Regular.ttf'
2042
+ + }
2043
+ +]
2044
+ +
2045
+ +@Entry
2046
+ +@Component
2047
+ +struct Index {
2048
+ + @StorageLink('RNOHCoreContext') private rnohCoreContext: RNOHCoreContext | undefined = undefined
2049
+ + @State shouldShow: boolean = false
2050
+ + private logger!: RNOHLogger
2051
+ + bundlePath: string = 'bunlde.harmony.js'
2052
+ + @State hasBundle: boolean = false
2053
+ +
2054
+ + aboutToAppear() {
2055
+ + this.logger = this.rnohCoreContext!.logger.clone("Index")
2056
+ + const stopTracing = this.logger.clone("aboutToAppear").startTracing()
2057
+ + for (const customFont of fonts) {
2058
+ + font.registerFont(customFont)
2059
+ + }
2060
+ +
2061
+ + this.shouldShow = true
2062
+ + stopTracing()
2063
+ + }
2064
+ +
2065
+ + onBackPress(): boolean | undefined {
2066
+ + // NOTE: this is required since `Ability`'s `onBackPressed` function always
2067
+ + // terminates or puts the app in the background, but we want Ark to ignore it completely
2068
+ + // when handled by RN
2069
+ + this.rnohCoreContext!.dispatchBackPress()
2070
+ + return true
2071
+ + }
2072
+ +
2073
+ + build() {
2074
+ + Column() {
2075
+ + if (this.rnohCoreContext && this.shouldShow) {
2076
+ + if (this.rnohCoreContext?.isDebugModeEnabled) {
2077
+ + RNOHErrorDialog({ ctx: this.rnohCoreContext })
2078
+ + }
2079
+ + RNApp({
2080
+ + rnInstanceConfig: {
2081
+ + createRNPackages,
2082
+ + enableNDKTextMeasuring: true,
2083
+ + enableBackgroundExecutor: false,
2084
+ + enableCAPIArchitecture: true,
2085
+ + arkTsComponentNames: arkTsComponentNames,
2086
+ + },
2087
+ + initialProps: { "foo": "bar" } as Record<string, string>,
2088
+ + appKey: "app_name",
2089
+ + wrappedCustomRNComponentBuilder: wrappedCustomRNComponentBuilder,
2090
+ + onSetUp: (rnInstance) => {
2091
+ + rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP")
2092
+ + },
2093
+ + jsBundleProvider: new TraceJSBundleProviderDecorator(
2094
+ + new AnyJSBundleProvider([
2095
+ + new MetroJSBundleProvider(),
2096
+ + // NOTE: to load the bundle from file, place it in
2097
+ + // `/data/app/el2/100/base/com.rnoh.tester/files/bundle.harmony.js`
2098
+ + // on your device. The path mismatch is due to app sandboxing on HarmonyOS
2099
+ + new FileJSBundleProvider('/data/storage/el2/base/files/bundle.harmony.js'),
2100
+ + // new FileJSBundleProvider(context.filesDir + '/' + this.bundlePath),
2101
+ + new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'hermes_bundle.hbc'),
2102
+ + new ResourceJSBundleProvider(this.rnohCoreContext.uiAbilityContext.resourceManager, 'bundle.harmony.js')
2103
+ + ]),
2104
+ + this.rnohCoreContext.logger),
2105
+ + })
2106
+ + }
2107
+ + Text("1233333333122 1212323")
2108
+ + }
2109
+ + .height('100%')
2110
+ + .width('100%')
2111
+ + }
2112
+ +}
2113
+
2114
+ ```
2115
+
2116
+ ### `example/harmony/entry/src/main/ets/pages/SurfaceDeadlockTest.ets`
2117
+
2118
+ ```diff
2119
+ @@ -0,0 +1,153 @@
2120
+ +/**
2121
+ + * MIT License
2122
+ + *
2123
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
2124
+ + *
2125
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
2126
+ + * of this software and associated documentation files (the "Software"), to deal
2127
+ + * in the Software without restriction, including without limitation the rights
2128
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2129
+ + * copies of the Software, and to permit persons to whom the Software is
2130
+ + * furnished to do so, subject to the following conditions:
2131
+ + *
2132
+ + * The above copyright notice and this permission notice shall be included in all
2133
+ + * copies or substantial portions of the Software.
2134
+ + *
2135
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2136
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2137
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2138
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2139
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2140
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2141
+ + * SOFTWARE.
2142
+ + */
2143
+ +import { RNInstance, JSBundleProvider, RNAbility, RNSurface } from '@rnoh/react-native-openharmony'
2144
+ +import { CustomComponentBuilder } from "@rnoh/react-native-openharmony/src/main/ets/RNOHCorePackage"
2145
+ +import { SurfaceConfig2 } from '@rnoh/react-native-openharmony/src/main/ets/RNSurface'
2146
+ +
2147
+ +
2148
+ +@Component
2149
+ +export struct SurfaceDeadlockTest {
2150
+ + public jsBundleProvider: JSBundleProvider | undefined = undefined
2151
+ + public appKeys: string[] = []
2152
+ + public numberOfIterations: number = 1
2153
+ + @BuilderParam public buildCustomComponent!: CustomComponentBuilder
2154
+ + // -------------------------------------------------------------------------------------------------------------------
2155
+ + @StorageLink('RNAbility') private rnAbility: RNAbility = {} as RNAbility
2156
+ + private rnInstance!: RNInstance
2157
+ + @State private shouldShow: boolean = false
2158
+ + private shouldDestroyRNInstance: boolean = false
2159
+ + private cleanUpCallbacks: (() => void)[] = []
2160
+ +
2161
+ + aboutToAppear() {
2162
+ + this.getOrCreateRNInstance().then(rnInstance => {
2163
+ + this.rnInstance = rnInstance
2164
+ + const jsBundleExecutionStatus = this.rnInstance.getBundleExecutionStatus(this.jsBundleProvider?.getURL())
2165
+ + if (this.jsBundleProvider && jsBundleExecutionStatus === undefined) {
2166
+ + this.rnInstance.runJSBundle(this.jsBundleProvider).then(() => {
2167
+ + this.shouldShow = true
2168
+ + })
2169
+ + return;
2170
+ + }
2171
+ + }).catch((reason: string | Error) => {
2172
+ + if (typeof reason === "string")
2173
+ + this.rnAbility.getLogger().error(reason)
2174
+ + else if (reason instanceof Error) {
2175
+ + this.rnAbility.getLogger().error(reason.message)
2176
+ + } else {
2177
+ + this.rnAbility.getLogger().error("Fatal exception")
2178
+ + }
2179
+ + })
2180
+ + }
2181
+ +
2182
+ + aboutToDisappear() {
2183
+ + if (this.shouldDestroyRNInstance)
2184
+ + this.rnAbility.destroyAndUnregisterRNInstance(this.rnInstance)
2185
+ + this.cleanUpCallbacks.forEach(cleanUp => cleanUp())
2186
+ + }
2187
+ +
2188
+ + private getOrCreateRNInstance(): Promise<RNInstance> {
2189
+ + return this.rnAbility.createAndRegisterRNInstance({ createRNPackages: () => [] })
2190
+ + }
2191
+ +
2192
+ + build() {
2193
+ + Stack() {
2194
+ + if (this.shouldShow) {
2195
+ + ForEach(this.appKeys, (appKey: string, idx) => {
2196
+ + Stack() {
2197
+ + Blinker({
2198
+ + minDelayInMs: 1000,
2199
+ + maxDelayInMs: 2000,
2200
+ + blinksCount: this.numberOfIterations,
2201
+ + randomnessPrecisionInMs: 500
2202
+ + }) {
2203
+ + RNSurface({
2204
+ + ctx: this.rnAbility.createRNOHContext({ rnInstance: this.rnInstance }),
2205
+ + surfaceConfig: {
2206
+ + initialProps: {},
2207
+ + appKey: appKey,
2208
+ + } as SurfaceConfig2,
2209
+ + buildCustomComponent: this.buildCustomComponent,
2210
+ + })
2211
+ + }
2212
+ + }.height(`${100 / this.appKeys.length}%`)
2213
+ + .position({ x: 0, y: `${(idx / this.appKeys.length) * 100}%` })
2214
+ + })
2215
+ + }
2216
+ + }.width("100%")
2217
+ + .height("100%")
2218
+ + }
2219
+ +}
2220
+ +
2221
+ +
2222
+ +@Component
2223
+ +struct Blinker {
2224
+ + public minDelayInMs: number = 0
2225
+ + public maxDelayInMs: number = 1000
2226
+ + public blinksCount: number = 0
2227
+ + public randomnessPrecisionInMs: number = 250
2228
+ + @BuilderParam public renderChildren: () => void
2229
+ + private currentBlinksCount = 0
2230
+ + @State private isVisible: boolean = false
2231
+ + private timeout: number = 0
2232
+ +
2233
+ + aboutToAppear() {
2234
+ + this.blink(this.minDelayInMs)
2235
+ + }
2236
+ +
2237
+ + aboutToDisappear() {
2238
+ + clearTimeout(this.timeout)
2239
+ + }
2240
+ +
2241
+ + private blink(ms: number) {
2242
+ + this.isVisible = !this.isVisible
2243
+ + this.currentBlinksCount += 1
2244
+ + if (this.currentBlinksCount >= this.blinksCount) {
2245
+ + if (this.timeout) {
2246
+ + clearTimeout(this.timeout)
2247
+ + }
2248
+ + this.isVisible = true
2249
+ + return;
2250
+ + }
2251
+ + this.timeout = setTimeout(() => {
2252
+ + this.blink(this.getNextDelay())
2253
+ + }, ms)
2254
+ + }
2255
+ +
2256
+ + private getNextDelay(): number {
2257
+ + return ((Math.floor(Math.random() * (Number.MAX_VALUE / this.randomnessPrecisionInMs)) * this.randomnessPrecisionInMs) % this.maxDelayInMs) + this.minDelayInMs
2258
+ + }
2259
+ +
2260
+ + build() {
2261
+ + Stack() {
2262
+ + if (this.isVisible) {
2263
+ + this.renderChildren()
2264
+ + }
2265
+ + }
2266
+ + }
2267
+ +}
2268
+ +
2269
+ +
2270
+ +
2271
+ +
2272
+ +
2273
+
2274
+ ```
2275
+
2276
+ ### `example/harmony/entry/src/main/ets/pages/TouchDisplayer.ets`
2277
+
2278
+ ```diff
2279
+ @@ -0,0 +1,60 @@
2280
+ +/**
2281
+ + * MIT License
2282
+ + *
2283
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
2284
+ + *
2285
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
2286
+ + * of this software and associated documentation files (the "Software"), to deal
2287
+ + * in the Software without restriction, including without limitation the rights
2288
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2289
+ + * copies of the Software, and to permit persons to whom the Software is
2290
+ + * furnished to do so, subject to the following conditions:
2291
+ + *
2292
+ + * The above copyright notice and this permission notice shall be included in all
2293
+ + * copies or substantial portions of the Software.
2294
+ + *
2295
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2296
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2297
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2298
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2299
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2300
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2301
+ + * SOFTWARE.
2302
+ + */
2303
+ +@Component
2304
+ +export struct TouchDisplayer {
2305
+ + @State currentTouches: TouchObject[] = []
2306
+ + @State touchIndicatorOpacity: number = 0
2307
+ + @BuilderParam buildChildren: () => void
2308
+ + build() {
2309
+ + Stack() {
2310
+ + this.buildChildren()
2311
+ + ForEach(this.currentTouches, (activeTouch: TouchObject) => {
2312
+ + Stack() {
2313
+ + }
2314
+ + .width(64)
2315
+ + .height(64)
2316
+ + .backgroundColor("blue")
2317
+ + .borderWidth(2)
2318
+ + .borderColor("white")
2319
+ + .opacity(this.touchIndicatorOpacity)
2320
+ + .position({ x: activeTouch.x - 32, y: activeTouch.y - 32 })
2321
+ + .borderRadius(1000)
2322
+ + .hitTestBehavior(HitTestMode.Transparent)
2323
+ + })
2324
+ + }
2325
+ + .width("100%")
2326
+ + .height("100%")
2327
+ + .hitTestBehavior(HitTestMode.Transparent)
2328
+ + .onTouch(e => {
2329
+ + this.currentTouches = e.touches
2330
+ + this.touchIndicatorOpacity = 0.5
2331
+ + animateTo({
2332
+ + duration: 500,
2333
+ + curve: Curve.Linear,
2334
+ + }, () => {
2335
+ + this.touchIndicatorOpacity = 0
2336
+ + })
2337
+ + })
2338
+ + }
2339
+ +}
2340
+
2341
+
2342
+ ```
2343
+
2344
+ ### `example/harmony/entry/src/main/module.json5`
2345
+
2346
+ ```diff
2347
+ @@ -0,0 +1,52 @@
2348
+ +{
2349
+ + "module": {
2350
+ + "name": "entry",
2351
+ + "type": "entry",
2352
+ + "description": "$string:module_desc",
2353
+ + "mainElement": "EntryAbility",
2354
+ + "deviceTypes": [
2355
+ + "default"
2356
+ + ],
2357
+ + "querySchemes": [
2358
+ + "weixin",
2359
+ + ],
2360
+ + "deliveryWithInstall": true,
2361
+ + "installationFree": false,
2362
+ + "pages": "$profile:main_pages",
2363
+ + // below property is supported from 5.0.0 - it is needed by bundleManager.canOpenLink to check if the app can open some url
2364
+ + // "querySchemes": ["maps", "http", "https", "customDomain"],
2365
+ + "requestPermissions": [
2366
+ + {
2367
+ + "name": "ohos.permission.INTERNET"
2368
+ + },
2369
+ + ],
2370
+ + "metadata": [
2371
+ + {
2372
+ + "name": "OPTLazyForEach",
2373
+ + "value": "true",
2374
+ + }
2375
+ + ],
2376
+ + "abilities": [
2377
+ + {
2378
+ + "name": "EntryAbility",
2379
+ + "srcEntry": "./ets/entryability/EntryAbility.ets",
2380
+ + "description": "$string:EntryAbility_desc",
2381
+ + "icon": "$media:icon",
2382
+ + "label": "$string:EntryAbility_label",
2383
+ + "startWindowIcon": "$media:icon",
2384
+ + "startWindowBackground": "$color:start_window_background",
2385
+ + "visible": true,
2386
+ + "skills": [
2387
+ + {
2388
+ + "entities": [
2389
+ + "entity.system.home"
2390
+ + ],
2391
+ + "actions": [
2392
+ + "action.system.home"
2393
+ + ]
2394
+ + }
2395
+ + ]
2396
+ + }
2397
+ + ]
2398
+ + }
2399
+ +}
2400
+
2401
+
2402
+ ```
2403
+
2404
+ ### `example/harmony/entry/src/main/resources/.gitignore`
2405
+
2406
+ ```diff
2407
+ @@ -0,0 +1 @@
2408
+ +rawfile/assets
2409
+
2410
+ ```
2411
+
2412
+ ### `example/harmony/entry/src/main/resources/base/element/color.json`
2413
+
2414
+ ```diff
2415
+ @@ -0,0 +1,8 @@
2416
+ +{
2417
+ + "color": [
2418
+ + {
2419
+ + "name": "start_window_background",
2420
+ + "value": "#FFFFFF"
2421
+ + }
2422
+ + ]
2423
+ +}
2424
+
2425
+
2426
+ ```
2427
+
2428
+ ### `example/harmony/entry/src/main/resources/base/element/string.json`
2429
+
2430
+ ```diff
2431
+ @@ -0,0 +1,16 @@
2432
+ +{
2433
+ + "string": [
2434
+ + {
2435
+ + "name": "module_desc",
2436
+ + "value": "module description"
2437
+ + },
2438
+ + {
2439
+ + "name": "EntryAbility_desc",
2440
+ + "value": "description"
2441
+ + },
2442
+ + {
2443
+ + "name": "EntryAbility_label",
2444
+ + "value": "RN Tester"
2445
+ + }
2446
+ + ]
2447
+ +}
2448
+
2449
+
2450
+ ```
2451
+
2452
+ ### `example/harmony/entry/src/main/resources/base/media/icon.png`
2453
+
2454
+ ```diff
2455
+ Binary files no preview for this file type
2456
+ ```
2457
+
2458
+ ### `example/harmony/entry/src/main/resources/base/profile/main_pages.json`
2459
+
2460
+ ```diff
2461
+ @@ -0,0 +1,5 @@
2462
+ +{
2463
+ + "src": [
2464
+ + "pages/Index"
2465
+ + ]
2466
+ +}
2467
+
2468
+ ```
2469
+
2470
+ ### `example/harmony/entry/src/main/resources/rawfile/1.txt`
2471
+
2472
+ ```diff
2473
+ @@ -0,0 +1 @@
2474
+ +text test
2475
+
2476
+
2477
+ ```
2478
+
2479
+ ### `example/harmony/format.ps1`
2480
+
2481
+ ```diff
2482
+ @@ -0,0 +1,12 @@
2483
+ +$directoryPath = Split-Path -Parent $MyInvocation.MyCommand.Path
2484
+ +$filePaths = Get-ChildItem $directoryPath -Recurse -Include *.h, *.cpp |
2485
+ +Where-Object {
2486
+ + $_.DirectoryName -notmatch 'third-party' -and
2487
+ + $_.DirectoryName -notmatch 'patches' -and
2488
+ + $_.DirectoryName -notmatch 'node_modules' -and
2489
+ + $_.DirectoryName -notmatch '.cxx' -and
2490
+ + $_.DirectoryName -notmatch 'build'
2491
+ +}
2492
+ +foreach ($filePath in $filePaths) {
2493
+ + & "clang-format.exe" -style=file -i $filePath.FullName
2494
+ +}
2495
+
2496
+
2497
+ ```
2498
+
2499
+ ### `example/harmony/hvigor/.gitignore`
2500
+
2501
+ ```diff
2502
+ @@ -0,0 +1 @@
2503
+ +*.tgz
2504
+
2505
+ ```
2506
+
2507
+ ### `example/harmony/hvigor/hvigor-config.json5`
2508
+
2509
+ ```diff
2510
+ @@ -0,0 +1,21 @@
2511
+ +{
2512
+ + "modelVersion": "5.0.0",
2513
+ + "dependencies": {
2514
+ + },
2515
+ + "execution": {
2516
+ + // "analyze": "default", /* Define the build analyze mode. Value: [ "default" | "verbose" | false ]. Default: "default" */
2517
+ + // "daemon": true, /* Enable daemon compilation. Value: [ true | false ]. Default: true */
2518
+ + // "incremental": true, /* Enable incremental compilation. Value: [ true | false ]. Default: true */
2519
+ + // "parallel": true, /* Enable parallel compilation. Value: [ true | false ]. Default: true */
2520
+ + // "typeCheck": false, /* Enable typeCheck. Value: [ true | false ]. Default: false */
2521
+ + },
2522
+ + "logging": {
2523
+ + // "level": "info" /* Define the log level. Value: [ "debug" | "info" | "warn" | "error" ]. Default: "info" */
2524
+ + },
2525
+ + "debugging": {
2526
+ + "stacktrace": false /* Disable stacktrace compilation. Value: [ true | false ]. Default: false */
2527
+ + },
2528
+ + "nodeOptions": {
2529
+ + // "maxOldSpaceSize": 4096 /* Enable nodeOptions maxOldSpaceSize compilation. Unit M. Used for the daemon process */
2530
+ + }
2531
+ +}
2532
+
2533
+
2534
+ ```
2535
+
2536
+ ### `example/harmony/hvigorfile.ts`
2537
+
2538
+ ```diff
2539
+ @@ -0,0 +1,2 @@
2540
+ +// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
2541
+ +export { appTasks } from '@ohos/hvigor-ohos-plugin';
2542
+
2543
+
2544
+ ```
2545
+
2546
+ ### `example/harmony/oh-package.json5`
2547
+
2548
+ ```diff
2549
+ @@ -0,0 +1,12 @@
2550
+ +{
2551
+ + "modelVersion": "5.0.0",
2552
+ + "license": "ISC",
2553
+ + "name": "rnoh",
2554
+ + "description": "example description",
2555
+ + "repository": {},
2556
+ + "version": "1.0.0",
2557
+ + "overrides": {
2558
+ + "@rnoh/react-native-openharmony": "file:./../node_modules/react-native-harmony/react_native_openharmony.har"
2559
+ + },
2560
+ + "dynamicDependencies": {}
2561
+ +}
2562
+
2563
+
2564
+ ```
2565
+
2566
+ ### `example/index.js`
2567
+
2568
+ ```diff
2569
+ @@ -0,0 +1,28 @@
2570
+ +/**
2571
+ + * MIT License
2572
+ + *
2573
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
2574
+ + *
2575
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
2576
+ + * of this software and associated documentation files (the "Software"), to deal
2577
+ + * in the Software without restriction, including without limitation the rights
2578
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2579
+ + * copies of the Software, and to permit persons to whom the Software is
2580
+ + * furnished to do so, subject to the following conditions:
2581
+ + *
2582
+ + * The above copyright notice and this permission notice shall be included in all
2583
+ + * copies or substantial portions of the Software.
2584
+ + *
2585
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2586
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2587
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2588
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2589
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2590
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2591
+ + * SOFTWARE.
2592
+ + */
2593
+ +import {AppRegistry, View, Text} from 'react-native';
2594
+ +import {name as appName} from './app.json';
2595
+ +import App from './src/codepush';
2596
+ +
2597
+ +AppRegistry.registerComponent(appName, () => App);
2598
+
2599
+
2600
+ ```
2601
+
2602
+ ### `example/jest.config.js`
2603
+
2604
+ ```diff
2605
+ @@ -0,0 +1,5 @@
2606
+ +/** @type {import('ts-jest').JestConfigWithTsJest} */
2607
+ +module.exports = {
2608
+ + preset: 'ts-jest',
2609
+ + testEnvironment: 'node',
2610
+ +};
2611
+
2612
+ ```
2613
+
2614
+ ### `example/metro.config.js`
2615
+
2616
+ ```diff
2617
+ @@ -0,0 +1,24 @@
2618
+ +const {mergeConfig, getDefaultConfig} = require('@react-native/metro-config');
2619
+ +const {createHarmonyMetroConfig} = require('react-native-harmony/metro.config');
2620
+ +
2621
+ +/**
2622
+ + * @type {import("metro-config").ConfigT}
2623
+ + */
2624
+ +const config = {
2625
+ + transformer: {
2626
+ + getTransformOptions: async () => ({
2627
+ + transform: {
2628
+ + experimentalImportSupport: false,
2629
+ + inlineRequires: true,
2630
+ + },
2631
+ + }),
2632
+ + },
2633
+ +};
2634
+ +
2635
+ +module.exports = mergeConfig(
2636
+ + getDefaultConfig(__dirname),
2637
+ + createHarmonyMetroConfig({
2638
+ + reactNativeHarmonyPackageName: 'react-native-harmony',
2639
+ + }),
2640
+ + config,
2641
+ +);
2642
+
2643
+ ```
2644
+
2645
+ ### `example/package.json`
2646
+
2647
+ ```diff
2648
+ @@ -0,0 +1,68 @@
2649
+ +{
2650
+ + "name": "react-native-harmony-tester",
2651
+ + "version": "1.0.0",
2652
+ + "private": true,
2653
+ + "scripts": {
2654
+ + "i": "cd ../ && npm i && npm run pack && cd ./example && npm i",
2655
+ + "reStart": "npm run install:pkg && npm run codegen && hdc rport tcp:8081 tcp:8081 && react-native start",
2656
+ + "start": "hdc rport tcp:8081 tcp:8081 && react-native start",
2657
+ + "codegen": "react-native codegen-harmony --rnoh-module-path ./harmony/entry/oh_modules/@rnoh/react-native-openharmony",
2658
+ + "pack:pkg": "cd ../ && npm run pack && cd ./example",
2659
+ + "install:pkg": "npm uninstall @react-native-ohos/react-native-code-push && npm run pack:pkg && npm i @react-native-ohos/react-native-code-push@file:../react-native-ohos-react-native-code-push-8.2.3.tgz",
2660
+ + "dev": "npm run codegen && react-native bundle-harmony --dev --minify=false",
2661
+ + "prod": "npm run codegen && react-native bundle-harmony --dev=false --minify=true",
2662
+ + "postinstall": "node ./scripts/create-build-profile",
2663
+ + "fast-install-project": "cd ../ && npm i --force && npm run pack && rm -r node_modules && cd ./example && npm i --force",
2664
+ + "fast:pkg": "npm run fast-install-project && npm run dev"
2665
+ + },
2666
+ + "dependencies": {
2667
+ + "@gorhom/portal": "^1.0.14",
2668
+ + "@react-native-ohos/react-native-code-push": "file:../react-native-ohos-react-native-code-push-8.2.3.tgz",
2669
+ + "@rnoh/testerino": "npm:@react-native-oh-tpl/testerino@0.0.9",
2670
+ + "react": "18.2.0",
2671
+ + "react-native": "0.72.5",
2672
+ + "react-native-harmony": "npm:@react-native-oh/react-native-harmony@^0.72.32"
2673
+ + },
2674
+ + "devDependencies": {
2675
+ + "@babel/core": "^7.20.0",
2676
+ + "@babel/preset-env": "^7.20.0",
2677
+ + "@babel/runtime": "^7.20.0",
2678
+ + "@react-native-community/eslint-config": "^3.2.0",
2679
+ + "@react-native/eslint-config": "^0.74.0",
2680
+ + "@react-native/metro-config": "^0.72.6",
2681
+ + "@tsconfig/react-native": "^2.0.2",
2682
+ + "@types/chai": "^4.3.4",
2683
+ + "@types/d3-scale-chromatic": "^3.0.0",
2684
+ + "@types/fs-extra": "^11.0.1",
2685
+ + "@types/jest": "^29.5.5",
2686
+ + "@types/metro-config": "^0.76.2",
2687
+ + "@types/react": "17.0.14",
2688
+ + "@types/react-dom": "17.0.14",
2689
+ + "@types/react-test-renderer": "^18.0.0",
2690
+ + "babel-jest": "^29.2.1",
2691
+ + "csv-parser": "^3.0.0",
2692
+ + "eslint": "^8.19.0",
2693
+ + "eslint-plugin-prettier": "^5.0.1",
2694
+ + "fs-extra": "^11.1.1",
2695
+ + "husky": "^8.0.3",
2696
+ + "jest": "^29.7.0",
2697
+ + "json5": "^2.2.3",
2698
+ + "metro": "^0.76.3",
2699
+ + "metro-config": "^0.76.3",
2700
+ + "metro-react-native-babel-preset": "0.73.9",
2701
+ + "prettier": "3.2.4",
2702
+ + "react-test-renderer": "18.2.0",
2703
+ + "simple-statistics": "^7.8.3",
2704
+ + "ts-jest": "^29.1.1",
2705
+ + "typescript": "^5.3.2",
2706
+ + "yargs": "^17.7.2"
2707
+ + },
2708
+ + "overrides": {
2709
+ + "@rnoh/react-native-harmony-cli": "npm:@react-native-oh/react-native-harmony-cli@^0.0.27",
2710
+ + "@react-native-community/cli": "11.3.6",
2711
+ + "@react-native/codegen": "0.74.0"
2712
+ + },
2713
+ + "resolutions": {
2714
+ + "@react-native-community/cli": "11.3.6"
2715
+ + }
2716
+ +}
2717
+
2718
+ ```
2719
+
2720
+ ### `example/react-native.config.js`
2721
+
2722
+ ```diff
2723
+ @@ -0,0 +1,5 @@
2724
+ +module.exports = {
2725
+ + project: {
2726
+ + },
2727
+ + assets: ['./assets/fonts/'],
2728
+ +};
2729
+
2730
+ ```
2731
+
2732
+ ### `example/scripts/create-build-profile.js`
2733
+
2734
+ ```diff
2735
+ @@ -0,0 +1,39 @@
2736
+ +const fs = require('fs');
2737
+ +const JSON5 = require('json5');
2738
+ +const path = require('path');
2739
+ +
2740
+ +const templatePath = path.join(
2741
+ + __dirname,
2742
+ + '..',
2743
+ + 'harmony',
2744
+ + 'build-profile.template.json5',
2745
+ +);
2746
+ +const existingProfilePath = path.join(
2747
+ + __dirname,
2748
+ + '..',
2749
+ + 'harmony',
2750
+ + 'build-profile.json5',
2751
+ +);
2752
+ +
2753
+ +if (fs.existsSync(existingProfilePath)) {
2754
+ + let existingProfile = JSON5.parse(
2755
+ + fs.readFileSync(existingProfilePath, 'utf-8'),
2756
+ + );
2757
+ + let template = JSON5.parse(fs.readFileSync(templatePath, 'utf-8'));
2758
+ + let signingConfigs =
2759
+ + existingProfile.app && existingProfile.app.signingConfigs;
2760
+ +
2761
+ + existingProfile = {...template};
2762
+ +
2763
+ + if (signingConfigs) {
2764
+ + existingProfile.app.signingConfigs = signingConfigs;
2765
+ + }
2766
+ +
2767
+ + fs.writeFileSync(
2768
+ + existingProfilePath,
2769
+ + JSON5.stringify(existingProfile, null, 2),
2770
+ + );
2771
+ +} else {
2772
+ + // File doesn't exist, create a copy from the template
2773
+ + fs.copyFileSync(templatePath, existingProfilePath);
2774
+ +}
2775
+
2776
+
2777
+ ```
2778
+
2779
+ ### `example/src/codepush.tsx`
2780
+
2781
+ ```diff
2782
+ @@ -0,0 +1,126 @@
2783
+ +/**
2784
+ + * MIT License
2785
+ + *
2786
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
2787
+ + *
2788
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
2789
+ + * of this software and associated documentation files (the "Software"), to deal
2790
+ + * in the Software without restriction, including without limitation the rights
2791
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2792
+ + * copies of the Software, and to permit persons to whom the Software is
2793
+ + * furnished to do so, subject to the following conditions:
2794
+ + *
2795
+ + * The above copyright notice and this permission notice shall be included in all
2796
+ + * copies or substantial portions of the Software.
2797
+ + *
2798
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2799
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2800
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2801
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2802
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2803
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2804
+ + * SOFTWARE.
2805
+ + */
2806
+ +import React, {Component} from 'react'
2807
+ +import {View, Text, StyleSheet, TouchableOpacity} from 'react-native'
2808
+ +import CodePush from 'react-native-code-push';
2809
+ +class App extends Component<any,any>{
2810
+ + constructor(props:any) {
2811
+ + super(props);
2812
+ + this.state={
2813
+ + syncMessage:'',
2814
+ + progress:{}
2815
+ + }
2816
+ + }
2817
+ + componentDidMount() {
2818
+ + console.log('开始检查更新')
2819
+ + this.syncImmediate(); //开始检查更新
2820
+ + }
2821
+ + syncImmediate() {
2822
+ + CodePush.sync(
2823
+ + {
2824
+ + updateDialog: {
2825
+ + appendReleaseDescription: true, //是否显示更新description,默认为false
2826
+ + descriptionPrefix: '更新内容:', //更新说明的前缀。 默认是” Description:
2827
+ + mandatoryContinueButtonLabel: '立即更新', //强制更新的按钮文字,默认为continue
2828
+ + mandatoryUpdateMessage: '', //- 强制更新时,更新通知. Defaults to “An update is available that must be installed.”.
2829
+ + optionalIgnoreButtonLabel: '稍后', //非强制更新时,取消按钮文字,默认是ignore
2830
+ + optionalInstallButtonLabel: '后台更新', //非强制更新时,确认文字. Defaults to “Install”
2831
+ + optionalUpdateMessage: '有新版本了,是否更新?', //非强制更新时,更新通知. Defaults to “An update is available. Would you like to install it?”.
2832
+ + title: '更新提示', //要显示的更新通知的标题. Defaults to “Update available”.
2833
+ + },
2834
+ + },
2835
+ + this.codePushStatusDidChange.bind(this),
2836
+ + this.codePushDownloadDidProgress.bind(this),
2837
+ + );
2838
+ + }
2839
+ +
2840
+ + codePushStatusDidChange(syncStatus:string|number) {
2841
+ + switch (syncStatus) {
2842
+ + case CodePush.SyncStatus.CHECKING_FOR_UPDATE:
2843
+ + this.setState({syncMessage: 'Checking for update.'});
2844
+ + break;
2845
+ + case CodePush.SyncStatus.DOWNLOADING_PACKAGE:
2846
+ + this.setState({syncMessage: 'Downloading package.',progressModalVisible:true});
2847
+ + break;
2848
+ + case CodePush.SyncStatus.AWAITING_USER_ACTION:
2849
+ + this.setState({syncMessage: 'Awaiting user action.'});
2850
+ + break;
2851
+ + case CodePush.SyncStatus.INSTALLING_UPDATE:
2852
+ + this.setState({syncMessage: 'Installing update.',progressModalVisible:true});
2853
+ + break;
2854
+ + case CodePush.SyncStatus.UP_TO_DATE:
2855
+ + this.setState({syncMessage: 'App up to date.', progress: false});
2856
+ + break;
2857
+ + case CodePush.SyncStatus.UPDATE_IGNORED:
2858
+ + this.setState({syncMessage: 'Update cancelled by user.', progress: false,});
2859
+ + break;
2860
+ + case CodePush.SyncStatus.UPDATE_INSTALLED:
2861
+ + this.setState({syncMessage: 'Update installed and will be applied on restart.', progress: false,});
2862
+ + break;
2863
+ + case CodePush.SyncStatus.UNKNOWN_ERROR:
2864
+ + this.setState({syncMessage: 'An unknown error occurred.', progress: false,});
2865
+ + break;
2866
+ + }
2867
+ + }
2868
+ +
2869
+ + codePushDownloadDidProgress(progress:any) {
2870
+ + this.setState({progress});
2871
+ + }
2872
+ +
2873
+ + render(){
2874
+ + return(
2875
+ + <View style={styles.container}>
2876
+ + <Text style={styles.welcome}>欢迎使用热更新--test!</Text>
2877
+ + <Text>SyncStatus: { this.state.syncMessage}</Text>
2878
+ + <Text>{this.state.progressModalVisible.toString()}</Text>
2879
+ + <TouchableOpacity onPress={this.syncImmediate.bind(this)}>
2880
+ + <Text style={styles.syncButton}>Press for dialog-driven sync</Text>
2881
+ + </TouchableOpacity>
2882
+ + </View>
2883
+ + )
2884
+ + }
2885
+ +}
2886
+ +
2887
+ +const styles = StyleSheet.create({
2888
+ + container:{
2889
+ + flex: 1,
2890
+ + alignItems: 'center',
2891
+ + backgroundColor: '#F5FCFF',
2892
+ + paddingTop: 10,
2893
+ + },
2894
+ + welcome:{
2895
+ + fontSize: 20,
2896
+ + textAlign: 'center',
2897
+ + margin: 10,
2898
+ + },
2899
+ + syncButton: {
2900
+ + color: 'green',
2901
+ + fontSize: 17,
2902
+ + },
2903
+ +})
2904
+ +
2905
+ +let codePushOptions = {checkFrequency: CodePush.CheckFrequency.MANUAL};
2906
+ +
2907
+ +
2908
+ +export default CodePush(codePushOptions)(App);
2909
+
2910
+
2911
+ ```
2912
+
2913
+ ### `example/tsconfig.json`
2914
+
2915
+ ```diff
2916
+ @@ -0,0 +1,14 @@
2917
+ +{
2918
+ + "extends": "@tsconfig/react-native/tsconfig.json",
2919
+ + "compilerOptions": {
2920
+ + "jsx": "react-native",
2921
+ + "paths": {
2922
+ + "react-native": [
2923
+ + "./node_modules/react-native-harmony"
2924
+ + ],
2925
+ + },
2926
+ + },
2927
+ + "exclude": [
2928
+ + "harmony"
2929
+ + ]
2930
+ +}
2931
+
2932
+
2933
+ ```
2934
+
2935
+ ### `harmony/codePush/index.ets`
2936
+
2937
+ ```diff
2938
+ @@ -1,7 +1,25 @@
2939
+ -/*
2940
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
2941
+ - * Use of this source code is governed by a MIT license that can be
2942
+ - * found in the LICENSE file.
2943
+ +/**
2944
+ + * MIT License
2945
+ + *
2946
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
2947
+ + *
2948
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
2949
+ + * of this software and associated documentation files (the "Software"), to deal
2950
+ + * in the Software without restriction, including without limitation the rights
2951
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2952
+ + * copies of the Software, and to permit persons to whom the Software is
2953
+ + * furnished to do so, subject to the following conditions:
2954
+ + *
2955
+ + * The above copyright notice and this permission notice shall be included in all
2956
+ + * copies or substantial portions of the Software.
2957
+ + *
2958
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2959
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2960
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2961
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2962
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2963
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2964
+ + * SOFTWARE.
2965
+ */
2966
+
2967
+ import { CodePushPackage } from './src/main/ets/CodePushPackage';
2968
+
2969
+ ```
2970
+
2971
+ ### `harmony/codePush/src/main/ets/CodePush.ts`
2972
+
2973
+ ```diff
2974
+ @@ -1,7 +1,25 @@
2975
+ -/*
2976
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
2977
+ - * Use of this source code is governed by a MIT license that can be
2978
+ - * found in the LICENSE file.
2979
+ +/**
2980
+ + * MIT License
2981
+ + *
2982
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
2983
+ + *
2984
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
2985
+ + * of this software and associated documentation files (the "Software"), to deal
2986
+ + * in the Software without restriction, including without limitation the rights
2987
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2988
+ + * copies of the Software, and to permit persons to whom the Software is
2989
+ + * furnished to do so, subject to the following conditions:
2990
+ + *
2991
+ + * The above copyright notice and this permission notice shall be included in all
2992
+ + * copies or substantial portions of the Software.
2993
+ + *
2994
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2995
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2996
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2997
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2998
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2999
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3000
+ + * SOFTWARE.
3001
+ */
3002
+
3003
+ import common from '@ohos.app.ability.common';
3004
+
3005
+ ```
3006
+
3007
+ ### `harmony/codePush/src/main/ets/CodePushBuilder.ts`
3008
+
3009
+ ```diff
3010
+ @@ -1,7 +1,25 @@
3011
+ -/*
3012
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3013
+ - * Use of this source code is governed by a MIT license that can be
3014
+ - * found in the LICENSE file.
3015
+ +/**
3016
+ + * MIT License
3017
+ + *
3018
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3019
+ + *
3020
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3021
+ + * of this software and associated documentation files (the "Software"), to deal
3022
+ + * in the Software without restriction, including without limitation the rights
3023
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3024
+ + * copies of the Software, and to permit persons to whom the Software is
3025
+ + * furnished to do so, subject to the following conditions:
3026
+ + *
3027
+ + * The above copyright notice and this permission notice shall be included in all
3028
+ + * copies or substantial portions of the Software.
3029
+ + *
3030
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3031
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3032
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3033
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3034
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3035
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3036
+ + * SOFTWARE.
3037
+ */
3038
+
3039
+ import common from '@ohos.app.ability.common';
3040
+
3041
+ ```
3042
+
3043
+ ### `harmony/codePush/src/main/ets/CodePushConstants.ts`
3044
+
3045
+ ```diff
3046
+ @@ -1,7 +1,25 @@
3047
+ -/*
3048
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3049
+ - * Use of this source code is governed by a MIT license that can be
3050
+ - * found in the LICENSE file.
3051
+ +/**
3052
+ + * MIT License
3053
+ + *
3054
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3055
+ + *
3056
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3057
+ + * of this software and associated documentation files (the "Software"), to deal
3058
+ + * in the Software without restriction, including without limitation the rights
3059
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3060
+ + * copies of the Software, and to permit persons to whom the Software is
3061
+ + * furnished to do so, subject to the following conditions:
3062
+ + *
3063
+ + * The above copyright notice and this permission notice shall be included in all
3064
+ + * copies or substantial portions of the Software.
3065
+ + *
3066
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3067
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3068
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3069
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3070
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3071
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3072
+ + * SOFTWARE.
3073
+ */
3074
+
3075
+ export class CodePushConstants {
3076
+
3077
+ ```
3078
+
3079
+ ### `harmony/codePush/src/main/ets/CodePushInstallMode.ts`
3080
+
3081
+ ```diff
3082
+ @@ -1,7 +1,25 @@
3083
+ -/*
3084
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3085
+ - * Use of this source code is governed by a MIT license that can be
3086
+ - * found in the LICENSE file.
3087
+ +/**
3088
+ + * MIT License
3089
+ + *
3090
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3091
+ + *
3092
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3093
+ + * of this software and associated documentation files (the "Software"), to deal
3094
+ + * in the Software without restriction, including without limitation the rights
3095
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3096
+ + * copies of the Software, and to permit persons to whom the Software is
3097
+ + * furnished to do so, subject to the following conditions:
3098
+ + *
3099
+ + * The above copyright notice and this permission notice shall be included in all
3100
+ + * copies or substantial portions of the Software.
3101
+ + *
3102
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3103
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3104
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3105
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3106
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3107
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3108
+ + * SOFTWARE.
3109
+ */
3110
+
3111
+ export const CodePushInstallMode = {
3112
+
3113
+ ```
3114
+
3115
+ ### `harmony/codePush/src/main/ets/CodePushInvalidPublicKeyException.ts`
3116
+
3117
+ ```diff
3118
+ @@ -1,7 +1,25 @@
3119
+ -/*
3120
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3121
+ - * Use of this source code is governed by a MIT license that can be
3122
+ - * found in the LICENSE file.
3123
+ +/**
3124
+ + * MIT License
3125
+ + *
3126
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3127
+ + *
3128
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3129
+ + * of this software and associated documentation files (the "Software"), to deal
3130
+ + * in the Software without restriction, including without limitation the rights
3131
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3132
+ + * copies of the Software, and to permit persons to whom the Software is
3133
+ + * furnished to do so, subject to the following conditions:
3134
+ + *
3135
+ + * The above copyright notice and this permission notice shall be included in all
3136
+ + * copies or substantial portions of the Software.
3137
+ + *
3138
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3139
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3140
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3141
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3142
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3143
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3144
+ + * SOFTWARE.
3145
+ */
3146
+
3147
+ export class CodePushInvalidPublicKeyException extends Error {
3148
+
3149
+ ```
3150
+
3151
+ ### `harmony/codePush/src/main/ets/CodePushInvalidUpdateException.ts`
3152
+
3153
+ ```diff
3154
+ @@ -1,7 +1,25 @@
3155
+ -/*
3156
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3157
+ - * Use of this source code is governed by a MIT license that can be
3158
+ - * found in the LICENSE file.
3159
+ +/**
3160
+ + * MIT License
3161
+ + *
3162
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3163
+ + *
3164
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3165
+ + * of this software and associated documentation files (the "Software"), to deal
3166
+ + * in the Software without restriction, including without limitation the rights
3167
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3168
+ + * copies of the Software, and to permit persons to whom the Software is
3169
+ + * furnished to do so, subject to the following conditions:
3170
+ + *
3171
+ + * The above copyright notice and this permission notice shall be included in all
3172
+ + * copies or substantial portions of the Software.
3173
+ + *
3174
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3175
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3176
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3177
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3178
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3179
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3180
+ + * SOFTWARE.
3181
+ */
3182
+
3183
+ export class CodePushInvalidUpdateException extends Error {
3184
+
3185
+ ```
3186
+
3187
+ ### `harmony/codePush/src/main/ets/CodePushMalformedDataException.ts`
3188
+
3189
+ ```diff
3190
+ @@ -1,7 +1,25 @@
3191
+ -/*
3192
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3193
+ - * Use of this source code is governed by a MIT license that can be
3194
+ - * found in the LICENSE file.
3195
+ +/**
3196
+ + * MIT License
3197
+ + *
3198
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3199
+ + *
3200
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3201
+ + * of this software and associated documentation files (the "Software"), to deal
3202
+ + * in the Software without restriction, including without limitation the rights
3203
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3204
+ + * copies of the Software, and to permit persons to whom the Software is
3205
+ + * furnished to do so, subject to the following conditions:
3206
+ + *
3207
+ + * The above copyright notice and this permission notice shall be included in all
3208
+ + * copies or substantial portions of the Software.
3209
+ + *
3210
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3211
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3212
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3213
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3214
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3215
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3216
+ + * SOFTWARE.
3217
+ */
3218
+
3219
+ export class CodePushMalformedDataException extends Error {
3220
+
3221
+ ```
3222
+
3223
+ ### `harmony/codePush/src/main/ets/CodePushNativeModule.ts`
3224
+
3225
+ ```diff
3226
+ @@ -1,7 +1,25 @@
3227
+ -/*
3228
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3229
+ - * Use of this source code is governed by a MIT license that can be
3230
+ - * found in the LICENSE file.
3231
+ +/**
3232
+ + * MIT License
3233
+ + *
3234
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3235
+ + *
3236
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3237
+ + * of this software and associated documentation files (the "Software"), to deal
3238
+ + * in the Software without restriction, including without limitation the rights
3239
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3240
+ + * copies of the Software, and to permit persons to whom the Software is
3241
+ + * furnished to do so, subject to the following conditions:
3242
+ + *
3243
+ + * The above copyright notice and this permission notice shall be included in all
3244
+ + * copies or substantial portions of the Software.
3245
+ + *
3246
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3247
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3248
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3249
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3250
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3251
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3252
+ + * SOFTWARE.
3253
+ */
3254
+
3255
+ import { CodePushConstants } from './CodePushConstants';
3256
+ @@ -53,14 +71,12 @@ export class CodePushNativeModule extends UITurboModule implements TM.RTNCodePus
3257
+ private preferences: dataPreferences.Preferences | null = null;
3258
+ private mTelemetryManager: CodePushTelemetryManager | null = null;
3259
+ private mSettingsManager: SettingsManager | null = null;
3260
+ + private _restartInProgress: boolean = false;
3261
+ + private _allowed: boolean = true;
3262
+ private mUpdateManager: CodePushUpdateManager | null = null;
3263
+ private installMode: number = -1;
3264
+ private ready: boolean = false;
3265
+
3266
+ - sync(): Promise<unknown> {
3267
+ - throw new Error('Method not implemented.');
3268
+ - }
3269
+ -
3270
+ constructor(rnContext: UITurboModuleContext, codePush: CodePush) {
3271
+ super(rnContext);
3272
+ Logger.info(TAG, `constructor start`)
3273
+ @@ -167,20 +183,15 @@ export class CodePushNativeModule extends UITurboModule implements TM.RTNCodePus
3274
+ // The caller wants the running update, but the current
3275
+ // one is pending, so we need to grab the previous.
3276
+
3277
+ - // let previousPackage = new CodePushUpdateManager('').getPreviousPackage();
3278
+ + let previousPackage = new CodePushUpdateManager('').getPreviousPackage();
3279
+
3280
+ - // if (previousPackage == null) {
3281
+ - // Logger.info(TAG, `currentPackage previousPackage is null`);
3282
+ - // return null;
3283
+ - // }
3284
+ -
3285
+ - // return previousPackage;
3286
+ - let previousPackage = new CodePushUpdateManager('').getCurrentPackageInfo();
3287
+ - const packageHash = {
3288
+ - packageHash:previousPackage['previousPackage']
3289
+ + if (previousPackage == null) {
3290
+ + Logger.info(TAG, `currentPackage previousPackage is null`);
3291
+ + return null;
3292
+ }
3293
+ - Logger.info(TAG, `doInBackgroundForUpdateMetadata previousPackage=${packageHash}`);
3294
+ - return packageHash
3295
+ +
3296
+ + Logger.info(TAG, `doInBackgroundForUpdateMetadata previousPackage=${JSON.stringify(previousPackage)}`);
3297
+ + return previousPackage;
3298
+ } else {
3299
+ if (this.mCodePush.isRunningBinaryVersion()) {
3300
+ currentPackage["_isDebugOnly"] = true;
3301
+ @@ -298,6 +309,7 @@ export class CodePushNativeModule extends UITurboModule implements TM.RTNCodePus
3302
+ async disallow() {
3303
+ return new Promise((resolve) => {
3304
+ Logger.info(TAG, "Disallowing restarts");
3305
+ + this._allowed = false;
3306
+ resolve(null);
3307
+ })
3308
+ }
3309
+ @@ -319,6 +331,33 @@ export class CodePushNativeModule extends UITurboModule implements TM.RTNCodePus
3310
+ }
3311
+ }
3312
+
3313
+ + restartAppInternal(onlyIfUpdateIsPending: boolean) {
3314
+ + // 1. 防重入检查
3315
+ + if (this._restartInProgress) {
3316
+ + this._restartQueue.push(onlyIfUpdateIsPending);
3317
+ + return;
3318
+ + }
3319
+ + // 2. 允许重启检查
3320
+ + else if (!this._allowed) {
3321
+ + this._restartQueue.push(onlyIfUpdateIsPending);
3322
+ + return;
3323
+ + }
3324
+ + this._restartInProgress = true;
3325
+ + // 3. onlyIfUpdateIsPending 检查
3326
+ + if (!onlyIfUpdateIsPending || this.mSettingsManager.isPendingUpdate(null)) {
3327
+ + this.loadBundle();
3328
+ + this._restartInProgress = false;
3329
+ + return;
3330
+ + }
3331
+ + this._restartInProgress = false;
3332
+ + // 4. 处理排队请求
3333
+ + if (this._restartQueue.length > 0) {
3334
+ + let buf: boolean = this._restartQueue[0];
3335
+ + this._restartQueue.splice(0, 1);
3336
+ + this.restartAppInternal(buf);
3337
+ + }
3338
+ + }
3339
+ +
3340
+ async setLatestRollbackInfo(packageHash: string): Promise<null | string> {
3341
+ try {
3342
+ this.mSettingsManager.setLatestRollbackInfo(packageHash);
3343
+ @@ -362,13 +401,10 @@ export class CodePushNativeModule extends UITurboModule implements TM.RTNCodePus
3344
+
3345
+ }
3346
+
3347
+ - restartAppInternal(onlyIfUpdateIsPending: boolean) {
3348
+ - this.loadBundle();
3349
+ - }
3350
+ -
3351
+ async allow() {
3352
+ return new Promise((resolve) => {
3353
+ Logger.info(TAG, "Re-allowing restarts");
3354
+ + this._allowed = true;
3355
+ if (this._restartQueue.length > 0) {
3356
+ Logger.info(TAG, "Executing pending restart");
3357
+ let buf: boolean = this._restartQueue[0];
3358
+ @@ -426,6 +462,9 @@ export class CodePushNativeModule extends UITurboModule implements TM.RTNCodePus
3359
+ if(this.installMode === 0 || this.installMode === -1){
3360
+ this.ctx.devToolsController.eventEmitter.emit("RELOAD", { reason: 'HotReload2' })
3361
+ }
3362
+ + if (this.installMode === 1) {
3363
+ + this.installMode = -1;
3364
+ + }
3365
+ Logger.info(TAG, "restartAppInternal RELOAD end");
3366
+ }
3367
+
3368
+
3369
+ ```
3370
+
3371
+ ### `harmony/codePush/src/main/ets/CodePushNotInitializedException.ts`
3372
+
3373
+ ```diff
3374
+ @@ -1,7 +1,25 @@
3375
+ -/*
3376
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3377
+ - * Use of this source code is governed by a MIT license that can be
3378
+ - * found in the LICENSE file.
3379
+ +/**
3380
+ + * MIT License
3381
+ + *
3382
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3383
+ + *
3384
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3385
+ + * of this software and associated documentation files (the "Software"), to deal
3386
+ + * in the Software without restriction, including without limitation the rights
3387
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3388
+ + * copies of the Software, and to permit persons to whom the Software is
3389
+ + * furnished to do so, subject to the following conditions:
3390
+ + *
3391
+ + * The above copyright notice and this permission notice shall be included in all
3392
+ + * copies or substantial portions of the Software.
3393
+ + *
3394
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3395
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3396
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3397
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3398
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3399
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3400
+ + * SOFTWARE.
3401
+ */
3402
+
3403
+ export class CodePushNotInitializedException extends Error {
3404
+
3405
+ ```
3406
+
3407
+ ### `harmony/codePush/src/main/ets/CodePushPackage.ets`
3408
+
3409
+ ```diff
3410
+ @@ -1,7 +1,25 @@
3411
+ -/*
3412
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3413
+ - * Use of this source code is governed by a MIT license that can be
3414
+ - * found in the LICENSE file.
3415
+ +/**
3416
+ + * MIT License
3417
+ + *
3418
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3419
+ + *
3420
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3421
+ + * of this software and associated documentation files (the "Software"), to deal
3422
+ + * in the Software without restriction, including without limitation the rights
3423
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3424
+ + * copies of the Software, and to permit persons to whom the Software is
3425
+ + * furnished to do so, subject to the following conditions:
3426
+ + *
3427
+ + * The above copyright notice and this permission notice shall be included in all
3428
+ + * copies or substantial portions of the Software.
3429
+ + *
3430
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3431
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3432
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3433
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3434
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3435
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3436
+ + * SOFTWARE.
3437
+ */
3438
+
3439
+ import { RNOHPackage, UITurboModule,UITurboModuleContext,UITurboModuleFactory } from "@rnoh/react-native-openharmony";
3440
+
3441
+ ```
3442
+
3443
+ ### `harmony/codePush/src/main/ets/CodePushTelemetryManager.ts`
3444
+
3445
+ ```diff
3446
+ @@ -1,7 +1,25 @@
3447
+ -/*
3448
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3449
+ - * Use of this source code is governed by a MIT license that can be
3450
+ - * found in the LICENSE file.
3451
+ +/**
3452
+ + * MIT License
3453
+ + *
3454
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3455
+ + *
3456
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3457
+ + * of this software and associated documentation files (the "Software"), to deal
3458
+ + * in the Software without restriction, including without limitation the rights
3459
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3460
+ + * copies of the Software, and to permit persons to whom the Software is
3461
+ + * furnished to do so, subject to the following conditions:
3462
+ + *
3463
+ + * The above copyright notice and this permission notice shall be included in all
3464
+ + * copies or substantial portions of the Software.
3465
+ + *
3466
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3467
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3468
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3469
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3470
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3471
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3472
+ + * SOFTWARE.
3473
+ */
3474
+
3475
+ import dataPreferences from '@ohos.data.preferences';
3476
+
3477
+ ```
3478
+
3479
+ ### `harmony/codePush/src/main/ets/CodePushUnknownException.ts`
3480
+
3481
+ ```diff
3482
+ @@ -1,7 +1,25 @@
3483
+ -/*
3484
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3485
+ - * Use of this source code is governed by a MIT license that can be
3486
+ - * found in the LICENSE file.
3487
+ +/**
3488
+ + * MIT License
3489
+ + *
3490
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3491
+ + *
3492
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3493
+ + * of this software and associated documentation files (the "Software"), to deal
3494
+ + * in the Software without restriction, including without limitation the rights
3495
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3496
+ + * copies of the Software, and to permit persons to whom the Software is
3497
+ + * furnished to do so, subject to the following conditions:
3498
+ + *
3499
+ + * The above copyright notice and this permission notice shall be included in all
3500
+ + * copies or substantial portions of the Software.
3501
+ + *
3502
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3503
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3504
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3505
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3506
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3507
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3508
+ + * SOFTWARE.
3509
+ */
3510
+
3511
+ export class CodePushUnknownException extends Error {
3512
+
3513
+ ```
3514
+
3515
+ ### `harmony/codePush/src/main/ets/CodePushUpdateManager.ts`
3516
+
3517
+ ```diff
3518
+ @@ -1,7 +1,25 @@
3519
+ -/*
3520
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3521
+ - * Use of this source code is governed by a MIT license that can be
3522
+ - * found in the LICENSE file.
3523
+ +/**
3524
+ + * MIT License
3525
+ + *
3526
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3527
+ + *
3528
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3529
+ + * of this software and associated documentation files (the "Software"), to deal
3530
+ + * in the Software without restriction, including without limitation the rights
3531
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3532
+ + * copies of the Software, and to permit persons to whom the Software is
3533
+ + * furnished to do so, subject to the following conditions:
3534
+ + *
3535
+ + * The above copyright notice and this permission notice shall be included in all
3536
+ + * copies or substantial portions of the Software.
3537
+ + *
3538
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3539
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3540
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3541
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3542
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3543
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3544
+ + * SOFTWARE.
3545
+ */
3546
+
3547
+ import { CodePush } from './CodePush';
3548
+
3549
+ ```
3550
+
3551
+ ### `harmony/codePush/src/main/ets/CodePushUpdateState.ts`
3552
+
3553
+ ```diff
3554
+ @@ -1,7 +1,25 @@
3555
+ -/*
3556
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3557
+ - * Use of this source code is governed by a MIT license that can be
3558
+ - * found in the LICENSE file.
3559
+ +/**
3560
+ + * MIT License
3561
+ + *
3562
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3563
+ + *
3564
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3565
+ + * of this software and associated documentation files (the "Software"), to deal
3566
+ + * in the Software without restriction, including without limitation the rights
3567
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3568
+ + * copies of the Software, and to permit persons to whom the Software is
3569
+ + * furnished to do so, subject to the following conditions:
3570
+ + *
3571
+ + * The above copyright notice and this permission notice shall be included in all
3572
+ + * copies or substantial portions of the Software.
3573
+ + *
3574
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3575
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3576
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3577
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3578
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3579
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3580
+ + * SOFTWARE.
3581
+ */
3582
+
3583
+ export enum CodePushUpdateState {
3584
+
3585
+ ```
3586
+
3587
+ ### `harmony/codePush/src/main/ets/CodePushUpdateUtils.ts`
3588
+
3589
+ ```diff
3590
+ @@ -1,7 +1,25 @@
3591
+ -/*
3592
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3593
+ - * Use of this source code is governed by a MIT license that can be
3594
+ - * found in the LICENSE file.
3595
+ +/**
3596
+ + * MIT License
3597
+ + *
3598
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3599
+ + *
3600
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3601
+ + * of this software and associated documentation files (the "Software"), to deal
3602
+ + * in the Software without restriction, including without limitation the rights
3603
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3604
+ + * copies of the Software, and to permit persons to whom the Software is
3605
+ + * furnished to do so, subject to the following conditions:
3606
+ + *
3607
+ + * The above copyright notice and this permission notice shall be included in all
3608
+ + * copies or substantial portions of the Software.
3609
+ + *
3610
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3611
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3612
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3613
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3614
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3615
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3616
+ + * SOFTWARE.
3617
+ */
3618
+
3619
+ import fs, { ListFileOptions } from "@ohos.file.fs";
3620
+
3621
+ ```
3622
+
3623
+ ### `harmony/codePush/src/main/ets/CodePushUtils.ts`
3624
+
3625
+ ```diff
3626
+ @@ -1,7 +1,25 @@
3627
+ -/*
3628
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3629
+ - * Use of this source code is governed by a MIT license that can be
3630
+ - * found in the LICENSE file.
3631
+ +/**
3632
+ + * MIT License
3633
+ + *
3634
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3635
+ + *
3636
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3637
+ + * of this software and associated documentation files (the "Software"), to deal
3638
+ + * in the Software without restriction, including without limitation the rights
3639
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3640
+ + * copies of the Software, and to permit persons to whom the Software is
3641
+ + * furnished to do so, subject to the following conditions:
3642
+ + *
3643
+ + * The above copyright notice and this permission notice shall be included in all
3644
+ + * copies or substantial portions of the Software.
3645
+ + *
3646
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3647
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3648
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3649
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3650
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3651
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3652
+ + * SOFTWARE.
3653
+ */
3654
+
3655
+ import fileio from "@ohos.fileio";
3656
+
3657
+ ```
3658
+
3659
+ ### `harmony/codePush/src/main/ets/FileUtils.ts`
3660
+
3661
+ ```diff
3662
+ @@ -1,7 +1,25 @@
3663
+ -/*
3664
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3665
+ - * Use of this source code is governed by a MIT license that can be
3666
+ - * found in the LICENSE file.
3667
+ +/**
3668
+ + * MIT License
3669
+ + *
3670
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3671
+ + *
3672
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3673
+ + * of this software and associated documentation files (the "Software"), to deal
3674
+ + * in the Software without restriction, including without limitation the rights
3675
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3676
+ + * copies of the Software, and to permit persons to whom the Software is
3677
+ + * furnished to do so, subject to the following conditions:
3678
+ + *
3679
+ + * The above copyright notice and this permission notice shall be included in all
3680
+ + * copies or substantial portions of the Software.
3681
+ + *
3682
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3683
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3684
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3685
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3686
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3687
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3688
+ + * SOFTWARE.
3689
+ */
3690
+
3691
+ import fs, { Options, Filter, ListFileOptions } from '@ohos.file.fs';
3692
+
3693
+ ```
3694
+
3695
+ ### `harmony/codePush/src/main/ets/Logger.ts`
3696
+
3697
+ ```diff
3698
+ @@ -1,7 +1,25 @@
3699
+ -/*
3700
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3701
+ - * Use of this source code is governed by a MIT license that can be
3702
+ - * found in the LICENSE file.
3703
+ +/**
3704
+ + * MIT License
3705
+ + *
3706
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3707
+ + *
3708
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3709
+ + * of this software and associated documentation files (the "Software"), to deal
3710
+ + * in the Software without restriction, including without limitation the rights
3711
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3712
+ + * copies of the Software, and to permit persons to whom the Software is
3713
+ + * furnished to do so, subject to the following conditions:
3714
+ + *
3715
+ + * The above copyright notice and this permission notice shall be included in all
3716
+ + * copies or substantial portions of the Software.
3717
+ + *
3718
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3719
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3720
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3721
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3722
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3723
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3724
+ + * SOFTWARE.
3725
+ */
3726
+
3727
+ import hilog from '@ohos.hilog';
3728
+
3729
+ ```
3730
+
3731
+ ### `harmony/codePush/src/main/ets/SettingsManager.ts`
3732
+
3733
+ ```diff
3734
+ @@ -1,7 +1,25 @@
3735
+ -/*
3736
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3737
+ - * Use of this source code is governed by a MIT license that can be
3738
+ - * found in the LICENSE file.
3739
+ +/**
3740
+ + * MIT License
3741
+ + *
3742
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3743
+ + *
3744
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3745
+ + * of this software and associated documentation files (the "Software"), to deal
3746
+ + * in the Software without restriction, including without limitation the rights
3747
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3748
+ + * copies of the Software, and to permit persons to whom the Software is
3749
+ + * furnished to do so, subject to the following conditions:
3750
+ + *
3751
+ + * The above copyright notice and this permission notice shall be included in all
3752
+ + * copies or substantial portions of the Software.
3753
+ + *
3754
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3755
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3756
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3757
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3758
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3759
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3760
+ + * SOFTWARE.
3761
+ */
3762
+
3763
+ import { CodePushConstants } from "./CodePushConstants";
3764
+
3765
+ ```
3766
+
3767
+ ### `harmony/codePush/src/main/ets/generated/turboModules/RTNCodePush.ts`
3768
+
3769
+ ```diff
3770
+ @@ -8,8 +8,6 @@ export namespace RTNCodePush {
3771
+ export const NAME = 'RTNCodePush' as const
3772
+
3773
+ export interface Spec {
3774
+ - sync(): Promise<unknown>;
3775
+ -
3776
+ isFailedUpdate(packageHash: string): Promise<boolean>;
3777
+
3778
+ allow(): void;
3779
+
3780
+ ```
3781
+
3782
+ ### `harmony/codePush/ts.ets`
3783
+
3784
+ ```diff
3785
+ @@ -1,7 +1,25 @@
3786
+ -/*
3787
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3788
+ - * Use of this source code is governed by a MIT license that can be
3789
+ - * found in the LICENSE file.
3790
+ +/**
3791
+ + * MIT License
3792
+ + *
3793
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3794
+ + *
3795
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3796
+ + * of this software and associated documentation files (the "Software"), to deal
3797
+ + * in the Software without restriction, including without limitation the rights
3798
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3799
+ + * copies of the Software, and to permit persons to whom the Software is
3800
+ + * furnished to do so, subject to the following conditions:
3801
+ + *
3802
+ + * The above copyright notice and this permission notice shall be included in all
3803
+ + * copies or substantial portions of the Software.
3804
+ + *
3805
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3806
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3807
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3808
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3809
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3810
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3811
+ + * SOFTWARE.
3812
+ */
3813
+
3814
+ export * from "./src/main/ets/CodePushNativeModule";
3815
+
3816
+ ```
3817
+
3818
+ ### `package.json`
3819
+
3820
+ ```diff
3821
+ @@ -23,6 +23,7 @@
3822
+ "author": "Microsoft Corporation",
3823
+ "license": "MIT",
3824
+ "scripts": {
3825
+ + "pack": "npm pack",
3826
+ "codegen-lib": "react-native codegen-lib-harmony --no-safety-check --npm-package-name react-native-code-push --cpp-output-path ./harmony/codePush/src/main/cpp/generated --ets-output-path ./harmony/codePush/src/main/ets/generated --turbo-modules-spec-paths ./src --arkts-components-spec-paths ./src"
3827
+ },
3828
+ "repository": {
3829
+
3830
+ ```
3831
+
3832
+ ### `src/NativeCodePush.ts`
3833
+
3834
+ ```diff
3835
+ @@ -1,7 +1,25 @@
3836
+ -/*
3837
+ - * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved
3838
+ - * Use of this source code is governed by a MIT license that can be
3839
+ - * found in the LICENSE file.
3840
+ +/**
3841
+ + * MIT License
3842
+ + *
3843
+ + * Copyright (C) 2024 Huawei Device Co., Ltd.
3844
+ + *
3845
+ + * Permission is hereby granted, free of charge, to any person obtaining a copy
3846
+ + * of this software and associated documentation files (the "Software"), to deal
3847
+ + * in the Software without restriction, including without limitation the rights
3848
+ + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3849
+ + * copies of the Software, and to permit persons to whom the Software is
3850
+ + * furnished to do so, subject to the following conditions:
3851
+ + *
3852
+ + * The above copyright notice and this permission notice shall be included in all
3853
+ + * copies or substantial portions of the Software.
3854
+ + *
3855
+ + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3856
+ + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3857
+ + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3858
+ + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3859
+ + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3860
+ + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3861
+ + * SOFTWARE.
3862
+ */
3863
+
3864
+ import type { TurboModule } from "react-native/Libraries/TurboModule/RCTExport";
3865
+
3866
+ ```