Skip to content

Commit a3c106e

Browse files
committed
Refactor event monitoring to Start/StopEventListening
Replaces SetupEventMonitoring and CleanupEventMonitoring methods with StartEventListening and StopEventListening across all platform-specific WindowManager implementations. Updates the WindowManager interface to use the new methods and removes the old ones, improving clarity and aligning with EventEmitter lifecycle hooks.
1 parent c3ff8c1 commit a3c106e

File tree

7 files changed

+116
-115
lines changed

7 files changed

+116
-115
lines changed

src/platform/android/window_manager_android.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,36 +58,24 @@ class WindowManager::Impl {
5858
Impl(WindowManager* manager) : manager_(manager) {}
5959
~Impl() {}
6060

61-
void SetupEventMonitoring() {
61+
void StartEventListening() {
6262
// On Android, event monitoring is done through Activity callbacks
6363
// Setup will be handled by the Activity lifecycle
6464
ALOGI("Window event monitoring setup");
6565
}
6666

67-
void CleanupEventMonitoring() { ALOGI("Window event monitoring cleanup"); }
67+
void StopEventListening() { ALOGI("Window event monitoring cleanup"); }
6868

6969
private:
7070
WindowManager* manager_;
7171
};
7272

7373
WindowManager::WindowManager() : pimpl_(std::make_unique<Impl>(this)) {
74-
SetupEventMonitoring();
74+
StartEventListening();
7575
}
7676

7777
WindowManager::~WindowManager() {
78-
CleanupEventMonitoring();
79-
}
80-
81-
void WindowManager::SetupEventMonitoring() {
82-
pimpl_->SetupEventMonitoring();
83-
}
84-
85-
void WindowManager::CleanupEventMonitoring() {
86-
pimpl_->CleanupEventMonitoring();
87-
}
88-
89-
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
90-
Emit(event);
78+
StopEventListening();
9179
}
9280

9381
std::shared_ptr<Window> WindowManager::Get(WindowId id) {
@@ -153,4 +141,16 @@ void WindowManager::InvokeWillHideHook(WindowId id) {
153141
// Empty implementation
154142
}
155143

144+
void WindowManager::StartEventListening() {
145+
pimpl_->StartEventListening();
146+
}
147+
148+
void WindowManager::StopEventListening() {
149+
pimpl_->StopEventListening();
150+
}
151+
152+
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
153+
Emit(event);
154+
}
155+
156156
} // namespace nativeapi

src/platform/ios/window_manager_ios.mm

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
};
1313

1414
WindowManager::WindowManager() : pimpl_(std::make_unique<Impl>(this)) {
15-
SetupEventMonitoring();
15+
StartEventListening();
1616
}
1717

1818
WindowManager::~WindowManager() {
19-
CleanupEventMonitoring();
19+
StopEventListening();
2020
}
2121

2222
std::shared_ptr<Window> WindowManager::Create(const WindowOptions& options) {
@@ -66,18 +66,6 @@
6666
return true;
6767
}
6868

69-
void WindowManager::SetupEventMonitoring() {
70-
// iOS manages window events through UIKit
71-
}
72-
73-
void WindowManager::CleanupEventMonitoring() {
74-
// No cleanup needed
75-
}
76-
77-
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
78-
Emit(event);
79-
}
80-
8169
void WindowManager::SetWillShowHook(std::optional<WindowWillShowHook> hook) {
8270
// Empty implementation
8371
}
@@ -94,4 +82,16 @@
9482
// Empty implementation
9583
}
9684

85+
void WindowManager::StartEventListening() {
86+
// iOS manages window events through UIKit
87+
}
88+
89+
void WindowManager::StopEventListening() {
90+
// No cleanup needed
91+
}
92+
93+
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
94+
Emit(event);
95+
}
96+
9797
} // namespace nativeapi

