From 53cb92f4ef768d3c86d71352db6c49398d09648c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Sat, 10 Feb 2024 14:09:02 +0100 Subject: [PATCH] find keyboard layouts from AppDelegate --- Mini vMac/AppDelegate.h | 1 + Mini vMac/AppDelegate.m | 10 ++++++++++ Mini vMac/SettingsViewController.m | 7 +------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Mini vMac/AppDelegate.h b/Mini vMac/AppDelegate.h index 6b23356..7da8f03 100644 --- a/Mini vMac/AppDelegate.h +++ b/Mini vMac/AppDelegate.h @@ -22,6 +22,7 @@ extern NSString *DocumentsChangedNotification; @property (nonatomic, readonly) NSString *emulatorBundlesPath; @property (readonly, nonatomic, getter = isSandboxed) BOOL sandboxed; @property (readonly, nonatomic) id sharedEmulator; +@property (readonly, nonatomic) NSArray *keyboardLayoutPaths; @property (class, readonly, strong) AppDelegate *sharedInstance NS_SWIFT_NAME(shared); @property (class, readonly, strong) id sharedEmulator NS_SWIFT_NAME(emulator); diff --git a/Mini vMac/AppDelegate.m b/Mini vMac/AppDelegate.m index 317d054..d4bc884 100644 --- a/Mini vMac/AppDelegate.m +++ b/Mini vMac/AppDelegate.m @@ -257,6 +257,16 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; return userKeyboardLayoutsPath; } +- (NSArray *)keyboardLayoutPaths { + NSArray *keyboardLayouts = [[NSBundle mainBundle] pathsForResourcesOfType:@"nfkeyboardlayout" inDirectory:@"Keyboard Layouts"]; + NSString *userKeyboardLayoutsPath = [AppDelegate sharedInstance].userKeyboardLayoutsPath; + NSArray *userKeyboardLayouts = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:userKeyboardLayoutsPath error:nil] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"pathExtension.lowercaseString = %@", @"nfkeyboardlayout"]]; + if (userKeyboardLayouts.count > 0) { + keyboardLayouts = [keyboardLayouts arrayByAddingObjectsFromArray:userKeyboardLayouts]; + } + return keyboardLayouts; +} + - (BOOL)importFileToDocuments:(NSURL *)url copy:(BOOL)copy { if (url.fileURL) { // opening file diff --git a/Mini vMac/SettingsViewController.m b/Mini vMac/SettingsViewController.m index ffd65a6..fbcaa3f 100644 --- a/Mini vMac/SettingsViewController.m +++ b/Mini vMac/SettingsViewController.m @@ -37,12 +37,7 @@ typedef enum : NSInteger { - (void)viewDidLoad { [super viewDidLoad]; - keyboardLayouts = [[NSBundle mainBundle] pathsForResourcesOfType:@"nfkeyboardlayout" inDirectory:@"Keyboard Layouts"]; - NSString *userKeyboardLayoutsPath = [AppDelegate sharedInstance].userKeyboardLayoutsPath; - NSArray *userKeyboardLayouts = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:userKeyboardLayoutsPath error:nil] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"pathExtension.lowercaseString = %@", @"nfkeyboardlayout"]]; - if (userKeyboardLayouts.count > 0) { - keyboardLayouts = [keyboardLayouts arrayByAddingObjectsFromArray:userKeyboardLayouts]; - } + keyboardLayouts = [AppDelegate sharedInstance].keyboardLayoutPaths; [self loadEmulatorBundles]; [self loadCredits]; }