diff --git a/Mini vMac/AppDelegate.h b/Mini vMac/AppDelegate.h index bad7f21..e73438c 100644 --- a/Mini vMac/AppDelegate.h +++ b/Mini vMac/AppDelegate.h @@ -16,6 +16,7 @@ extern NSString *DocumentsChangedNotification; @property (strong, nonatomic) UIWindow *window; @property (nonatomic, readonly) NSString *documentsPath; +@property (nonatomic, readonly) NSString *userKeyboardLayoutsPath; @property (nonatomic, readonly) NSArray *diskImageExtensions; @property (nonatomic, readonly) NSArray *emulatorBundles; @property (readonly, nonatomic, getter = isSandboxed) BOOL sandboxed; diff --git a/Mini vMac/AppDelegate.m b/Mini vMac/AppDelegate.m index 112cca8..c7cfc3b 100644 --- a/Mini vMac/AppDelegate.m +++ b/Mini vMac/AppDelegate.m @@ -45,6 +45,10 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; [application btcMouseSetRawMode:YES]; [application btcMouseSetDelegate:self]; } + + // populate documents directory so it shows up in Files + [[NSFileManager defaultManager] createDirectoryAtPath:self.userKeyboardLayoutsPath withIntermediateDirectories:YES attributes:nil error:nil]; + return YES; } @@ -280,6 +284,15 @@ NSString *DocumentsChangedNotification = @"documentsChanged"; return documentsPath; } +- (NSString *)userKeyboardLayoutsPath { + static dispatch_once_t onceToken; + static NSString *userKeyboardLayoutsPath; + dispatch_once(&onceToken, ^{ + userKeyboardLayoutsPath = [self.documentsPath stringByAppendingPathComponent:@"Keyboard Layouts"]; + }); + return userKeyboardLayoutsPath; +} + - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if (url.fileURL) { // opening file diff --git a/Mini vMac/SettingsViewController.m b/Mini vMac/SettingsViewController.m index 8edb8e7..b65087f 100644 --- a/Mini vMac/SettingsViewController.m +++ b/Mini vMac/SettingsViewController.m @@ -37,6 +37,11 @@ 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]; + } [self loadEmulatorBundles]; [self loadCredits]; } diff --git a/Mini vMac/ViewController.m b/Mini vMac/ViewController.m index 230a384..92860bc 100644 --- a/Mini vMac/ViewController.m +++ b/Mini vMac/ViewController.m @@ -220,7 +220,10 @@ - (KBKeyboardLayout*)keyboardLayout { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSString *layoutName = [defaults stringForKey:@"keyboardLayout"]; - NSString *layoutPath = [[NSBundle mainBundle] pathForResource:layoutName ofType:nil inDirectory:@"Keyboard Layouts"]; + NSString *layoutPath = [[[AppDelegate sharedInstance] userKeyboardLayoutsPath] stringByAppendingPathComponent:layoutName]; + if (![[NSFileManager defaultManager] fileExistsAtPath:layoutPath]) { + layoutPath = [[NSBundle mainBundle] pathForResource:layoutName ofType:nil inDirectory:@"Keyboard Layouts"]; + } if (layoutPath == nil) { NSLog(@"Layout not found: %@", layoutPath); }