Skip to content

Commit dfd4fea

Browse files
committed
refactor: Remove static map for BroadcastCenter instances and enhance OnBroadcastReceived logging
1 parent 2cd0630 commit dfd4fea

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/broadcast_center.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ BroadcastEventHandler::BroadcastEventHandler(
2020
void BroadcastEventHandler::OnBroadcastReceived(const std::string& topic,
2121
const std::string& message) {
2222
if (onBroadcastReceivedCallback_) {
23+
std::cout << "BroadcastEventHandler::OnBroadcastReceived() " << topic << " "
24+
<< message << std::endl;
2325
onBroadcastReceivedCallback_(topic, message);
2426
}
2527
}

src/broadcast_center_macos.mm

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010

1111
namespace nativeapi {
1212

13-
// Static map to store BroadcastCenter instances
14-
static std::map<BroadcastCenter*, std::string> g_broadcast_centers;
15-
1613
void BroadcastCenter::SendBroadcast(const std::string& topic, const std::string& message) {
1714
NSDistributedNotificationCenter* center = [NSDistributedNotificationCenter defaultCenter];
1815
[center postNotificationName:[NSString stringWithUTF8String:topic.c_str()]
@@ -27,6 +24,7 @@
2724
object:nil
2825
queue:[NSOperationQueue mainQueue]
2926
usingBlock:^(NSNotification* notification) {
27+
std::string topic = [notification.name UTF8String];
3028
std::string message = [notification.userInfo[@"message"] UTF8String];
3129
receiver->OnBroadcastReceived(topic, message);
3230
}];

src/window_manager_macos.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@
4949

5050
std::shared_ptr<Window> WindowManager::GetCurrent() {
5151
NSApplication* app = [NSApplication sharedApplication];
52+
NSArray* ns_windows = [[NSApplication sharedApplication] windows];
5253
NSWindow* ns_window = [app mainWindow];
54+
if (ns_window == nil) {
55+
ns_window = [ns_windows objectAtIndex:0];
56+
}
5357
if (ns_window != nil) {
5458
return Get([ns_window windowNumber]);
5559
}

0 commit comments

Comments
 (0)