|
3 | 3 | #include <iostream>
|
4 | 4 | #include "nativeapi.h"
|
5 | 5 |
|
| 6 | +using nativeapi::BroadcastCenter; |
| 7 | +using nativeapi::BroadcastEventHandler; |
| 8 | +using nativeapi::Display; |
| 9 | +using nativeapi::DisplayEventHandler; |
| 10 | +using nativeapi::DisplayManager; |
6 | 11 | using nativeapi::Tray;
|
7 | 12 | using nativeapi::TrayManager;
|
8 | 13 | using nativeapi::Window;
|
@@ -36,6 +41,32 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
|
36 | 41 | NSLog(@"所有窗口: %@", NSApp.windows);
|
37 | 42 | });
|
38 | 43 |
|
| 44 | + |
| 45 | + DisplayManager displayManager = DisplayManager(); |
| 46 | + |
| 47 | + DisplayEventHandler displayEventHandler = DisplayEventHandler( |
| 48 | + [](const Display& display) { |
| 49 | + std::cout << "Display added: " << display.id << std::endl; |
| 50 | + }, |
| 51 | + [](const Display& display) { |
| 52 | + std::cout << "Display removed: " << display.id << std::endl; |
| 53 | + }); |
| 54 | + displayManager.AddListener(&displayEventHandler); |
| 55 | + |
| 56 | + std::shared_ptr<BroadcastCenter> broadcastCenter = std::make_shared<BroadcastCenter>(); |
| 57 | + |
| 58 | + BroadcastEventHandler broadcastEventHandler = |
| 59 | + BroadcastEventHandler([](const std::string& message) { |
| 60 | + std::cout << "Received broadcast: " << message << std::endl; |
| 61 | + }); |
| 62 | + |
| 63 | + broadcastCenter->RegisterReceiver("com.example.myNotification", &broadcastEventHandler); |
| 64 | + |
| 65 | + // broadcastCenter.RegisterReceiver( |
| 66 | + // BroadcastEventHandler ([&](const std::string& message) { |
| 67 | + // std::cout << "Received broadcast: " << message << std::endl; |
| 68 | + // })); |
| 69 | + |
39 | 70 | [[NSNotificationCenter defaultCenter]
|
40 | 71 | addObserverForName:NSWindowDidBecomeMainNotification
|
41 | 72 | object:nil
|
@@ -71,18 +102,17 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
|
71 | 102 | << std::endl;
|
72 | 103 | }
|
73 | 104 |
|
| 105 | + TrayManager trayManager = TrayManager(); |
74 | 106 |
|
75 |
| - TrayManager trayManager = TrayManager(); |
76 |
| - |
77 |
| - std::shared_ptr<Tray> newTrayPtr = trayManager.Create(); |
78 |
| - if (newTrayPtr != nullptr) { |
79 |
| - Tray& newTray = *newTrayPtr; |
80 |
| - newTray.SetTitle("Hello, World!"); |
81 |
| - std::cout << "Tray ID: " << newTray.id << std::endl; |
82 |
| - std::cout << "Tray Title: " << newTray.GetTitle() << std::endl; |
83 |
| - } else { |
84 |
| - std::cerr << "Failed to create tray." << std::endl; |
85 |
| - } |
| 107 | + std::shared_ptr<Tray> newTrayPtr = trayManager.Create(); |
| 108 | + if (newTrayPtr != nullptr) { |
| 109 | + Tray& newTray = *newTrayPtr; |
| 110 | + newTray.SetTitle("Hello, World!"); |
| 111 | + std::cout << "Tray ID: " << newTray.id << std::endl; |
| 112 | + std::cout << "Tray Title: " << newTray.GetTitle() << std::endl; |
| 113 | + } else { |
| 114 | + std::cerr << "Failed to create tray." << std::endl; |
| 115 | + } |
86 | 116 | }];
|
87 | 117 | }
|
88 | 118 |
|
|
0 commit comments