src/platform/linux/window_manager_linux.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class WindowManager::Impl {
185185
Impl(WindowManager* manager) : manager_(manager) {}
186186
~Impl() {}
187187

188-
void SetupEventMonitoring() {
188+
void StartEventListening() {
189189
// Install global swizzling for show/hide interception
190190
InstallGlobalSwizzling();
191191

@@ -201,7 +201,7 @@ class WindowManager::Impl {
201201
}
202202
}
203203

204-
void CleanupEventMonitoring() {
204+
void StopEventListening() {
205205
// Clear hooked widgets set
206206
std::lock_guard<std::mutex> lock(g_hook_mutex);
207207
g_hooked_widgets.clear();
@@ -236,23 +236,11 @@ WindowManager::WindowManager() : pimpl_(std::make_unique<Impl>(this)) {
236236
// This is acceptable for headless environments
237237
}
238238

239-
SetupEventMonitoring();
239+
StartEventListening();
240240
}
241241

242242
WindowManager::~WindowManager() {
243-
CleanupEventMonitoring();
244-
}
245-
246-
void WindowManager::SetupEventMonitoring() {
247-
pimpl_->SetupEventMonitoring();
248-
}
249-
250-
void WindowManager::CleanupEventMonitoring() {
251-
pimpl_->CleanupEventMonitoring();
252-
}
253-
254-
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
255-
Emit(event);
243+
StopEventListening();
256244
}
257245

258246
std::shared_ptr<Window> WindowManager::Get(WindowId id) {
@@ -465,4 +453,16 @@ void WindowManager::InvokeWillHideHook(WindowId id) {
465453
}
466454
}
467455

456+
void WindowManager::StartEventListening() {
457+
pimpl_->StartEventListening();
458+
}
459+
460+
void WindowManager::StopEventListening() {
461+
pimpl_->StopEventListening();
462+
}
463+
464+
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
465+
Emit(event);
466+
}
467+
468468
} // namespace nativeapi

src/platform/macos/window_manager_macos.mm

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
public:
1919
Impl(WindowManager* manager);
2020
~Impl();
21-
void SetupEventMonitoring();
22-
void CleanupEventMonitoring();
21+
void StartEventListening();
22+
void StopEventListening();
2323
void OnWindowEvent(NSWindow* window, const std::string& event_type);
2424

