Skip to content

Commit f8a5f9f

Browse files
committed
Add OpenHarmony platform support (stub implementation)
1 parent cab1ff0 commit f8a5f9f

14 files changed

+1188
-2
lines changed

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
.vs/
33
.vscode/
44
build/
5-
cmake-build-debug/
65
build-android/
6+
build-ios/
7+
build-linux/
8+
build-macos/
9+
build-ohos/
10+
build-windows/
11+
cmake-build-debug/
712

813
# Generated test binaries and object files
914
*.o
1015
*_test
1116
callback_test
1217
simple_test
13-
event_test
18+
event_test

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ elseif(WIN32)
3838
file(GLOB PLATFORM_SOURCES "platform/windows/*.cpp")
3939
elseif(ANDROID)
4040
file(GLOB PLATFORM_SOURCES "platform/android/*.cpp")
41+
elseif(CMAKE_SYSTEM_NAME STREQUAL "OHOS")
42+
file(GLOB PLATFORM_SOURCES "platform/ohos/*.cpp")
4143
else()
4244
set(PLATFORM_SOURCES "")
4345
endif()
@@ -77,4 +79,6 @@ elseif(WIN32)
7779
target_link_libraries(nativeapi PUBLIC user32 shell32 dwmapi gdiplus crypt32)
7880
elseif(ANDROID)
7981
target_link_libraries(nativeapi PUBLIC log android)
82+
elseif(CMAKE_SYSTEM_NAME STREQUAL "OHOS")
83+
target_link_libraries(nativeapi PUBLIC hilog_ndk.z)
8084
endif ()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifdef __OHOS__
2+
#include <hilog/log.h>
3+
#endif
4+
#include <iostream>
5+
#include "../../accessibility_manager.h"
6+
7+
#ifdef __OHOS__
8+
#define HILOG_WARN(...) HILOG_WARN(LOG_CORE, LOG_TAG, __VA_ARGS__)
9+
#else
10+
#define HILOG_WARN(...) std::cerr << "[WARN] " << __VA_ARGS__ << std::endl
11+
#endif
12+
13+
namespace nativeapi {
14+
15+
AccessibilityManager::AccessibilityManager() : enabled_(false) {}
16+
AccessibilityManager::~AccessibilityManager() {}
17+
18+
void AccessibilityManager::Enable() {
19+
enabled_ = true;
20+
}
21+
22+
bool AccessibilityManager::IsEnabled() {
23+
return enabled_;
24+
}
25+
26+
} // namespace nativeapi
27+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#ifdef __OHOS__
2+
#include <hilog/log.h>
3+
#endif
4+
#include <iostream>
5+
#include "../../application.h"
6+
7+
// Temporarily disable logging to avoid macro conflicts
8+
#define HILOG_WARN(...) ((void)0)
9+
10+
namespace nativeapi {
11+
12+
class Application::Impl {
13+
public:
14+
Impl() {}
15+
};
16+
17+
Application::Application() : pimpl_(std::make_unique<Impl>()) {}
18+
Application::~Application() {}
19+
20+
int Application::Run() {
21+
HILOG_WARN("Application::Run not applicable on OpenHarmony (handled by Ability lifecycle)");
22+
return 0;
23+
}
24+
25+
int Application::Run(std::shared_ptr<Window> window) {
26+
HILOG_WARN("Application::Run with window not applicable on OpenHarmony");
27+
return 0;
28+
}
29+
30+
void Application::Quit(int exit_code) {
31+
HILOG_WARN("Application::Quit requests Ability terminate");
32+
}
33+
34+
bool Application::IsRunning() const {
35+
return true;
36+
}
37+
38+
bool Application::IsSingleInstance() const {
39+
return false;
40+
}
41+
42+
bool Application::SetIcon(const std::string& icon_path) {
43+
HILOG_WARN("Application::SetIcon not implemented on OpenHarmony");
44+
return false;
45+
}
46+
47+
bool Application::SetDockIconVisible(bool visible) {
48+
HILOG_WARN("Application::SetDockIconVisible not applicable on OpenHarmony");
49+
return false;
50+
}
51+
52+
bool Application::SetMenuBar(std::shared_ptr<Menu> menu) {
53+
HILOG_WARN("Application::SetMenuBar not implemented on OpenHarmony");
54+
return false;
55+
}
56+
57+
std::shared_ptr<Window> Application::GetPrimaryWindow() const {
58+
return nullptr;
59+
}
60+
61+
void Application::SetPrimaryWindow(std::shared_ptr<Window> window) {
62+
HILOG_WARN("Application::SetPrimaryWindow not implemented on OpenHarmony");
63+
}
64+
65+
} // namespace nativeapi
66+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifdef __OHOS__
2+
#include <hilog/log.h>
3+
#endif
4+
#include <iostream>
5+
#include "../../display_manager.h"
6+
7+
// Temporarily disable logging to avoid macro conflicts
8+
#define HILOG_WARN(...) ((void)0)
9+
10+
namespace nativeapi {
11+
12+
DisplayManager::DisplayManager() {}
13+
14+
DisplayManager::~DisplayManager() {}
15+
16+
Display DisplayManager::GetPrimary() {
17+
return Display();
18+
}
19+
20+
std::vector<Display> DisplayManager::GetAll() {
21+
std::vector<Display> displays;
22+
displays.push_back(Display());
23+
return displays;
24+
}
25+
26+
Point DisplayManager::GetCursorPosition() {
27+
return Point{0, 0};
28+
}
29+
30+
} // namespace nativeapi

