diff --git a/MacPass/MPAutotypeDoctor.m b/MacPass/MPAutotypeDoctor.m index cf1e3dbb..7da4e576 100644 --- a/MacPass/MPAutotypeDoctor.m +++ b/MacPass/MPAutotypeDoctor.m @@ -63,19 +63,41 @@ - (BOOL)hasScreenRecordingPermissions:(NSError *__autoreleasing*)error { /* macos 10.14 and lower do not require screen recording permission to get window titles */ - if (@available(macOS 10.15, *)) { + + /* + Solution is heavily inspired by Craig Hockenberry's + https://stackoverflow.com/questions/56597221/detecting-screen-recording-settings-on-macos-catalina/58985069#58985069 + */ + if(@available(macOS 10.15, *)) { CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); NSUInteger numberOfWindows = CFArrayGetCount(windowList); - NSUInteger numberOfWindowsWithName = 0; + BOOL canRecordScreen = NO; for(int idx = 0; idx < numberOfWindows; idx++) { NSDictionary *windowInfo = (NSDictionary *)CFArrayGetValueAtIndex(windowList, idx); + NSNumber *ownerPid = windowInfo[(id)kCGWindowOwnerPID]; + /* + Skip over our own windows + */ + if(ownerPid.intValue == NSProcessInfo.processInfo.processIdentifier) { + continue; + } + /* + Skip applications we aren't allowed to access anyway + */ + NSRunningApplication *ownerApp = [NSRunningApplication runningApplicationWithProcessIdentifier:ownerPid.intValue]; + if(!ownerApp) { + continue; + } NSString *windowName = windowInfo[(id)kCGWindowName]; if(windowName) { - numberOfWindowsWithName++; + if([ownerApp.executableURL.lastPathComponent isEqualToString:@"Dock"]) { + continue; + } + canRecordScreen = YES; + break; } } CFRelease(windowList); - BOOL canRecordScreen = (numberOfWindows == 0) || (numberOfWindowsWithName > 0); if(!canRecordScreen && error) { *error = [NSError errorInDomain:MPAutotypeErrorDomain withCode:MPErrorAutotypeIsMissingScreenRecordingPermissions description:NSLocalizedString(@"ERROR_NO_PERMISSION_TO_RECORD_SCREEN", "Error description for missing screen recording permissions")]; }