2525
private:
@@ -160,10 +160,10 @@ - (void)windowWillClose:(NSNotification*)notification {
160160
WindowManager::Impl::Impl(WindowManager* manager) : manager_(manager), delegate_(nullptr) {}
161161

162162
WindowManager::Impl::~Impl() {
163-
CleanupEventMonitoring();
163+
StopEventListening();
164164
}
165165

166-
void WindowManager::Impl::SetupEventMonitoring() {
166+
void WindowManager::Impl::StartEventListening() {
167167
if (!delegate_) {
168168
delegate_ = [[NativeAPIWindowManagerDelegate alloc] initWithImpl:this];
169169

@@ -199,7 +199,7 @@ - (void)windowWillClose:(NSNotification*)notification {
199199
}
200200
}
201201

202-
void WindowManager::Impl::CleanupEventMonitoring() {
202+
void WindowManager::Impl::StopEventListening() {
203203
if (delegate_) {
204204
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
205205
[center removeObserver:delegate_];
@@ -239,23 +239,11 @@ - (void)windowWillClose:(NSNotification*)notification {
239239
}
240240

241241
WindowManager::WindowManager() : pimpl_(std::make_unique<Impl>(this)) {
242-
SetupEventMonitoring();
242+
StartEventListening();
243243
}
244244

245245
WindowManager::~WindowManager() {
246-
CleanupEventMonitoring();
247-
}
248-
249-
void WindowManager::SetupEventMonitoring() {
250-
pimpl_->SetupEventMonitoring();
251-
}
252-
253-
void WindowManager::CleanupEventMonitoring() {
254-
pimpl_->CleanupEventMonitoring();
255-
}
256-
257-
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
258-
Emit(event); // Use Dispatch instead of DispatchSync
246+
StopEventListening();
259247
}
260248

261249
// Create a new window with the given options.
@@ -373,4 +361,16 @@ - (void)windowWillClose:(NSNotification*)notification {
373361
}
374362
}
375363

364+
void WindowManager::StartEventListening() {
365+
pimpl_->StartEventListening();
366+
}
367+
368+
void WindowManager::StopEventListening() {
369+
pimpl_->StopEventListening();
370+
}
371+
372+
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
373+
Emit(event); // Use Dispatch instead of DispatchSync
374+
}
375+
376376
} // namespace nativeapi

src/platform/ohos/window_manager_ohos.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ class WindowManager::Impl {
5454
Impl(WindowManager* manager) : manager_(manager) {}
5555
~Impl() {}
5656

57-
void SetupEventMonitoring() {
57+
void StartEventListening() {
5858
// On OpenHarmony, event monitoring is done through Ability callbacks
5959
// Window event monitoring setup
6060
}
6161

62-
void CleanupEventMonitoring() {
62+
void StopEventListening() {
6363
// Window event monitoring cleanup
6464
}
6565

@@ -68,23 +68,11 @@ class WindowManager::Impl {
6868
};
6969

7070
WindowManager::WindowManager() : pimpl_(std::make_unique<Impl>(this)) {
71-
SetupEventMonitoring();
71+
StartEventListening();
7272
}
7373

7474
WindowManager::~WindowManager() {
75-
CleanupEventMonitoring();
76-
}
77-
78-
void WindowManager::SetupEventMonitoring() {
79-
pimpl_->SetupEventMonitoring();
80-
}
81-
82-
void WindowManager::CleanupEventMonitoring() {
83-
pimpl_->CleanupEventMonitoring();
84-
}
85-
86-
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
87-
Emit(event);
75+
StopEventListening();
8876
}
8977

9078
std::shared_ptr<Window> WindowManager::Get(WindowId id) {
@@ -148,4 +136,16 @@ void WindowManager::InvokeWillHideHook(WindowId id) {
148136
// Empty implementation
149137
}
150138

139+
void WindowManager::StartEventListening() {
140+
pimpl_->StartEventListening();
141+
}
142+
143+
void WindowManager::StopEventListening() {
144+
pimpl_->StopEventListening();
145+
}
146+
147+
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
148+
Emit(event);
149+
}
150+
151151
} // namespace nativeapi

src/platform/windows/window_manager_windows.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,14 @@ class WindowManager::Impl {
296296
Impl(WindowManager* manager) : manager_(manager) {}
297297
~Impl() {}
298298

299-
void SetupEventMonitoring() {
299+
void StartEventListening() {
300300
// Windows event monitoring would typically be done through:
301301
// - SetWinEventHook for system-wide window events
302302
// - Window subclassing for specific window events
303303
// This is a placeholder implementation
304304
}
305305

306-
void CleanupEventMonitoring() {
306+
void StopEventListening() {
307307
// Clean up any event hooks or monitoring
308308
}
309309

@@ -353,27 +353,13 @@ class WindowManager::Impl {
353353
};
354354

355355
WindowManager::WindowManager() : pimpl_(std::make_unique<Impl>(this)) {
356-
SetupEventMonitoring();
356+
StartEventListening();
357357
}
358358

359359
WindowManager::~WindowManager() {
360-
CleanupEventMonitoring();
360+
StopEventListening();
361361
}
362362

363-
void WindowManager::SetupEventMonitoring() {
364-
pimpl_->SetupEventMonitoring();
365-
}
366-
367-
void WindowManager::CleanupEventMonitoring() {
368-
pimpl_->CleanupEventMonitoring();
369-
}
370-
371-
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
372-
Emit(event);
373-
}
374-
375-
// Note: Global ShowWindow hooks are installed/uninstalled when hooks are set/cleared
376-
377363
// Create a new window with the given options
378364
std::shared_ptr<Window> WindowManager::Create(const WindowOptions& options) {
379365
HINSTANCE hInstance = GetModuleHandle(nullptr);
@@ -507,4 +493,16 @@ void WindowManager::InvokeWillHideHook(WindowId id) {
507493
}
508494
}
509495

496+
void WindowManager::StartEventListening() {
497+
pimpl_->StartEventListening();
498+
}
499+
500+
void WindowManager::StopEventListening() {
501+
pimpl_->StopEventListening();
502+
}
503+
504+
void WindowManager::DispatchWindowEvent(const WindowEvent& event) {
505+
Emit(event);
506+
}
507+
510508
} // namespace nativeapi

0 commit comments

Comments
 (0)