fix(info): fix segmentation fault on macOS
This commit is contained in:
parent
8c2e02030a
commit
fc69b7a79f
|
@ -23,54 +23,56 @@
|
|||
|
||||
int32_t info_get_title(char *buffer, int32_t buffer_size)
|
||||
{
|
||||
CFArrayRef windows = CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements | kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
|
||||
int32_t result = 0;
|
||||
@autoreleasepool {
|
||||
CFArrayRef windows = CGWindowListCopyWindowInfo(kCGWindowListExcludeDesktopElements | kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
|
||||
int32_t result = 0;
|
||||
|
||||
if (windows) {
|
||||
for (NSDictionary *window in (NSArray *)windows) {
|
||||
NSNumber *ownerPid = window[(id) kCGWindowOwnerPID];
|
||||
if (windows) {
|
||||
for (NSDictionary *window in (NSArray *)windows) {
|
||||
NSNumber *ownerPid = window[(id) kCGWindowOwnerPID];
|
||||
|
||||
NSRunningApplication *currentApp = [NSRunningApplication runningApplicationWithProcessIdentifier: [ownerPid intValue]];
|
||||
NSRunningApplication *currentApp = [NSRunningApplication runningApplicationWithProcessIdentifier: [ownerPid intValue]];
|
||||
|
||||
if ([currentApp isActive]) {
|
||||
NSString *name = window[(id) kCGWindowName];
|
||||
if (name.length > 0) {
|
||||
const char * title = [name UTF8String];
|
||||
snprintf(buffer, buffer_size, "%s", title);
|
||||
result = 1;
|
||||
if ([currentApp isActive]) {
|
||||
NSString *name = window[(id) kCGWindowName];
|
||||
if (name.length > 0) {
|
||||
const char * title = [name UTF8String];
|
||||
snprintf(buffer, buffer_size, "%s", title);
|
||||
result = 1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(windows);
|
||||
CFRelease(windows);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t info_get_exec(char *buffer, int32_t buffer_size)
|
||||
{
|
||||
NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||
NSString *bundlePath = [frontApp bundleURL].path;
|
||||
const char * path = [bundlePath UTF8String];
|
||||
@autoreleasepool {
|
||||
NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||
NSString *bundlePath = [frontApp bundleURL].path;
|
||||
const char * path = [bundlePath UTF8String];
|
||||
|
||||
snprintf(buffer, buffer_size, "%s", path);
|
||||
|
||||
[bundlePath release];
|
||||
snprintf(buffer, buffer_size, "%s", path);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t info_get_class(char *buffer, int32_t buffer_size)
|
||||
{
|
||||
NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||
NSString *bundleId = frontApp.bundleIdentifier;
|
||||
const char * bundle = [bundleId UTF8String];
|
||||
@autoreleasepool {
|
||||
NSRunningApplication *frontApp = [[NSWorkspace sharedWorkspace] frontmostApplication];
|
||||
NSString *bundleId = frontApp.bundleIdentifier;
|
||||
const char * bundle = [bundleId UTF8String];
|
||||
|
||||
snprintf(buffer, buffer_size, "%s", bundle);
|
||||
|
||||
[bundleId release];
|
||||
snprintf(buffer, buffer_size, "%s", bundle);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
Loading…
Reference in New Issue
Block a user