Skip to content

Commit ed351d9

Browse files
committed
optimise harmony
1 parent 3a22996 commit ed351d9

9 files changed

Lines changed: 337 additions & 382 deletions
Lines changed: 89 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,96 @@
1-
21
#include "PushyTurboModule.h"
32

4-
using namespace rnoh;
53
using namespace facebook;
4+
using namespace rnoh;
65

7-
static jsi::Value _hostFunction_PushyTurboModule_getConstants(
8-
jsi::Runtime &rt,
9-
react::TurboModule & turboModule,
10-
const jsi::Value* args,
11-
size_t count)
12-
{
13-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"getConstants", args, count));
14-
}
15-
16-
static jsi::Value _hostFunction_PushyTurboModule_setLocalHashInfo(
17-
jsi::Runtime &rt,
18-
react::TurboModule & turboModule,
19-
const jsi::Value* args,
20-
size_t count)
21-
{
22-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"setLocalHashInfo", args, count));
23-
}
24-
25-
static jsi::Value _hostFunction_PushyTurboModule_getLocalHashInfo(
26-
jsi::Runtime &rt,
27-
react::TurboModule & turboModule,
28-
const jsi::Value* args,
29-
size_t count)
30-
{
31-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"getLocalHashInfo", args, count));
32-
}
33-
34-
static jsi::Value _hostFunction_PushyTurboModule_setUuid(
35-
jsi::Runtime &rt,
36-
react::TurboModule & turboModule,
37-
const jsi::Value* args,
38-
size_t count)
39-
{
40-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"setUuid", args, count));
41-
}
42-
43-
static jsi::Value _hostFunction_PushyTurboModule_reloadUpdate(
44-
jsi::Runtime &rt,
45-
react::TurboModule & turboModule,
46-
const jsi::Value* args,
47-
size_t count)
48-
{
49-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"reloadUpdate", args, count));
50-
}
51-
52-
static jsi::Value _hostFunction_PushyTurboModule_setNeedUpdate(
53-
jsi::Runtime &rt,
54-
react::TurboModule & turboModule,
55-
const jsi::Value* args,
56-
size_t count)
57-
{
58-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"setNeedUpdate", args, count));
59-
}
60-
61-
static jsi::Value _hostFunction_PushyTurboModule_markSuccess(
62-
jsi::Runtime &rt,
63-
react::TurboModule & turboModule,
64-
const jsi::Value* args,
65-
size_t count)
66-
{
67-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"markSuccess", args, count));
68-
}
69-
70-
static jsi::Value _hostFunction_PushyTurboModule_downloadPatchFromPpk(
71-
jsi::Runtime &rt,
72-
react::TurboModule & turboModule,
73-
const jsi::Value* args,
74-
size_t count)
75-
{
76-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadPatchFromPpk", args, count));
77-
}
78-
79-
static jsi::Value _hostFunction_PushyTurboModule_downloadPatchFromPackage(
80-
jsi::Runtime &rt,
81-
react::TurboModule & turboModule,
82-
const jsi::Value* args,
83-
size_t count)
84-
{
85-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadPatchFromPackage", args, count));
86-
}
87-
88-
static jsi::Value _hostFunction_PushyTurboModule_downloadFullUpdate(
89-
jsi::Runtime &rt,
90-
react::TurboModule & turboModule,
91-
const jsi::Value* args,
92-
size_t count)
93-
{
94-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadFullUpdate", args, count));
95-
}
96-
97-
static jsi::Value _hostFunction_PushyTurboModule_downloadAndInstallApk(
98-
jsi::Runtime &rt,
99-
react::TurboModule & turboModule,
100-
const jsi::Value* args,
101-
size_t count)
102-
{
103-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).callAsync(rt,"downloadAndInstallApk", args, count));
104-
}
105-
106-
6+
namespace {
1077

108-
static jsi::Value _hostFunction_PushyTurboModule_addListener(
8+
jsi::Value CallSync(
1099
jsi::Runtime &rt,
110-
react::TurboModule & turboModule,
111-
const jsi::Value* args,
112-
size_t count)
113-
{
114-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"addListener", args, count));
115-
}
116-
117-
static jsi::Value _hostFunction_PushyTurboModule_removeListeners(
10+
react::TurboModule &turboModule,
11+
const char *methodName,
12+
const jsi::Value *args,
13+
size_t count) {
14+
return jsi::Value(
15+
static_cast<ArkTSTurboModule &>(turboModule).call(
16+
rt, methodName, args, count));
17+
}
18+
19+
jsi::Value CallAsync(
11820
jsi::Runtime &rt,
119-
react::TurboModule & turboModule,
120-
const jsi::Value* args,
121-
size_t count)
122-
{
123-
return jsi::Value(static_cast<ArkTSTurboModule &> (turboModule).call(rt,"removeListeners", args, count));
124-
}
125-
126-
PushyTurboModule::PushyTurboModule(const ArkTSTurboModule::Context ctx, const std::string name)
127-
: ArkTSTurboModule(ctx,name)
128-
{
129-
methodMap_["getConstants"]= MethodMetadata{1, _hostFunction_PushyTurboModule_getConstants};
130-
methodMap_["setLocalHashInfo"]= MethodMetadata{2, _hostFunction_PushyTurboModule_setLocalHashInfo};
131-
methodMap_["getLocalHashInfo"]= MethodMetadata{3, _hostFunction_PushyTurboModule_getLocalHashInfo};
132-
methodMap_["setUuid"]= MethodMetadata{1, _hostFunction_PushyTurboModule_setUuid};
133-
methodMap_["reloadUpdate"]= MethodMetadata{0, _hostFunction_PushyTurboModule_reloadUpdate};
134-
methodMap_["setNeedUpdate"]= MethodMetadata{0, _hostFunction_PushyTurboModule_setNeedUpdate};
135-
methodMap_["markSuccess"]= MethodMetadata{0, _hostFunction_PushyTurboModule_markSuccess};
136-
methodMap_["downloadPatchFromPpk"]= MethodMetadata{0, _hostFunction_PushyTurboModule_downloadPatchFromPpk};
137-
methodMap_["downloadPatchFromPackage"]= MethodMetadata{0, _hostFunction_PushyTurboModule_downloadPatchFromPackage};
138-
methodMap_["downloadFullUpdate"]= MethodMetadata{0, _hostFunction_PushyTurboModule_downloadFullUpdate};
139-
methodMap_["downloadAndInstallApk"]= MethodMetadata{0, _hostFunction_PushyTurboModule_downloadAndInstallApk};
140-
methodMap_["addListener"]= MethodMetadata{1, _hostFunction_PushyTurboModule_addListener};
141-
methodMap_["removeListeners"]= MethodMetadata{1, _hostFunction_PushyTurboModule_removeListeners};
142-
}
21+
react::TurboModule &turboModule,
22+
const char *methodName,
23+
const jsi::Value *args,
24+
size_t count) {
25+
return jsi::Value(
26+
static_cast<ArkTSTurboModule &>(turboModule).callAsync(
27+
rt, methodName, args, count));
28+
}
29+
30+
#define PUSHY_SYNC_METHOD(method_name) \
31+
static jsi::Value HostFunction_##method_name( \
32+
jsi::Runtime &rt, \
33+
react::TurboModule &turboModule, \
34+
const jsi::Value *args, \
35+
size_t count) { \
36+
return CallSync(rt, turboModule, #method_name, args, count); \
37+
}
38+
39+
#define PUSHY_ASYNC_METHOD(method_name) \
40+
static jsi::Value HostFunction_##method_name( \
41+
jsi::Runtime &rt, \
42+
react::TurboModule &turboModule, \
43+
const jsi::Value *args, \
44+
size_t count) { \
45+
return CallAsync(rt, turboModule, #method_name, args, count); \
46+
}
47+
48+
PUSHY_SYNC_METHOD(getConstants)
49+
PUSHY_SYNC_METHOD(setLocalHashInfo)
50+
PUSHY_SYNC_METHOD(getLocalHashInfo)
51+
PUSHY_SYNC_METHOD(setUuid)
52+
PUSHY_SYNC_METHOD(setNeedUpdate)
53+
PUSHY_SYNC_METHOD(markSuccess)
54+
PUSHY_SYNC_METHOD(addListener)
55+
PUSHY_SYNC_METHOD(removeListeners)
56+
57+
PUSHY_ASYNC_METHOD(reloadUpdate)
58+
PUSHY_ASYNC_METHOD(restartApp)
59+
PUSHY_ASYNC_METHOD(downloadPatchFromPpk)
60+
PUSHY_ASYNC_METHOD(downloadPatchFromPackage)
61+
PUSHY_ASYNC_METHOD(downloadFullUpdate)
62+
PUSHY_ASYNC_METHOD(downloadAndInstallApk)
63+
64+
#undef PUSHY_SYNC_METHOD
65+
#undef PUSHY_ASYNC_METHOD
66+
67+
} // namespace
68+
69+
PushyTurboModule::PushyTurboModule(
70+
const ArkTSTurboModule::Context ctx,
71+
const std::string name)
72+
: ArkTSTurboModule(ctx, name) {
73+
const auto registerMethod =
74+
[this](const std::string &methodName,
75+
size_t argCount,
76+
auto hostFunction) {
77+
methodMap_[methodName] = MethodMetadata{argCount, hostFunction};
78+
};
79+
80+
registerMethod("getConstants", 0, HostFunction_getConstants);
81+
registerMethod("setLocalHashInfo", 2, HostFunction_setLocalHashInfo);
82+
registerMethod("getLocalHashInfo", 1, HostFunction_getLocalHashInfo);
83+
registerMethod("setUuid", 1, HostFunction_setUuid);
84+
registerMethod("reloadUpdate", 1, HostFunction_reloadUpdate);
85+
registerMethod("restartApp", 0, HostFunction_restartApp);
86+
registerMethod("setNeedUpdate", 1, HostFunction_setNeedUpdate);
87+
registerMethod("markSuccess", 0, HostFunction_markSuccess);
88+
registerMethod("downloadPatchFromPpk", 1, HostFunction_downloadPatchFromPpk);
89+
registerMethod(
90+
"downloadPatchFromPackage", 1, HostFunction_downloadPatchFromPackage);
91+
registerMethod("downloadFullUpdate", 1, HostFunction_downloadFullUpdate);
92+
registerMethod(
93+
"downloadAndInstallApk", 1, HostFunction_downloadAndInstallApk);
94+
registerMethod("addListener", 1, HostFunction_addListener);
95+
registerMethod("removeListeners", 1, HostFunction_removeListeners);
96+
}