src/platform/ohos/display_ohos.cpp

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#ifdef __OHOS__
2+
#include <hilog/log.h>
3+
#endif
4+
#include <memory>
5+
#include <string>
6+
#include <utility>
7+
#include "../../display.h"
8+
9+
#ifdef __OHOS__
10+
#define LOG_CORE 0xD001700
11+
// Note: LOG_TAG is defined in hilog/log.h as NULL,
12+
// redefine to avoid warnings if needed
13+
#undef LOG_TAG
14+
#define LOG_TAG "NativeApi"
15+
#endif
16+
17+
namespace nativeapi {
18+
19+
class Display::Impl {
20+
public:
21+
Impl() = default;
22+
Impl(void* display) : native_display_(display) {}
23+
24+
void* native_display_ = nullptr;
25+
};
26+
27+
Display::Display() : pimpl_(std::make_unique<Impl>()) {}
28+
29+
Display::Display(void* display) : pimpl_(std::make_unique<Impl>(display)) {}
30+
31+
Display::Display(const Display& other) : pimpl_(std::make_unique<Impl>(*other.pimpl_)) {}
32+
33+
Display& Display::operator=(const Display& other) {
34+
if (this != &other) {
35+
*pimpl_ = *other.pimpl_;
36+
}
37+
return *this;
38+
}
39+
40+
Display::Display(Display&& other) noexcept : pimpl_(std::move(other.pimpl_)) {}
41+
42+
Display& Display::operator=(Display&& other) noexcept {
43+
if (this != &other) {
44+
pimpl_ = std::move(other.pimpl_);
45+
}
46+
return *this;
47+
}
48+
49+
Display::~Display() = default;
50+
51+
void* Display::GetNativeObjectInternal() const {
52+
return pimpl_->native_display_;
53+
}
54+
55+
std::string Display::GetId() const {
56+
return "primary";
57+
}
58+
59+
std::string Display::GetName() const {
60+
return "Primary Display";
61+
}
62+
63+
Point Display::GetPosition() const {
64+
return {0.0, 0.0};
65+
}
66+
67+
Size Display::GetSize() const {
68+
// Default display size for OpenHarmony devices
69+
return {360.0, 780.0};
70+
}
71+
72+
Rectangle Display::GetWorkArea() const {
73+
// Default work area matches display size
74+
Size size = GetSize();
75+
return {0.0, 0.0, size.width, size.height};
76+
}
77+
78+
double Display::GetScaleFactor() const {
79+
return 1.0;
80+
}
81+
82+
bool Display::IsPrimary() const {
83+
return true;
84+
}
85+
86+
DisplayOrientation Display::GetOrientation() const {
87+
return DisplayOrientation::kPortrait;
88+
}
89+
90+
int Display::GetRefreshRate() const {
91+
return 60;
92+
}
93+
94+
int Display::GetBitDepth() const {
95+
return 32;
96+
}
97+
98+
} // namespace nativeapi
99+

