Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ AXUIElementRef getAXWindowById(int handle) {
NSNumber *windowNumber = info[(id)kCGWindowNumber];

auto app = [NSRunningApplication runningApplicationWithProcessIdentifier: [ownerPid intValue]];
auto path = app ? [app.bundleURL.path UTF8String] : "";
auto path = (app && app.bundleURL && app.bundleURL.path) ? [app.bundleURL.path UTF8String] : "";

if (app && path != "") {
vec.push_back(Napi::Number::New(env, [windowNumber intValue]));
Expand Down Expand Up @@ -147,7 +147,7 @@ AXUIElementRef getAXWindowById(int handle) {

auto app = [NSRunningApplication runningApplicationWithProcessIdentifier: [ownerPid intValue]];

if (![app isActive]) {
if (app && ![app isActive]) {
continue;
}

Expand All @@ -171,6 +171,9 @@ AXUIElementRef getAXWindowById(int handle) {
if (wInfo) {
NSNumber *ownerPid = wInfo[(id)kCGWindowOwnerPID];
NSRunningApplication *app = [NSRunningApplication runningApplicationWithProcessIdentifier: [ownerPid intValue]];
if (!app || !app.bundleURL || !app.bundleURL.path) {
return Napi::Object::New(env);
}

auto obj = Napi::Object::New(env);
obj.Set("processId", [ownerPid intValue]);
Expand All @@ -193,6 +196,9 @@ AXUIElementRef getAXWindowById(int handle) {

if (wInfo) {
NSString *windowName = wInfo[(id)kCGWindowOwnerName];
if (!windowName) {
return Napi::String::New(env, "");
}
return Napi::String::New(env, [windowName UTF8String]);
}

Expand Down