Skip to content

Commit

Permalink
refactor(mac): pass kmx data blob to keyman core instead of file path
Browse files Browse the repository at this point in the history
Fixes: #12499
  • Loading branch information
sgschantz committed Dec 2, 2024
1 parent f747984 commit 42ba0a4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/CoreWrapper/CoreWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,22 @@ -(void) dealloc{

-(void)loadKeyboardUsingCore:(NSString*) path {
km_core_path_name keyboardPath = [path UTF8String];
km_core_status result = km_core_keyboard_load(keyboardPath, &_coreKeyboard);
NSError* dataError = nil;
NSData *data = [NSData dataWithContentsOfFile:path options:0 error:&dataError];

if (result != KM_CORE_STATUS_OK) {
NSString *message = [NSString stringWithFormat:@"Unexpected Keyman Core result: %u", result];
[NSException raise:@"LoadKeyboardException" format:@"%@", message];
if (dataError != nil) {
os_log_error([KMELogs coreLog], "loadKeyboardUsingCore, path: %{public}@\n dataError: %{public}@", path, dataError);
} else {
NSUInteger dataLength = data.length;
os_log_info([KMELogs coreLog], "loadKeyboardUsingCore, path: %{public}@\n dataLength: %lu", path, dataLength);

km_core_status result = km_core_keyboard_load_from_blob(keyboardPath,
data.bytes, dataLength, &_coreKeyboard);
if (result != KM_CORE_STATUS_OK) {
NSString *message = [NSString stringWithFormat:@"Unexpected Keyman Core result: %u", result];
os_log_error([KMELogs coreLog], "loadKeyboardUsingCore, path: %{public}@\n core result: %{public}@", path, message);
[NSException raise:@"LoadKeyboardException" format:@"%@", message];
}
}
}

Expand All @@ -126,7 +137,7 @@ -(void)readKeyboardAttributesUsingCore {
if (result==KM_CORE_STATUS_OK) {
_keyboardVersion = [self.coreHelper createNSStringFromUnicharString:keyboardAttributes->version_string];
_keyboardId = [self.coreHelper createNSStringFromUnicharString:keyboardAttributes->id];
os_log_debug([KMELogs coreLog], "readKeyboardAttributesUsingCore, keyboardVersion: %{public}@\n, keyboardId: %{public}@\n", _keyboardVersion, _keyboardId);
os_log_debug([KMELogs coreLog], "readKeyboardAttributesUsingCore, keyboardVersion: %{public}@, keyboardId: %{public}@\n", _keyboardVersion, _keyboardId);
} else {
os_log_error([KMELogs coreLog], "km_core_keyboard_get_attrs() failed with result = %u\n", result);
}
Expand Down

0 comments on commit 42ba0a4

Please sign in to comment.