harmony/pushy/src/main/cpp/PushyTurboModule.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222
* SOFTWARE.
2323
*/
2424

25-
#ifndef GEO_LOCATION_TURBOMODULE_H
26-
#define GEO_LOCATION_TURBOMODULE_H
25+
#ifndef PUSHY_TURBOMODULE_H
26+
#define PUSHY_TURBOMODULE_H
2727

2828
#include <ReactCommon/TurboModule.h>
2929
#include "RNOH/ArkTSTurboModule.h"
3030

3131
namespace rnoh {
3232
class JSI_EXPORT PushyTurboModule : public ArkTSTurboModule {
33-
public:
34-
PushyTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
33+
public:
34+
PushyTurboModule(const ArkTSTurboModule::Context ctx, const std::string name);
3535
};
3636
} // namespace rnoh
3737

38-
#endif
38+
#endif

harmony/pushy/src/main/ets/DownloadTaskParams.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export class DownloadTaskParams {
99
static readonly TASK_TYPE_PATCH_FROM_PPK: number = 3; // 从PPK补丁
1010
static readonly TASK_TYPE_PLAIN_DOWNLOAD: number = 4; // 普通下载
1111

12-
type: number; // 任务类型
13-
url: string; // 下载URL
14-
hash: string; // 文件哈希值
15-
originHash: string; // 原始文件哈希值
16-
targetFile: string; // 目标文件路径
17-
unzipDirectory: string; // 解压目录路径
18-
originDirectory: string; // 原始文件目录路径
12+
type: number = DownloadTaskParams.TASK_TYPE_CLEANUP; // 任务类型
13+
url: string = ''; // 下载URL
14+
hash: string = ''; // 文件哈希值
15+
originHash: string = ''; // 原始文件哈希值
16+
targetFile: string = ''; // 目标文件路径
17+
unzipDirectory: string = ''; // 解压目录路径
18+
originDirectory: string = ''; // 原始文件目录路径
1919
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import {
22
RNOHPackage,
3-
UITurboModule,
4-
UITurboModuleContext,
53
} from '@rnoh/react-native-openharmony';
6-
import { PushyTurboModule } from './PushyTurboModule';
4+
import { createPushyTurboModuleFactoryMap } from './PushyPackageFactory';
75

86
export class PushyPackage extends RNOHPackage {
9-
override getUITurboModuleFactoryByNameMap(): Map<
10-
string,
11-
(ctx: UITurboModuleContext) => UITurboModule | null
12-
> {
13-
return new Map<string, (ctx: UITurboModuleContext) => UITurboModule>()
14-
.set(PushyTurboModule.NAME, (ctx) => new PushyTurboModule(ctx));
7+
override getUITurboModuleFactoryByNameMap() {
8+
return createPushyTurboModuleFactoryMap();
159
}
1610
}
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import {
22
RNPackage,
3-
UITurboModule,
4-
UITurboModuleContext,
53
} from '@rnoh/react-native-openharmony/ts';
6-
import { PushyTurboModule } from './PushyTurboModule';
4+
import { createPushyTurboModuleFactoryMap } from './PushyPackageFactory';
75

86
export class PushyPackage extends RNPackage {
9-
override getUITurboModuleFactoryByNameMap(): Map<
10-
string,
11-
(ctx: UITurboModuleContext) => UITurboModule | null
12-
> {
13-
return new Map<string, (ctx: UITurboModuleContext) => UITurboModule>()
14-
.set(PushyTurboModule.NAME, (ctx) => new PushyTurboModule(ctx));
7+
override getUITurboModuleFactoryByNameMap() {
8+
return createPushyTurboModuleFactoryMap();
159
}
1610
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {
2+
UITurboModule,
3+
UITurboModuleContext,
4+
} from '@rnoh/react-native-openharmony/ts';
5+
import { PushyTurboModule } from './PushyTurboModule';
6+
7+
export function createPushyTurboModuleFactoryMap(): Map<
8+
string,
9+
(ctx: UITurboModuleContext) => UITurboModule | null
10+
> {
11+
return new Map<string, (ctx: UITurboModuleContext) => UITurboModule | null>([
12+
[PushyTurboModule.NAME, (ctx) => new PushyTurboModule(ctx)],
13+
]);
14+
}

0 commit comments

Comments
 (0)