This commit is contained in:
2026-01-08 18:57:17 +08:00
parent 8e692647d3
commit bbacef4ff7
14 changed files with 158 additions and 262 deletions

View File

@@ -226,6 +226,12 @@ static NSString * const kKBSkinMetadataThemeKey = @"theme_json";
if ([forceValue respondsToSelector:@selector(boolValue)]) {
forceDownload = [forceValue boolValue];
}
id serverIcons = skinJSON[@"key_icons"];
NSUInteger serverIconCount = [serverIcons isKindOfClass:NSDictionary.class] ? ((NSDictionary *)serverIcons).count : 0;
NSLog(@"[SkinBridge] request id=%@ zip=%@ force=%d key_icons_class=%@ count=%tu",
skinId, zipURL, forceDownload,
serverIcons ? NSStringFromClass([serverIcons class]) : @"nil",
serverIconCount);
// key_icons
// - key_icons使
@@ -236,6 +242,9 @@ static NSString * const kKBSkinMetadataThemeKey = @"theme_json";
} else {
iconShortNames = [self defaultIconShortNames];
}
NSLog(@"[SkinBridge] iconShortNames source=%@ count=%tu",
[skinJSON[@"key_icons"] isKindOfClass:NSDictionary.class] ? @"server" : @"default",
iconShortNames.count);
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *containerURL = [fm containerURLForSecurityApplicationGroupIdentifier:AppGroup];
@@ -262,6 +271,7 @@ static NSString * const kKBSkinMetadataThemeKey = @"theme_json";
NSArray *contents = hasIconsDir ? [fm contentsOfDirectoryAtPath:iconsDir error:NULL] : nil;
//
BOOL hasCachedAssets = (contents.count > 0);
NSLog(@"[SkinBridge] assets cache id=%@ cached=%d iconsDir=%@", skinId, hasCachedAssets, iconsDir);
NSString *bgPath = [skinRoot stringByAppendingPathComponent:@"background.png"];
BOOL useTempRoot = forceDownload;
@@ -482,6 +492,8 @@ static NSString * const kKBSkinMetadataThemeKey = @"theme_json";
//
// B
BOOL hasAssets = (didUnzip || (!forceDownload && hasCachedAssets));
NSLog(@"[SkinBridge] apply check id=%@ hasAssets=%d didUnzip=%d cached=%d",
skinId, hasAssets, didUnzip, hasCachedAssets);
if (!hasAssets) {
NSError *finalError = innerError ?: [NSError errorWithDomain:KBSkinBridgeErrorDomain
code:KBSkinBridgeErrorZipMissing
@@ -491,7 +503,9 @@ static NSString * const kKBSkinMetadataThemeKey = @"theme_json";
return;
}
// key_icons -> App Group
// key_icons -> App Group
NSString *iconsDirFinal = [skinRoot stringByAppendingPathComponent:@"icons"];
__block NSUInteger missingCount = 0;
NSMutableDictionary<NSString *, NSString *> *iconPathMap = [NSMutableDictionary dictionary];
[iconShortNames enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, NSString *shortName, BOOL *stop) {
if (![shortName isKindOfClass:NSString.class] || shortName.length == 0) return;
@@ -500,9 +514,27 @@ static NSString * const kKBSkinMetadataThemeKey = @"theme_json";
if (fileName.pathExtension.length == 0) {
fileName = [fileName stringByAppendingPathExtension:@"png"];
}
NSString *fullPath = [iconsDirFinal stringByAppendingPathComponent:fileName];
if (![fm fileExistsAtPath:fullPath]) {
missingCount += 1;
if (missingCount <= 5) {
NSLog(@"[SkinBridge] icon missing id=%@ short=%@", identifier, fileName);
}
return;
}
NSString *relative = [NSString stringWithFormat:@"Skins/%@/icons/%@", skinId, fileName];
iconPathMap[identifier] = relative;
}];
if (missingCount > 0) {
NSLog(@"[SkinBridge] icon missing count=%tu total=%tu", missingCount, iconShortNames.count);
}
NSLog(@"[SkinBridge] iconPathMap count=%tu shift=%@ shift_upper=%@ backspace=%@ mode_123=%@ return=%@",
iconPathMap.count,
iconPathMap[@"shift"],
iconPathMap[@"shift_upper"],
iconPathMap[@"backspace"],
iconPathMap[@"mode_123"],
iconPathMap[@"return"]);
NSMutableDictionary *themeJSON = [skinJSON mutableCopy];
themeJSON[@"id"] = skinId;
@@ -515,6 +547,8 @@ static NSString * const kKBSkinMetadataThemeKey = @"theme_json";
// Zip background.png
NSData *bgData = [NSData dataWithContentsOfFile:bgPath];
BOOL ok = themeOK;
NSLog(@"[SkinBridge] theme apply id=%@ themeOK=%d bg=%d",
skinId, themeOK, (bgData.length > 0));
if (bgData.length > 0) {
ok = [[KBSkinManager shared] applyImageSkinWithData:bgData skinId:skinId name:name];
}
@@ -748,6 +782,8 @@ static NSString * const kKBSkinMetadataThemeKey = @"theme_json";
shortNames = [self defaultIconShortNames];
}
NSString *iconsDirFinal = iconsDir;
__block NSUInteger missingCount = 0;
NSMutableDictionary<NSString *, NSString *> *iconPathMap = [NSMutableDictionary dictionary];
[shortNames enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, NSString *shortName, BOOL *stop) {
if (identifier.length == 0 || ![shortName isKindOfClass:NSString.class] || shortName.length == 0) return;
@@ -755,9 +791,20 @@ static NSString * const kKBSkinMetadataThemeKey = @"theme_json";
if (fileName.pathExtension.length == 0) {
fileName = [fileName stringByAppendingPathExtension:@"png"];
}
NSString *fullPath = [iconsDirFinal stringByAppendingPathComponent:fileName];
if (![fm fileExistsAtPath:fullPath]) {
missingCount += 1;
if (missingCount <= 5) {
NSLog(@"[SkinBridge] icon missing(bundle) id=%@ short=%@", identifier, fileName);
}
return;
}
NSString *relative = [NSString stringWithFormat:@"Skins/%@/icons/%@", skinId, fileName];
iconPathMap[identifier] = relative;
}];
if (missingCount > 0) {
NSLog(@"[SkinBridge] icon missing(bundle) count=%tu total=%tu", missingCount, shortNames.count);
}
NSMutableDictionary *themeJSON = [NSMutableDictionary dictionary];
themeJSON[@"id"] = skinId;

