find keyboard layouts from AppDelegate

This commit is contained in:
Jesús A. Álvarez 2024-02-10 14:09:02 +01:00
parent 22256824d2
commit 53cb92f4ef
3 changed files with 12 additions and 6 deletions

View File

@ -22,6 +22,7 @@ extern NSString *DocumentsChangedNotification;
@property (nonatomic, readonly) NSString *emulatorBundlesPath;
@property (readonly, nonatomic, getter = isSandboxed) BOOL sandboxed;
@property (readonly, nonatomic) id<Emulator> sharedEmulator;
@property (readonly, nonatomic) NSArray<NSString*> *keyboardLayoutPaths;
@property (class, readonly, strong) AppDelegate *sharedInstance NS_SWIFT_NAME(shared);
@property (class, readonly, strong) id<Emulator> sharedEmulator NS_SWIFT_NAME(emulator);

View File

@ -257,6 +257,16 @@ NSString *DocumentsChangedNotification = @"documentsChanged";
return userKeyboardLayoutsPath;
}
- (NSArray<NSString *> *)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

View File

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