@@ -27,16 +27,12 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
2727 [self .window makeMainWindow ];
2828 [NSApp activateIgnoringOtherApps: YES ];
2929
30- // dispatch_async(dispatch_get_main_queue(), ^{
31-
32- // });
33-
3430 // 延迟检查主窗口
35- dispatch_async (dispatch_get_main_queue (), ^{
36- NSLog (@" 主窗口: %@ " , NSApp .mainWindow);
37- NSLog (@" 关键窗口: %@ " , NSApp .keyWindow);
38- NSLog (@" 所有窗口: %@ " , NSApp .windows);
39- });
31+ dispatch_async (dispatch_get_main_queue (), ^{
32+ NSLog (@" 主窗口: %@ " , NSApp .mainWindow);
33+ NSLog (@" 关键窗口: %@ " , NSApp .keyWindow);
34+ NSLog (@" 所有窗口: %@ " , NSApp .windows);
35+ });
4036
4137 [[NSNotificationCenter defaultCenter ]
4238 addObserverForName: NSWindowDidBecomeMainNotification
@@ -50,25 +46,28 @@ - (void)applicationDidFinishLaunching:(NSNotification*)notification {
5046 WindowManager windowManager = WindowManager ();
5147
5248 // Get current window information
53- Window currentWindow = windowManager.GetCurrent ();
54- std::cout << " Current Window Information:" << std::endl;
55- std::cout << " ID: " << currentWindow.id << std::endl;
49+ std::shared_ptr<Window> currentWindowPtr = windowManager.GetCurrent ();
50+ if (currentWindowPtr != nullptr ) {
51+ Window& currentWindow = *currentWindowPtr;
52+ std::cout << " Current Window Information:" << std::endl;
53+ std::cout << " ID: " << currentWindow.id << std::endl;
5654
57- // Get window size
58- auto size = currentWindow.GetSize ();
59- std::cout << " Window Size: " << size.width << " x" << size.height << std::endl;
55+ // Get window size
56+ auto size = currentWindow.GetSize ();
57+ std::cout << " Window Size: " << size.width << " x" << size.height << std::endl;
58+ }
6059
61- // Get all windows
62- std::vector<Window> windowList = windowManager.GetAll ();
63- std::cout << " \n All Windows Information:" << std::endl;
64- for (size_t i = 0 ; i < windowList.size (); i++) {
65- const Window& window = windowList[i];
66- std::cout << " Window " << (i + 1 ) << " :" << std::endl;
67- std::cout << " ID: " << window.id << std::endl;
68- auto windowSize = window.GetSize ();
69- std::cout << " Size: " << windowSize.width << " x" << windowSize.height
70- << std::endl;
71- }
60+ // Get all windows
61+ std::vector<std::shared_ptr< Window>> windowList = ( windowManager.GetAll () );
62+ std::cout << " \n All Windows Information:" << std::endl;
63+ for (size_t i = 0 ; i < windowList.size (); i++) {
64+ const Window& window = * windowList[i];
65+ std::cout << " Window " << (i + 1 ) << " :" << std::endl;
66+ std::cout << " ID: " << window.id << std::endl;
67+ auto windowSize = window.GetSize ();
68+ std::cout << " Size: " << windowSize.width << " x" << windowSize.height
69+ << std::endl;
70+ }
7271 }];
7372}
7473
0 commit comments