mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-18 19:00:39 +08:00
react-native-pushy适配harmony (#461)
* init * update * udpate * update * update * update * add pushy build time logic
This commit is contained in:
6
Example/harmony_use_pushy/harmony/entry/.gitignore
vendored
Normal file
6
Example/harmony_use_pushy/harmony/entry/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
/node_modules
|
||||
/oh_modules
|
||||
/.preview
|
||||
/build
|
||||
/.cxx
|
||||
/.test
|
33
Example/harmony_use_pushy/harmony/entry/build-profile.json5
Normal file
33
Example/harmony_use_pushy/harmony/entry/build-profile.json5
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"apiType": "stageMode",
|
||||
"buildOption": {
|
||||
"externalNativeOptions": {
|
||||
"path": "./src/main/cpp/CMakeLists.txt",
|
||||
"arguments": "",
|
||||
"cppFlags": "",
|
||||
},
|
||||
},
|
||||
"buildOptionSet": [
|
||||
{
|
||||
"name": "release",
|
||||
"arkOptions": {
|
||||
"obfuscation": {
|
||||
"ruleOptions": {
|
||||
"enable": false,
|
||||
"files": [
|
||||
"./obfuscation-rules.txt"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
],
|
||||
"targets": [
|
||||
{
|
||||
"name": "default"
|
||||
},
|
||||
{
|
||||
"name": "ohosTest",
|
||||
}
|
||||
]
|
||||
}
|
32
Example/harmony_use_pushy/harmony/entry/hvigorfile.ts
Normal file
32
Example/harmony_use_pushy/harmony/entry/hvigorfile.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
export function generatePushyBuildTime(str?: string) {
|
||||
return {
|
||||
pluginId: 'PushyBuildTimePlugin',
|
||||
apply(pluginContext) {
|
||||
pluginContext.registerTask({
|
||||
name: 'pushy_build_time',
|
||||
run: (taskContext) => {
|
||||
const metaFilePath = path.resolve(__dirname, 'src/main/resources/rawfile/meta.json');
|
||||
const dirPath = path.dirname(metaFilePath);
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
const buildTime = new Date().toISOString();
|
||||
const metaContent = { pushy_build_time : buildTime };
|
||||
fs.writeFileSync(metaFilePath, JSON.stringify(metaContent, null, 4));
|
||||
console.log(`Build time written to ${metaFilePath}`);
|
||||
|
||||
},
|
||||
dependencies: [],
|
||||
postDependencies: ['default@BuildJS']
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
system: hapTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||
plugins:[generatePushyBuildTime()] /* Custom plugin to extend the functionality of Hvigor. */
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
# Define project specific obfuscation rules here.
|
||||
# You can include the obfuscation configuration files in the current module's build-profile.json5.
|
||||
#
|
||||
# For more details, see
|
||||
# https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5
|
||||
|
||||
# Obfuscation options:
|
||||
# -disable-obfuscation: disable all obfuscations
|
||||
# -enable-property-obfuscation: obfuscate the property names
|
||||
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
|
||||
# -compact: remove unnecessary blank spaces and all line feeds
|
||||
# -remove-log: remove all console.* statements
|
||||
# -print-namecache: print the name cache that contains the mapping from the old names to new names
|
||||
# -apply-namecache: reuse the given cache file
|
||||
|
||||
# Keep options:
|
||||
# -keep-property-name: specifies property names that you want to keep
|
||||
# -keep-global-name: specifies names that you want to keep in the global scope
|
||||
|
||||
-enable-property-obfuscation
|
||||
-enable-toplevel-obfuscation
|
||||
-enable-filename-obfuscation
|
||||
-enable-export-obfuscation
|
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"meta": {
|
||||
"stableOrder": true
|
||||
},
|
||||
"lockfileVersion": 3,
|
||||
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
|
||||
"specifiers": {
|
||||
"pushy@../../node_modules/react-native-update/harmony": "pushy@../../node_modules/react-native-update/harmony",
|
||||
"rnoh@../../libs/rnoh": "rnoh@../../libs/rnoh"
|
||||
},
|
||||
"packages": {
|
||||
"pushy@../../node_modules/react-native-update/harmony": {
|
||||
"name": "pushy",
|
||||
"version": "3.1.0-0.0.7",
|
||||
"resolved": "../../node_modules/react-native-update/harmony",
|
||||
"registryType": "local",
|
||||
"dependencies": {
|
||||
"rnoh": "file:../../../libs/rnoh"
|
||||
}
|
||||
},
|
||||
"rnoh@../../libs/rnoh": {
|
||||
"name": "rnoh",
|
||||
"version": "0.72.12",
|
||||
"resolved": "../../libs/rnoh",
|
||||
"registryType": "local"
|
||||
}
|
||||
}
|
||||
}
|
13
Example/harmony_use_pushy/harmony/entry/oh-package.json5
Normal file
13
Example/harmony_use_pushy/harmony/entry/oh-package.json5
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "entry",
|
||||
"version": "1.0.0",
|
||||
"description": "Please describe the basic information.",
|
||||
"main": "",
|
||||
"author": "",
|
||||
"license": "",
|
||||
"dependencies": {
|
||||
"rnoh": "file:../../libs/rnoh",
|
||||
"pushy": "file:../../node_modules/react-native-update/harmony"
|
||||
}
|
||||
}
|
||||
|
1
Example/harmony_use_pushy/harmony/entry/src/main/cpp/.gitignore
vendored
Normal file
1
Example/harmony_use_pushy/harmony/entry/src/main/cpp/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
jsbundle.h
|
@@ -0,0 +1,15 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(rnapp)
|
||||
set(RNOH_APP_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(NODE_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../node_modules")
|
||||
set(RNOH_CPP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../libs/rnoh/src/main/cpp")
|
||||
set(OH_MODULES "${CMAKE_CURRENT_SOURCE_DIR}/../../../oh_modules")
|
||||
add_subdirectory("${OH_MODULES}/pushy/src/main/cpp" ./pushy)
|
||||
|
||||
add_subdirectory("${RNOH_CPP_DIR}" ./rn)
|
||||
add_library(rnoh_app SHARED
|
||||
"./PackageProvider.cpp"
|
||||
"${RNOH_CPP_DIR}/RNOHAppNapiBridge.cpp"
|
||||
)
|
||||
target_link_libraries(rnoh_app PUBLIC rnoh)
|
||||
target_link_libraries(rnoh_app PUBLIC rnoh_pushy)
|
@@ -0,0 +1,9 @@
|
||||
#include "RNOH/PackageProvider.h"
|
||||
#include "PushyPackage.h"
|
||||
using namespace rnoh;
|
||||
|
||||
std::vector<std::shared_ptr<Package>> PackageProvider::getPackages(Package::Context ctx) {
|
||||
return {
|
||||
std::make_shared<PushyPackage>(ctx)
|
||||
};
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
import type {RNPackageContext, RNPackage} from 'rnoh/ts';
|
||||
import {PushyPackage} from 'pushy/ts';
|
||||
|
||||
export function createRNPackages(ctx: RNPackageContext): RNPackage[] {
|
||||
return [new PushyPackage(ctx)];
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
import {RNAbility} from 'rnoh/ts';
|
||||
|
||||
export default class EntryAbility extends RNAbility {
|
||||
getPagePath() {
|
||||
return 'pages/Index';
|
||||
}
|
||||
|
||||
shouldCleanUpRNInstance__hack() {
|
||||
return true // Used by RNOH devs. If set to true, the app may crash.
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { BackupExtensionAbility, BundleVersion } from '@kit.CoreFileKit';
|
||||
|
||||
export default class EntryBackupAbility extends BackupExtensionAbility {
|
||||
async onBackup() {
|
||||
hilog.info(0x0000, 'testTag', 'onBackup ok');
|
||||
}
|
||||
|
||||
async onRestore(bundleVersion: BundleVersion) {
|
||||
hilog.info(0x0000, 'testTag', 'onRestore ok %{public}s', JSON.stringify(bundleVersion));
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
import { FileJSBundleProvider } from 'pushy/src/main/ets/FileJSBundleProvider';
|
||||
import { ComponentBuilderContext, JSBundleProvider, RNOHLogger } from 'rnoh';
|
||||
import {
|
||||
RNApp,
|
||||
RNAbility,
|
||||
AnyJSBundleProvider,
|
||||
ResourceJSBundleProvider,
|
||||
TraceJSBundleProviderDecorator,
|
||||
} from 'rnoh'
|
||||
import { createRNPackages } from '../RNPackagesFactory'
|
||||
|
||||
@Builder
|
||||
export function CustomComponentBuilder(ctx: ComponentBuilderContext) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct Index {
|
||||
@StorageLink('RNAbility') private rnAbility: RNAbility | undefined = undefined
|
||||
@State shouldShow: boolean = false
|
||||
@State message: string = 'Hello World';
|
||||
|
||||
aboutToAppear(): void {
|
||||
this.shouldShow = true
|
||||
}
|
||||
|
||||
onBackPress(): boolean | undefined {
|
||||
// NOTE: this is required since `Ability`'s `onBackPressed` function always
|
||||
// terminates or puts the app in the background, but we want Ark to ignore it completely
|
||||
// when handled by RN
|
||||
return this.rnAbility?.onBackPress();
|
||||
}
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
if (this.rnAbility && this.shouldShow) {
|
||||
RNApp({
|
||||
rnInstanceConfig: { createRNPackages },
|
||||
initialProps: { "foo": "bar" } as Record<string, string>,
|
||||
appKey: "harmony_use_pushy",
|
||||
buildCustomComponent: CustomComponentBuilder,
|
||||
onSetUp: (rnInstance) => {
|
||||
rnInstance.enableFeatureFlag("ENABLE_RN_INSTANCE_CLEAN_UP")
|
||||
},
|
||||
jsBundleProvider: new TraceJSBundleProviderDecorator(
|
||||
new AnyJSBundleProvider([
|
||||
// MetroJSBundleProvider.fromServerIp('127.0.0.1'),
|
||||
// new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'hermes_bundle.hbc'),
|
||||
new FileJSBundleProvider(this.rnAbility.context),
|
||||
new ResourceJSBundleProvider(this.rnAbility.context.resourceManager, 'bundle.harmony.js')
|
||||
]),
|
||||
this.rnAbility.getLogger()),
|
||||
})
|
||||
}
|
||||
}
|
||||
.height('100%')
|
||||
.width('100%')
|
||||
}
|
||||
}
|
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "entry",
|
||||
"type": "entry",
|
||||
"description": "$string:module_desc",
|
||||
"mainElement": "EntryAbility",
|
||||
"deviceTypes": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"2in1"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false,
|
||||
"pages": "$profile:main_pages",
|
||||
"abilities": [
|
||||
{
|
||||
"name": "EntryAbility",
|
||||
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||
"description": "$string:EntryAbility_desc",
|
||||
"icon": "$media:layered_image",
|
||||
"label": "$string:EntryAbility_label",
|
||||
"startWindowIcon": "$media:startIcon",
|
||||
"startWindowBackground": "$color:start_window_background",
|
||||
"exported": true,
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"extensionAbilities": [
|
||||
{
|
||||
"name": "EntryBackupAbility",
|
||||
"srcEntry": "./ets/entrybackupability/EntryBackupAbility.ets",
|
||||
"type": "backup",
|
||||
"exported": false,
|
||||
"metadata": [
|
||||
{
|
||||
"name": "ohos.extension.backup",
|
||||
"resource": "$profile:backup_config"
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
"requestPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.WRITE_MEDIA",
|
||||
"reason": "$string:reason_write_media",
|
||||
"usedScene": {
|
||||
"when": "always",
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.READ_MEDIA",
|
||||
"reason": "$string:reason_read_media",
|
||||
"usedScene": {
|
||||
"when": "always",
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.INTERNET"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"color": [
|
||||
{
|
||||
"name": "start_window_background",
|
||||
"value": "#FFFFFF"
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "Access_location",
|
||||
"value": "access location"
|
||||
},
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
},
|
||||
{
|
||||
"name": "reason_write_media",
|
||||
"value": "Write files to internal storage"
|
||||
},
|
||||
{
|
||||
"name": "reason_read_media",
|
||||
"value": "Read files to internal storage"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"layered-image":
|
||||
{
|
||||
"background" : "$media:background",
|
||||
"foreground" : "$media:foreground"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"allowToBackupRestore": true
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"src": [
|
||||
"pages/Index"
|
||||
]
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "module description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
File diff suppressed because one or more lines are too long
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "module_desc",
|
||||
"value": "模块描述"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_desc",
|
||||
"value": "description"
|
||||
},
|
||||
{
|
||||
"name": "EntryAbility_label",
|
||||
"value": "label"
|
||||
}
|
||||
]
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
import { hilog } from '@kit.PerformanceAnalysisKit';
|
||||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
||||
|
||||
export default function abilityTest() {
|
||||
describe('ActsAbilityTest', () => {
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
beforeAll(() => {
|
||||
// Presets an action, which is performed only once before all test cases of the test suite start.
|
||||
// This API supports only one parameter: preset action function.
|
||||
})
|
||||
beforeEach(() => {
|
||||
// Presets an action, which is performed before each unit test case starts.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: preset action function.
|
||||
})
|
||||
afterEach(() => {
|
||||
// Presets a clear action, which is performed after each unit test case ends.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: clear action function.
|
||||
})
|
||||
afterAll(() => {
|
||||
// Presets a clear action, which is performed after all test cases of the test suite end.
|
||||
// This API supports only one parameter: clear action function.
|
||||
})
|
||||
it('assertContain', 0, () => {
|
||||
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
||||
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
|
||||
let a = 'abc';
|
||||
let b = 'b';
|
||||
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
|
||||
expect(a).assertContain(b);
|
||||
expect(a).assertEqual(a);
|
||||
})
|
||||
})
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
import abilityTest from './Ability.test';
|
||||
|
||||
export default function testsuite() {
|
||||
abilityTest();
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"module": {
|
||||
"name": "entry_test",
|
||||
"type": "feature",
|
||||
"deviceTypes": [
|
||||
"phone",
|
||||
"tablet",
|
||||
"2in1"
|
||||
],
|
||||
"deliveryWithInstall": true,
|
||||
"installationFree": false
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
import localUnitTest from './LocalUnit.test';
|
||||
|
||||
export default function testsuite() {
|
||||
localUnitTest();
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium';
|
||||
|
||||
export default function localUnitTest() {
|
||||
describe('localUnitTest', () => {
|
||||
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||
beforeAll(() => {
|
||||
// Presets an action, which is performed only once before all test cases of the test suite start.
|
||||
// This API supports only one parameter: preset action function.
|
||||
});
|
||||
beforeEach(() => {
|
||||
// Presets an action, which is performed before each unit test case starts.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: preset action function.
|
||||
});
|
||||
afterEach(() => {
|
||||
// Presets a clear action, which is performed after each unit test case ends.
|
||||
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||
// This API supports only one parameter: clear action function.
|
||||
});
|
||||
afterAll(() => {
|
||||
// Presets a clear action, which is performed after all test cases of the test suite end.
|
||||
// This API supports only one parameter: clear action function.
|
||||
});
|
||||
it('assertContain', 0, () => {
|
||||
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
||||
let a = 'abc';
|
||||
let b = 'b';
|
||||
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
|
||||
expect(a).assertContain(b);
|
||||
expect(a).assertEqual(a);
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user