also load keyboard layouts from Documents/Keyboard Layouts

This commit is contained in:
Jesús A. Álvarez 2018-04-28 11:49:05 +02:00
parent 097ac4e64d
commit a6e6014220
4 changed files with 23 additions and 1 deletions

View File

@ -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<NSString*> *diskImageExtensions;
@property (nonatomic, readonly) NSArray<NSBundle*> *emulatorBundles;
@property (readonly, nonatomic, getter = isSandboxed) BOOL sandboxed;

View File

@ -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

View File

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

View File

@ -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);
}