View File

@@ -152,6 +152,18 @@ static void KBSkinDarwinCallback(CFNotificationCenterRef center, void *observer,
if ([icons isKindOfClass:NSDictionary.class]) {
t.keyIconMap = icons;
}
NSUInteger iconCount = [t.keyIconMap isKindOfClass:NSDictionary.class] ? t.keyIconMap.count : 0;
NSUInteger hiddenCount = t.hiddenKeyTextIdentifiers.count;
NSLog(@"[SkinManager] applyThemeFromJSON id=%@ name=%@ iconMap=%tu hiddenKeys=%tu",
t.skinId, t.name, iconCount, hiddenCount);
if (iconCount > 0) {
NSLog(@"[SkinManager] iconMap sample shift=%@ shift_upper=%@ backspace=%@ mode_123=%@ return=%@",
t.keyIconMap[@"shift"],
t.keyIconMap[@"shift_upper"],
t.keyIconMap[@"backspace"],
t.keyIconMap[@"mode_123"],
t.keyIconMap[@"return"]);
}
return [self applyTheme:t];
}
@@ -249,6 +261,19 @@ static void KBSkinDarwinCallback(CFNotificationCenterRef center, void *observer,
}
- (UIImage *)iconImageForKeyIdentifier:(NSString *)identifier caseVariant:(NSInteger)caseVariant {
#if DEBUG
static NSSet<NSString *> *kb_debugIconIds;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
kb_debugIconIds = [NSSet setWithObjects:
@"shift", @"backspace", @"mode_123", @"mode_abc",
@"symbols_toggle_more", @"symbols_toggle_123",
@"return", @"space", @"emoji_panel", @"letter_q",
nil];
});
BOOL shouldLog = [kb_debugIconIds containsObject:identifier];
#endif
NSDictionary<NSString *, NSString *> *map = self.current.keyIconMap;
NSString *value = nil;
@@ -292,10 +317,23 @@ static void KBSkinDarwinCallback(CFNotificationCenterRef center, void *observer,
UIImage *img = [UIImage imageWithContentsOfFile:fullPath];
if (img) return img;
}
#if DEBUG
if (shouldLog) {
NSLog(@"[SkinManager] icon file missing id=%@ value=%@ skin=%@",
identifier, value, self.current.skinId ?: @"");
}
#endif
return nil;
}
// Assets
return [UIImage imageNamed:value];
UIImage *img = [UIImage imageNamed:value];
#if DEBUG
if (!img && shouldLog) {
NSLog(@"[SkinManager] icon asset missing id=%@ value=%@ skin=%@",
identifier, value, self.current.skinId ?: @"");
}
#endif
return img;
}
// keyIconMap App Group
@@ -329,6 +367,12 @@ static void KBSkinDarwinCallback(CFNotificationCenterRef center, void *observer,
if (img) return img;
}
}
#if DEBUG
if (shouldLog) {
NSLog(@"[SkinManager] icon fallback missing id=%@ variant=%ld skin=%@",
identifier, (long)caseVariant, self.current.skinId ?: @"");
}
#endif
return nil;
}