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]; }