Skip to content

Commit

Permalink
SEBMAC-489 Force Click lookup works on Ventura 13.3: Now killing two …
Browse files Browse the repository at this point in the history
…processes responsible for lookup in processWatcher..
  • Loading branch information
danschlet committed Mar 29, 2023
1 parent 664b011 commit ec6cb14
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
5 changes: 3 additions & 2 deletions Classes/Global/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,9 @@ static NSString __unused *ARDAgent = @"ARDAgent";
static NSString __unused *ARDAgentBundleID = @"com.apple.RemoteDesktopAgent";
static NSString __unused *fontRegistryUIAgent = @"FontRegistryUIAgent";
static NSString __unused *fontRegistryUIAgentBundleID = @"com.apple.FontRegistryUIAgent";
static NSString __unused *lookupQuicklookHelperBundleIDOld = @"com.apple.quicklook.ui.helper";
static NSString __unused *lookupQuicklookHelperBundleID = @"com.apple.quicklook.QuickLookUIService";
static NSString __unused *lookupQuicklookHelper = @"QuickLookUIHelper";
static NSString __unused *lookupQuicklookHelperBundleID = @"com.apple.quicklook.ui.helper";
static NSString __unused *lookupViewService = @"LookupViewService";
static NSString __unused *lookupViewServiceBundleID = @"com.apple.LookupViewService";
static NSString __unused *XcodeBundleID = @"com.apple.dt.Xcode";
static NSString __unused *SiriService = @"SiriNCService";
Expand Down
54 changes: 36 additions & 18 deletions Classes/SEBController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2852,16 +2852,29 @@ -(void)processWatcher
}
// Check for running screen capture process
if (!allowScreenCapture || _isAACEnabled) {
processNameFilter = [NSPredicate predicateWithFormat:@"name ==[cd] %@ ", screenCaptureAgent];
filteredProcesses = [allRunningProcesses filteredArrayUsingPredicate:processNameFilter];

if (filteredProcesses.count > 0) {
NSDictionary *screenCaptureAgentProcessDetails = filteredProcesses[0];
NSNumber *PID = [screenCaptureAgentProcessDetails objectForKey:@"PID"];
NSInteger success = [self killProcessWithPID:PID.intValue];
DDLogDebug(@"Terminating %@ was %@successfull (code: %ld)", screenCaptureAgentProcessDetails, success == 0 ? @"" : @"not ", (long)success);
NSDictionary *processDetails = nil;
NSInteger success = [self runningProcessCheckForName:screenCaptureAgent inRunningProcesses:&allRunningProcesses processDetails:&processDetails];
if (processDetails) {
DDLogDebug(@"Terminating %@ was %@successfull (code: %ld)", processDetails, success == 0 ? @"" : @"not ", (long)success);
}
}

if (@available(macOS 13.0, *)) {
if (!allowDictionaryLookup) {
NSDictionary *processDetails = nil;
NSInteger success = [self runningProcessCheckForName:lookupQuicklookHelper inRunningProcesses:&allRunningProcesses processDetails:&processDetails];
if (processDetails) {
DDLogDebug(@"Lookup is not allowed in settings: Terminating %@ was %@successfull (code: %ld)", processDetails, success == 0 ? @"" : @"not ", (long)success);
processDetails = nil;
}

success = [self runningProcessCheckForName:lookupViewService inRunningProcesses:&allRunningProcesses processDetails:&processDetails];
if (processDetails) {
DDLogDebug(@"Lookup is not allowed in settings: Terminating %@ was %@successfull (code: %ld)", processDetails, success == 0 ? @"" : @"not ", (long)success);
}
}
}

// Check for prohibited BSD processes
NSArray *prohibitedProcesses = [ProcessManager sharedProcessManager].prohibitedBSDProcesses.copy;
for (NSString *executableName in prohibitedProcesses) {
Expand All @@ -2880,6 +2893,21 @@ -(void)processWatcher
checkingRunningProcesses = NO;
}

- (NSInteger)runningProcessCheckForName:(NSString *)name inRunningProcesses:(NSArray **)allRunningProcesses processDetails:(NSDictionary **)processDetails
{
NSPredicate *processNameFilter = [NSPredicate predicateWithFormat:@"name ==[cd] %@ ", name];
NSArray *filteredProcesses = [*allRunningProcesses filteredArrayUsingPredicate:processNameFilter];

NSInteger success = -1;
if (filteredProcesses.count > 0) {
*processDetails = filteredProcesses[0];
NSNumber *PID = [*processDetails objectForKey:@"PID"];
success = [self killProcessWithPID:PID.intValue];
}
return success;
}


- (void)windowWatcher
{
// Check if the font download dialog (if displayed) was successfully closed
Expand Down Expand Up @@ -2956,16 +2984,6 @@ - (void)windowWatcher
CGSGetWindowWorkspace(connection, windowID, &workspace);
DDLogVerbose(@"Window %@ is on space %d", windowName, workspace);
#endif
if (@available(macOS 13.0, *)) {
if (!allowDictionaryLookup && ([appWithPanelBundleID isEqualToString:lookupQuicklookHelperBundleID] ||
[appWithPanelBundleID isEqualToString:lookupViewServiceBundleID] ||
[appWithPanelBundleID isEqualToString:lookupQuicklookHelperBundleIDOld])) {
DDLogDebug(@"Terminating process %@ as lookup is not allowed in settings.", appWithPanelBundleID);
[self killProcessWithPID:windowOwnerPID];
continue;
}
}

if (!_allowSwitchToApplications && ![_preferencesController preferencesAreOpen]) {
if (appWithPanelBundleID && ![appWithPanelBundleID hasPrefix:@"com.apple."]) {
// Application hasn't a com.apple. bundle ID prefix
Expand Down

0 comments on commit ec6cb14

Please sign in to comment.