[feat] add HarmonyOS desktop and mobile clients,issue #117

This commit is contained in:
kunkundi
2026-10-16 00:42:55 +08:00
parent 43a0789c1e
commit 45bf6ec4ee
149 changed files with 11587 additions and 93 deletions
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.16)
project(crossdesk_harmony LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
get_filename_component(HARMONY_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../.." ABSOLUTE)
set(CORE_LIBRARY "${HARMONY_ROOT}/entry/libs/${OHOS_ARCH}/libcrossdesk_harmony_core.so")
if(NOT EXISTS "${CORE_LIBRARY}")
message(FATAL_ERROR "Build MiniRTC first: python3 apps/harmony/scripts/build.py --mobile --native-only")
endif()
add_library(crossdesk_core SHARED IMPORTED)
set_target_properties(crossdesk_core PROPERTIES
IMPORTED_LOCATION "${CORE_LIBRARY}"
IMPORTED_SONAME "libcrossdesk_harmony_core.so")
add_library(crossdesk SHARED napi_init.cpp)
# HAP libraries are resolved by the app's linker namespace. The host build
# directory is not a useful runtime search path on a HarmonyOS device.
set_target_properties(crossdesk PROPERTIES SKIP_BUILD_RPATH TRUE)
target_include_directories(crossdesk PRIVATE "${HARMONY_ROOT}/native")
target_link_libraries(crossdesk PRIVATE crossdesk_core libace_napi.z.so)
@@ -0,0 +1,37 @@
#include <napi/native_api.h>
#include "mobile_session.h"
#include <string>
namespace {
napi_value Command(napi_env env, napi_callback_info info) {
size_t count = 1; napi_value argument;
if (napi_get_cb_info(env, info, &count, &argument, nullptr, nullptr) != napi_ok || count != 1) {
napi_throw_type_error(env, nullptr, "Expected a JSON command string"); return nullptr;
}
size_t size = 0;
if (napi_get_value_string_utf8(env, argument, nullptr, 0, &size) != napi_ok || size > 1024 * 1024) {
napi_throw_type_error(env, nullptr, "Invalid command"); return nullptr;
}
std::string value(size + 1, '\0');
napi_get_value_string_utf8(env, argument, value.data(), value.size(), &size); value.resize(size);
crossdesk::harmony::MobileCommand(value);
napi_value result; napi_get_undefined(env, &result); return result;
}
napi_value Poll(napi_env env, napi_callback_info) {
const std::string data = crossdesk::harmony::MobilePoll();
napi_value result;
napi_create_string_utf8(env, data.data(), data.size(), &result); return result;
}
napi_value Init(napi_env env, napi_value exports) {
napi_property_descriptor properties[] = {
{"mobileCommand", nullptr, Command, nullptr, nullptr, nullptr, napi_default, nullptr},
{"mobilePoll", nullptr, Poll, nullptr, nullptr, nullptr, napi_default, nullptr}};
napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties);
napi_add_env_cleanup_hook(env, [](void*) {
crossdesk::harmony::MobileShutdown();
}, nullptr);
return exports;
}
napi_module module = {1, 0, nullptr, Init, "crossdesk", nullptr, {0}};
}
extern "C" __attribute__((constructor)) void RegisterCrossDesk() { napi_module_register(&module); }
@@ -0,0 +1,2 @@
export const mobileCommand: (json: string) => void;
export const mobilePoll: () => string;
@@ -0,0 +1,5 @@
{
"name": "libcrossdesk.so",
"version": "0.1.0",
"types": "index.d.ts"
}