@@ -45,27 +45,17 @@ AXUIElementRef getAXWindow(int pid, int handle) {
4545 CGWindowListOption listOptions = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements ;
4646 CFArrayRef windowList = CGWindowListCopyWindowInfo (listOptions, kCGNullWindowID );
4747
48- std::vector<Napi::Object > vec;
48+ std::vector<Napi::Number > vec;
4949
5050 for (NSDictionary *info in (NSArray *)windowList) {
51- auto obj = Napi::Object::New (env);
52-
5351 NSNumber *ownerPid = info[(id )kCGWindowOwnerPID ];
5452 NSNumber *windowNumber = info[(id )kCGWindowNumber ];
5553 auto app = [NSRunningApplication runningApplicationWithProcessIdentifier: [ownerPid intValue ]];
5654
5755 auto path = app ? [app.bundleURL.path UTF8String ] : " " ;
5856
59- obj.Set (" id" , [windowNumber intValue ]);
60- obj.Set (" processId" , [ownerPid intValue ]);
61- obj.Set (" path" , path);
62-
63- if (m.find ([windowNumber intValue ]) == m.end ()) {
64- m[[windowNumber intValue ]] = getAXWindow ([ownerPid intValue ], [windowNumber intValue ]);
65- }
66-
6757 if (path != " " ) {
68- vec.push_back (obj );
58+ vec.push_back (Napi::Number::New (env, [windowNumber intValue ]) );
6959 }
7060 }
7161
@@ -78,7 +68,7 @@ AXUIElementRef getAXWindow(int pid, int handle) {
7868 return arr;
7969}
8070
81- Napi::Object getActiveWindow (const Napi::CallbackInfo &info) {
71+ Napi::Number getActiveWindow (const Napi::CallbackInfo &info) {
8272 Napi::Env env{info.Env ()};
8373
8474 CGWindowListOption listOptions = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements ;
@@ -92,20 +82,10 @@ AXUIElementRef getAXWindow(int pid, int handle) {
9282
9383 if ([ownerPid intValue ] != app.processIdentifier ) continue ;
9484
95- auto obj = Napi::Object::New (env);
96-
97- obj.Set (" id" , [windowNumber intValue ]);
98- obj.Set (" processId" , [ownerPid intValue ]);
99- obj.Set (" path" , [app.bundleURL.path UTF8String ]);
100-
101- if (m.find ([windowNumber intValue ]) == m.end ()) {
102- m[[windowNumber intValue ]] = getAXWindow ([ownerPid intValue ], [windowNumber intValue ]);
103- }
104-
105- return obj;
85+ return Napi::Number::New (env, [windowNumber intValue ]);
10686 }
10787
108- return Napi::Object ::New (env);
88+ return Napi::Number ::New (env, 0 );
10989}
11090
11191Napi::Object getWindowInfo (const Napi::CallbackInfo &info) {
@@ -182,10 +162,14 @@ AXUIElementRef getAXWindow(int pid, int handle) {
182162Napi::Boolean bringWindowToTop (const Napi::CallbackInfo &info) {
183163 Napi::Env env{info.Env ()};
184164
185- auto pid = info[0 ].As <Napi::Number>().Int32Value ();
165+ auto handle = info[0 ].As <Napi::Number>().Int32Value ();
166+ auto pid = info[1 ].As <Napi::Number>().Int32Value ();
167+
186168 auto app = AXUIElementCreateApplication (pid);
169+ auto win = m[handle];
187170
188171 AXUIElementSetAttributeValue (app, kAXFrontmostAttribute , kCFBooleanTrue );
172+ AXUIElementSetAttributeValue (win, kAXMainAttribute , kCFBooleanTrue );
189173
190174 return Napi::Boolean::New (env, true );
191175}
0 commit comments