mirror of
https://github.com/keymanapp/keyman.git
synced 2026-09-23 16:17:40 +00:00
added builders for package and keyboard value objects
This commit is contained in:
parent
d2ed35ac20
commit
4e5213aa64
5 changed files with 176 additions and 78 deletions
|
|
@ -707,6 +707,31 @@ CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef
|
|||
return packageInfo;
|
||||
}
|
||||
|
||||
- (KMPackageInfo *) createKeyboardInfoFromJsonKeyboard:(NSDictionary *) keyboard {
|
||||
|
||||
KMKeyboardInfoBuilder *builder = [[KMKeyboardInfoBuilder alloc] init];
|
||||
|
||||
NSArray *languages = keyboard[@"languages"];
|
||||
NSMutableArray *languageInfoArray = [NSMutableArray arrayWithCapacity:0];
|
||||
|
||||
for (NSDictionary *language in languages) {
|
||||
KMLanguageInfo *languageInfo = [[KMLanguageInfo alloc] initWithName:language[@"name"]
|
||||
identifier:language[@"id"]];
|
||||
|
||||
[languageInfoArray addObject:languageInfo];
|
||||
}
|
||||
|
||||
builder.name = keyboard[@"name"];
|
||||
builder.identifier = keyboard[@"id"];
|
||||
builder.version = keyboard[@"version"];
|
||||
builder.oskFont = keyboard[@"oskFont"];
|
||||
builder.displayFont = keyboard[@"displayFont"];
|
||||
builder.languages = [languageInfoArray copy];
|
||||
|
||||
KMKeyboardInfo *keyboardInfo = [[KMKeyboardInfo alloc] initWithBuilder:builder];
|
||||
return keyboardInfo;
|
||||
}
|
||||
|
||||
- (KMPackageInfo *) createPackageInfoFromJsonData:(NSDictionary *) jsonData {
|
||||
|
||||
NSMutableArray *keyboardInfoArray = [NSMutableArray arrayWithCapacity:0];
|
||||
|
|
@ -715,49 +740,39 @@ CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef
|
|||
|
||||
// loop through keyboards array and add keyboards, and loop through each keyboard's languages array to add languages
|
||||
for (NSDictionary *keyboard in keyboards) {
|
||||
NSArray *languages = keyboard[@"languages"];
|
||||
NSMutableArray *languageInfoArray = [NSMutableArray arrayWithCapacity:0];
|
||||
|
||||
for (NSDictionary *language in languages) {
|
||||
KMLanguageInfo *languageInfo = [[KMLanguageInfo alloc] initWithName:language[@"name"]
|
||||
identifier:language[@"id"]];
|
||||
|
||||
[languageInfoArray addObject:languageInfo];
|
||||
KMKeyboardInfo *keyboardInfo = [self createKeyboardInfoFromJsonKeyboard:keyboard];
|
||||
|
||||
// add oskFont to fontArray if not nil or empty string
|
||||
if ([keyboardInfo.oskFont length]) {
|
||||
[fontArray addObject:keyboardInfo.oskFont];
|
||||
}
|
||||
|
||||
NSString * oskFont = keyboard[@"oskFont"];
|
||||
if (oskFont && [oskFont length]) {
|
||||
[fontArray addObject:oskFont];
|
||||
|
||||
// add displayFont to fontArray if not not nil or empty string and not equal to oskFont
|
||||
if ([keyboardInfo.displayFont length] && ![keyboardInfo.displayFont isEqualToString:keyboardInfo.displayFont]) {
|
||||
[fontArray addObject:keyboardInfo.displayFont];
|
||||
}
|
||||
NSString * displayFont = keyboard[@"displayFont"];
|
||||
if (displayFont && [displayFont length] && ![displayFont isEqualToString:oskFont]) {
|
||||
[fontArray addObject:displayFont];
|
||||
}
|
||||
|
||||
KMKeyboardInfo *keyboardInfo = [[KMKeyboardInfo alloc] initWithName:keyboard[@"name"]
|
||||
identifier:keyboard[@"id"]
|
||||
version:keyboard[@"version"]
|
||||
oskFont:keyboard[@"oskFont"]
|
||||
displayFont:keyboard[@"displayFont"]
|
||||
languages:[languageInfoArray copy]];
|
||||
|
||||
[keyboardInfoArray addObject:keyboardInfo];
|
||||
|
||||
}
|
||||
|
||||
KMPackageInfo *packageInfo = [[KMPackageInfo alloc] initWithName:jsonData[@"info"][@"name"][@"description"]
|
||||
packageVersion:jsonData[@"info"][@"version"][@"description"]
|
||||
readmeFilename:jsonData[@"options"][@"readmeFile"]
|
||||
graphicFilename:jsonData[@"options"][@"graphicFile"]
|
||||
fileVersion:jsonData[@"system"][@"fileVersion"]
|
||||
keymanDeveloperVersion:jsonData[@"system"][@"keymanDeveloperVersion"]
|
||||
copyright:jsonData[@"info"][@"copyright"][@"description"]
|
||||
authorName:jsonData[@"info"][@"author"][@"description"]
|
||||
authorUrl:jsonData[@"info"][@"author"][@"url"]
|
||||
website:jsonData[@"info"][@"website"][@"url"]
|
||||
keyboards:[keyboardInfoArray copy]
|
||||
fonts:[fontArray copy]
|
||||
files:nil];
|
||||
KMPackageInfoBuilder *builder =
|
||||
[[KMPackageInfoBuilder alloc] init];
|
||||
|
||||
builder.packageName = jsonData[@"info"][@"name"][@"description"];
|
||||
builder.packageVersion = jsonData[@"info"][@"version"][@"description"];
|
||||
builder.readmeFilename = jsonData[@"options"][@"readmeFile"];
|
||||
builder.graphicFilename = jsonData[@"options"][@"graphicFile"];
|
||||
builder.fileVersion = jsonData[@"system"][@"fileVersion"];
|
||||
builder.keymanDeveloperVersion = jsonData[@"system"][@"keymanDeveloperVersion"];
|
||||
builder.copyright = jsonData[@"info"][@"copyright"][@"description"];
|
||||
builder.authorName = jsonData[@"info"][@"author"][@"description"];
|
||||
builder.authorUrl = jsonData[@"info"][@"author"][@"url"];
|
||||
builder.website = jsonData[@"info"][@"website"][@"url"];
|
||||
builder.keyboards = [keyboardInfoArray copy];
|
||||
builder.fonts = [fontArray copy];
|
||||
|
||||
KMPackageInfo *packageInfo = [[KMPackageInfo alloc] initWithBuilder:builder];
|
||||
|
||||
packageInfo.debugReport;
|
||||
return packageInfo;
|
||||
}
|
||||
|
|
@ -769,24 +784,12 @@ CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef
|
|||
adapted from legacy method keyboardInfoFromInfFile that loaded data from inf file to NSDictionary
|
||||
*/
|
||||
- (KMPackageInfo *) loadPackageInfoFromInfFile:(NSString *)path {
|
||||
KMPackageInfo * packageInfo = nil;
|
||||
|
||||
if (self.debugMode)
|
||||
NSLog(@"SGS2021 loading inf package info from path: %@", path);
|
||||
|
||||
NSString* packageName;
|
||||
NSString* packageVersion;
|
||||
NSString* readmeFilename;
|
||||
NSString* graphicFile;
|
||||
NSString* fileVersion;
|
||||
NSString* keymanDeveloperVersion;
|
||||
NSString* copyright;
|
||||
NSString* authorName;
|
||||
NSString* authorUrl;
|
||||
NSString* website;
|
||||
|
||||
|
||||
NSMutableArray *files = [NSMutableArray arrayWithCapacity:0];
|
||||
NSMutableArray *keyboards = [NSMutableArray arrayWithCapacity:0];
|
||||
KMPackageInfoBuilder *builder = [[KMPackageInfoBuilder alloc] init];
|
||||
|
||||
@try {
|
||||
NSString *fileContents = [[NSString stringWithContentsOfFile:path encoding:NSWindowsCP1252StringEncoding error:NULL] stringByReplacingOccurrencesOfString:@"\r" withString:@""];
|
||||
|
|
@ -824,9 +827,9 @@ CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef
|
|||
switch (contentType) {
|
||||
case ctPackage: {
|
||||
if ([line startsWith:kReadMeFile])
|
||||
readmeFilename = [line substringFromIndex:kReadMeFile.length+1];
|
||||
builder.readmeFilename = [line substringFromIndex:kReadMeFile.length+1];
|
||||
else if ([line startsWith:kGraphicFile])
|
||||
graphicFile = [line substringFromIndex:kGraphicFile.length+1];
|
||||
builder.graphicFilename = [line substringFromIndex:kGraphicFile.length+1];
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
@ -850,36 +853,36 @@ CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef
|
|||
NSArray *vs = [s componentsSeparatedByString:@"\","];
|
||||
NSString *v1 = [[vs objectAtIndex:0] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
NSString *v2 = [[vs objectAtIndex:1] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
packageName = v1;
|
||||
builder.packageName = v1;
|
||||
}
|
||||
else if ([line startsWith:kVersion]) {
|
||||
NSString *s = [line substringFromIndex:kVersion.length+1];
|
||||
NSArray *vs = [s componentsSeparatedByString:@"\","];
|
||||
NSString *v1 = [[vs objectAtIndex:0] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
NSString *v2 = [[vs objectAtIndex:1] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
packageVersion = v1;
|
||||
builder.packageVersion = v1;
|
||||
}
|
||||
else if ([line startsWith:kAuthor]) {
|
||||
NSString *s = [line substringFromIndex:kAuthor.length+1];
|
||||
NSArray *vs = [s componentsSeparatedByString:@"\","];
|
||||
NSString *v1 = [[vs objectAtIndex:0] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
NSString *v2 = [[vs objectAtIndex:1] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
authorName = v1;
|
||||
authorUrl = v2;
|
||||
builder.authorName = v1;
|
||||
builder.authorUrl = v2;
|
||||
}
|
||||
else if ([line startsWith:kCopyright]) {
|
||||
NSString *s = [line substringFromIndex:kCopyright.length+1];
|
||||
NSArray *vs = [s componentsSeparatedByString:@"\","];
|
||||
NSString *v1 = [[vs objectAtIndex:0] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
NSString *v2 = [[vs objectAtIndex:1] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
copyright = v1;
|
||||
builder.copyright = v1;
|
||||
}
|
||||
else if ([line startsWith:kWebSite]) {
|
||||
NSString *s = [line substringFromIndex:kWebSite.length+1];
|
||||
NSArray *vs = [s componentsSeparatedByString:@"\","];
|
||||
NSString *v1 = [[vs objectAtIndex:0] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
NSString *v2 = [[vs objectAtIndex:1] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
website = v1;
|
||||
builder.website = v1;
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -906,12 +909,11 @@ CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef
|
|||
NSArray *vs = [s componentsSeparatedByString:@"\","];
|
||||
NSString *keyboardName = [[[vs objectAtIndex:0] substringFromIndex:kKeyboard.length+1] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
NSString *keyboardFileName = [[vs objectAtIndex:1] stringByReplacingOccurrencesOfString:@"\"" withString:@""];
|
||||
KMKeyboardInfo * keyboardInfo = [[KMKeyboardInfo alloc] initWithName:keyboardName
|
||||
identifier:nil
|
||||
version:nil
|
||||
oskFont:nil
|
||||
displayFont:nil
|
||||
languages:nil];
|
||||
|
||||
|
||||
KMKeyboardInfoBuilder *builder = [[KMKeyboardInfoBuilder alloc] init];
|
||||
builder.name = keyboardName;
|
||||
KMKeyboardInfo *keyboardInfo = [[KMKeyboardInfo alloc] initWithBuilder:builder];
|
||||
[keyboards addObject:keyboardInfo];
|
||||
}
|
||||
|
||||
|
|
@ -927,19 +929,7 @@ CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef
|
|||
return nil;
|
||||
}
|
||||
|
||||
packageInfo = [[KMPackageInfo alloc] initWithName:packageName
|
||||
packageVersion:packageVersion
|
||||
readmeFilename:readmeFilename
|
||||
graphicFilename:graphicFile
|
||||
fileVersion:fileVersion
|
||||
keymanDeveloperVersion:keymanDeveloperVersion
|
||||
copyright:copyright
|
||||
authorName:authorName
|
||||
authorUrl:authorUrl
|
||||
website:website
|
||||
keyboards:keyboards
|
||||
fonts:nil
|
||||
files:files];
|
||||
KMPackageInfo *packageInfo = [[KMPackageInfo alloc] initWithBuilder:builder];
|
||||
return packageInfo;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,18 @@
|
|||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KMKeyboardInfoBuilder : NSObject
|
||||
@property (nonatomic,copy) NSString* name;
|
||||
@property (nonatomic,copy) NSString* identifier;
|
||||
@property (nonatomic,copy) NSString* version;
|
||||
@property (nonatomic,copy) NSString* oskFont;
|
||||
@property (nonatomic,copy) NSString* displayFont;
|
||||
@property (nonatomic,copy) NSArray* languages;
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
@end
|
||||
|
||||
@interface KMLanguageInfo : NSObject
|
||||
@property (nonatomic,readonly) NSString* name;
|
||||
@property (nonatomic,readonly) NSString* identifier;
|
||||
|
|
@ -26,6 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@property (nonatomic,readonly) NSString* displayFont;
|
||||
@property (nonatomic,readonly) NSArray* languages;
|
||||
|
||||
- (instancetype)initWithBuilder:(KMKeyboardInfoBuilder*)builder;
|
||||
|
||||
- (instancetype)initWithName:(NSString*)name
|
||||
identifier:(NSString*)identifier
|
||||
version:(NSString*)version
|
||||
|
|
|
|||
|
|
@ -8,6 +8,22 @@
|
|||
|
||||
#import "KMKeyboardInfo.h"
|
||||
|
||||
@implementation KMKeyboardInfoBuilder
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_name = nil;
|
||||
_identifier = nil;
|
||||
_version = nil;
|
||||
_oskFont = nil;
|
||||
_displayFont = nil;
|
||||
_languages = nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
@implementation KMLanguageInfo
|
||||
|
||||
- (instancetype)initWithName:(NSString*)name
|
||||
|
|
@ -25,6 +41,19 @@
|
|||
|
||||
@implementation KMKeyboardInfo
|
||||
|
||||
- (instancetype)initWithBuilder:(KMKeyboardInfoBuilder *)builder {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_name = builder.name;
|
||||
_identifier = builder.identifier;
|
||||
_version = builder.version;
|
||||
_oskFont = builder.oskFont;
|
||||
_displayFont = builder.displayFont;
|
||||
_languages = builder.languages;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(NSString*)name
|
||||
identifier:(NSString*)identifier
|
||||
version:(NSString*)version
|
||||
|
|
|
|||
|
|
@ -10,6 +10,26 @@
|
|||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KMPackageInfoBuilder : NSObject
|
||||
@property (nonatomic,copy) NSString* packageName;
|
||||
@property (nonatomic,copy) NSString* packageVersion;
|
||||
@property (nonatomic,copy) NSString* readmeFilename;
|
||||
@property (nonatomic,copy) NSString* graphicFilename;
|
||||
@property (nonatomic,copy) NSString* fileVersion;
|
||||
@property (nonatomic,copy) NSString* keymanDeveloperVersion;
|
||||
@property (nonatomic,copy) NSString* copyright;
|
||||
@property (nonatomic,copy) NSString* authorName;
|
||||
@property (nonatomic,copy) NSString* authorUrl;
|
||||
@property (nonatomic,copy) NSString* website;
|
||||
@property (nonatomic,copy) NSDictionary* keyboards;
|
||||
@property (nonatomic,copy) NSArray* files;
|
||||
@property (nonatomic,copy) NSArray* fonts;
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface KMPackageInfo : NSObject
|
||||
@property (nonatomic,readonly) NSString* packageName;
|
||||
@property (nonatomic,readonly) NSString* packageVersion;
|
||||
|
|
@ -25,6 +45,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@property (nonatomic,readonly) NSArray* files;
|
||||
@property (nonatomic,readonly) NSArray* fonts;
|
||||
|
||||
- (instancetype)initWithBuilder:(KMPackageInfoBuilder *)builder;
|
||||
|
||||
- (instancetype)initWithName:(NSString*)packageName
|
||||
packageVersion:(NSString*)packageVersion
|
||||
readmeFilename:(NSString*)readmeFilename
|
||||
|
|
@ -39,6 +61,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
fonts:(NSArray*)fonts
|
||||
files:(NSArray*)files;
|
||||
- (void)debugReport;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
|||
|
|
@ -8,8 +8,50 @@
|
|||
|
||||
#import "KMPackageInfo.h"
|
||||
|
||||
@implementation KMPackageInfoBuilder
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_packageName = nil;
|
||||
_packageVersion = nil;
|
||||
_readmeFilename = nil;
|
||||
_graphicFilename = nil;
|
||||
_fileVersion = nil;
|
||||
_keymanDeveloperVersion = nil;
|
||||
_copyright = nil;
|
||||
_authorName = nil;
|
||||
_authorUrl = nil;
|
||||
_website = nil;
|
||||
_keyboards = nil;
|
||||
_fonts = nil;
|
||||
_files = nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation KMPackageInfo
|
||||
|
||||
- (instancetype)initWithBuilder:(KMPackageInfoBuilder *)builder {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_packageName = builder.packageName;
|
||||
_packageVersion = builder.packageVersion;
|
||||
_readmeFilename = builder.readmeFilename;
|
||||
_graphicFilename = builder.graphicFilename;
|
||||
_fileVersion = builder.fileVersion;
|
||||
_keymanDeveloperVersion = builder.keymanDeveloperVersion;
|
||||
_copyright = builder.copyright;
|
||||
_authorName = builder.authorName;
|
||||
_authorUrl = builder.authorUrl;
|
||||
_website = builder.website;
|
||||
_keyboards = builder.keyboards;
|
||||
_fonts = builder.fonts;
|
||||
_files = builder.files;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithName:(NSString*)packageName
|
||||
packageVersion:(NSString*)packageVersion
|
||||
readmeFilename:(NSString*)readmeFilename
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue