Skip to content

Commit 5009db4

Browse files
committed
fix: bringToTop not working on macOS in some cases
Closes #25
1 parent 57821c3 commit 5009db4

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

example.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ console.timeEnd("setBounds");
2121
console.log("[info]: Visible Windows List");
2222
windowManager.getWindows().forEach(window => {
2323
console.log('Title: '+window.getTitle(), '\n', 'Path: '+window.path);
24+
window.bringToTop();
2425
});

lib/macos.mm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,14 @@ AXUIElementRef getAXWindow(int pid, int handle) {
162162
Napi::Boolean bringWindowToTop(const Napi::CallbackInfo &info) {
163163
Napi::Env env{info.Env()};
164164

165-
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+
166168
auto app = AXUIElementCreateApplication(pid);
169+
auto win = m[handle];
167170

168171
AXUIElementSetAttributeValue(app, kAXFrontmostAttribute, kCFBooleanTrue);
172+
AXUIElementSetAttributeValue(win, kAXMainAttribute, kCFBooleanTrue);
169173

170174
return Napi::Boolean::New(env, true);
171175
}

src/classes/window.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ export class Window {
128128

129129
bringToTop() {
130130
if (!addon) return;
131-
addon.bringWindowToTop(platform() === "darwin" ? this.processId : this.id);
131+
if (process.platform === 'darwin') {
132+
addon.bringWindowToTop(this.id, this.processId);
133+
} else {
134+
addon.bringWindowToTop(this.id);
135+
}
132136
}
133137

134138
redraw() {

0 commit comments

Comments
 (0)