From 3b547fa5b8abffc505a329c4a3d66443d4103220 Mon Sep 17 00:00:00 2001 From: "Daniel R. Schneider" Date: Wed, 15 May 2024 15:51:00 +0200 Subject: [PATCH] SEBMAC-587 Now detecting and denying to run when custom Cocoa Text System key bindings are set. --- Classes/Global/Constants.h | 1 + Classes/SEBController.m | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Classes/Global/Constants.h b/Classes/Global/Constants.h index e15c920a1..b545f0501 100644 --- a/Classes/Global/Constants.h +++ b/Classes/Global/Constants.h @@ -554,6 +554,7 @@ static NSString __unused *BTouchBarRestartAgent = @"BTTRelaunch"; static NSString __unused *WebKitNetworkingProcessBundleID = @"com.apple.WebKit.Networking"; static NSString __unused *UniversalControlBundleID = @"com.apple.universalcontrol"; static NSString __unused *KeyboardViewerBundleID = @"com.apple.inputmethod.AssistiveControl"; +static NSString __unused *KeyBindingsPath = @"/KeyBindings/DefaultKeyBinding.dict"; static NSString __unused *cachedTouchBarGlobalSettingsKey = @"cachedTouchBarGlobalSettingsKey"; static NSString __unused *cachedTouchBarFnDictionarySettingsKey = @"cachedTouchBarFnDictionarySettingsKey"; static NSString __unused *systemPreferencesBundleID = @"com.apple.systempreferences"; diff --git a/Classes/SEBController.m b/Classes/SEBController.m index ad04a32bb..4c0c68040 100644 --- a/Classes/SEBController.m +++ b/Classes/SEBController.m @@ -847,6 +847,30 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification DDLogDebug(@"%s", __FUNCTION__); NSApp.presentationOptions |= (NSApplicationPresentationDisableForceQuit | NSApplicationPresentationHideDock); + NSArray *libraryDirs = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, + NSLocalDomainMask | NSUserDomainMask, + YES); + NSFileManager *fileManager= [NSFileManager defaultManager]; + + for (NSString *libraryDir in libraryDirs) { + BOOL isDir; + NSString *keyBindingsFilePath = [libraryDir stringByAppendingPathComponent:KeyBindingsPath]; + if ([fileManager fileExistsAtPath:keyBindingsFilePath isDirectory:&isDir]) { + DDLogError(@"Cocoa Text System key bindings file detected: at path %@", keyBindingsFilePath); + NSAlert *modalAlert = [self newAlert]; + [modalAlert setMessageText:NSLocalizedString(@"Custom Key Binding Detected", @"")]; + [modalAlert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"SEB doesn't allow to use custom key bindings. Please delete or rename the file at the path %@ and restart SEB", @""), keyBindingsFilePath]]; + [modalAlert addButtonWithTitle:NSLocalizedString(@"Quit", @"")]; + [modalAlert setAlertStyle:NSAlertStyleCritical]; + void (^keyBindingDetectedHandler)(NSModalResponse) = ^void (NSModalResponse answer) { + [self removeAlertWindow:modalAlert.window]; + [self quitSEBOrSession]; + }; + [self runModalAlert:modalAlert conditionallyForWindow:self.browserController.mainBrowserWindow completionHandler:(void (^)(NSModalResponse answer))keyBindingDetectedHandler]; + return; + } + } + // Check if the font download alert was triggered from a web page // and SEB didn't had Accessibility permissions // and therefore was terminated to prevent a modal lock