src/platform/ohos/image_ohos.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#ifdef __OHOS__
2+
#include <hilog/log.h>
3+
#endif
4+
#include <memory>
5+
#include <string>
6+
#include <utility>
7+
#include "../../image.h"
8+
9+
#ifdef __OHOS__
10+
#define LOG_CORE 0xD001700
11+
// Note: LOG_TAG is defined in hilog/log.h as NULL,
12+
// redefine to avoid warnings if needed
13+
#undef LOG_TAG
14+
#define LOG_TAG "NativeApi"
15+
#endif
16+
17+
namespace nativeapi {
18+
19+
class Image::Impl {
20+
public:
21+
Impl() = default;
22+
23+
void* native_image_ = nullptr;
24+
std::string source_;
25+
Size size_ = {0, 0};
26+
std::string format_ = "Unknown";
27+
};
28+
29+
Image::Image() : pimpl_(std::make_unique<Impl>()) {}
30+
31+
Image::~Image() = default;
32+
33+
Image::Image(const Image& other) : pimpl_(std::make_unique<Impl>(*other.pimpl_)) {}
34+
35+
Image::Image(Image&& other) noexcept : pimpl_(std::move(other.pimpl_)) {}
36+
37+
std::shared_ptr<Image> Image::FromFile(const std::string& file_path) {
38+
// Return nullptr - not implemented on OpenHarmony yet
39+
return nullptr;
40+
}
41+
42+
std::shared_ptr<Image> Image::FromBase64(const std::string& base64_data) {
43+
// Return nullptr - not implemented on OpenHarmony yet
44+
return nullptr;
45+
}
46+
47+
Size Image::GetSize() const {
48+
return pimpl_->size_;
49+
}
50+
51+
std::string Image::GetFormat() const {
52+
return pimpl_->format_;
53+
}
54+
55+
std::string Image::ToBase64() const {
56+
// Return empty string - not implemented on OpenHarmony yet
57+
return "";
58+
}
59+
60+
bool Image::SaveToFile(const std::string& file_path) const {
61+
// Return false - not implemented on OpenHarmony yet
62+
return false;
63+
}
64+
65+
void* Image::GetNativeObjectInternal() const {
66+
return pimpl_->native_image_;
67+
}
68+
69+
} // namespace nativeapi
70+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifdef __OHOS__
2+
#include <hilog/log.h>
3+
#endif
4+
#include <memory>
5+
#include "../../keyboard_monitor.h"
6+
7+
#ifdef __OHOS__
8+
#define LOG_CORE 0xD001700
9+
// Note: LOG_TAG is defined in hilog/log.h as NULL,
10+
// redefine to avoid warnings if needed
11+
#undef LOG_TAG
12+
#define LOG_TAG "NativeApi"
13+
#endif
14+
15+
namespace nativeapi {
16+
17+
class KeyboardMonitor::Impl {
18+
public:
19+
Impl(KeyboardMonitor* monitor) : monitor_(monitor) {}
20+
21+
KeyboardMonitor* monitor_;
22+
};
23+
24+
KeyboardMonitor::KeyboardMonitor() : impl_(std::make_unique<Impl>(this)) {}
25+
26+
KeyboardMonitor::~KeyboardMonitor() {
27+
Stop();
28+
}
29+
30+
void KeyboardMonitor::Start() {
31+
// Not implemented on OpenHarmony yet
32+
}
33+
34+
void KeyboardMonitor::Stop() {
35+
// Not implemented on OpenHarmony yet
36+
}
37+
38+
bool KeyboardMonitor::IsMonitoring() const {
39+
return false;
40+
}
41+
42+
EventEmitter<KeyboardEvent>& KeyboardMonitor::GetInternalEventEmitter() {
43+
return *this;
44+
}
45+
46+
} // namespace nativeapi
47+

0 commit comments

Comments
 (0)