1
This commit is contained in:
@@ -947,4 +947,88 @@ static NSString * const kKBSkinMetadataThemeKey = @"theme_json";
|
||||
return applyOK;
|
||||
}
|
||||
|
||||
+ (BOOL)reloadCurrentSkinIconMapForLanguageCode:(NSString *)languageCode {
|
||||
if (languageCode.length == 0) {
|
||||
NSLog(@"[SkinBridge] reloadCurrentSkinIconMap: empty language code");
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSString *targetSkinId = [NSString stringWithFormat:@"bundle_skin_default_%@", languageCode];
|
||||
NSString *currentSkinId = [KBSkinManager shared].current.skinId ?: @"";
|
||||
|
||||
NSLog(@"[SkinBridge] reloadCurrentSkinIconMap: currentSkin=%@ targetSkin=%@ lang=%@",
|
||||
currentSkinId, targetSkinId, languageCode);
|
||||
|
||||
if ([targetSkinId isEqualToString:currentSkinId]) {
|
||||
NSLog(@"[SkinBridge] reloadCurrentSkinIconMap: already on target skin, just refresh icon map");
|
||||
} else {
|
||||
BOOL hasTargetSkin = [KBSkinManager kb_hasAssetsForSkinId:targetSkinId];
|
||||
NSLog(@"[SkinBridge] reloadCurrentSkinIconMap: hasTargetSkin=%d", hasTargetSkin);
|
||||
|
||||
if (hasTargetSkin) {
|
||||
NSError *applyError = nil;
|
||||
BOOL applied = [self applyInstalledSkinWithId:targetSkinId error:&applyError];
|
||||
NSLog(@"[SkinBridge] reloadCurrentSkinIconMap: switched to %@ applied=%d error=%@",
|
||||
targetSkinId, applied, applyError);
|
||||
return applied;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentSkinId.length == 0 || [currentSkinId isEqualToString:@"default"]) {
|
||||
NSLog(@"[SkinBridge] reloadCurrentSkinIconMap: no custom skin applied, skip");
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSDictionary<NSString *, NSString *> *iconShortNames = [self iconShortNamesForLanguageCode:languageCode];
|
||||
if (iconShortNames.count == 0) {
|
||||
NSLog(@"[SkinBridge] reloadCurrentSkinIconMap: no icon mapping found for language: %@", languageCode);
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSString *skinRoot = [[self kb_skinsRootPath] stringByAppendingPathComponent:currentSkinId];
|
||||
NSString *iconsDir = [skinRoot stringByAppendingPathComponent:@"icons"];
|
||||
|
||||
NSMutableDictionary<NSString *, NSString *> *iconPathMap = [NSMutableDictionary dictionary];
|
||||
[iconShortNames enumerateKeysAndObjectsUsingBlock:^(NSString *identifier, NSString *shortName, BOOL *stop) {
|
||||
if (![shortName isKindOfClass:NSString.class] || shortName.length == 0) return;
|
||||
NSString *fileName = shortName;
|
||||
if (fileName.pathExtension.length == 0) {
|
||||
fileName = [fileName stringByAppendingPathExtension:@"png"];
|
||||
}
|
||||
NSString *fullPath = [iconsDir stringByAppendingPathComponent:fileName];
|
||||
if ([fm fileExistsAtPath:fullPath]) {
|
||||
NSString *relative = [NSString stringWithFormat:@"Skins/%@/icons/%@", currentSkinId, fileName];
|
||||
iconPathMap[identifier] = relative;
|
||||
}
|
||||
}];
|
||||
|
||||
NSLog(@"[SkinBridge] reloadCurrentSkinIconMap: skin=%@ lang=%@ iconCount=%lu",
|
||||
currentSkinId, languageCode, (unsigned long)iconPathMap.count);
|
||||
|
||||
if (iconPathMap.count == 0) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
NSDictionary *meta = [self kb_metadataForSkinId:currentSkinId];
|
||||
NSMutableDictionary *themeJSON = [NSMutableDictionary dictionary];
|
||||
themeJSON[@"id"] = currentSkinId;
|
||||
NSString *name = [meta[kKBSkinMetadataNameKey] isKindOfClass:NSString.class] ? meta[kKBSkinMetadataNameKey] : currentSkinId;
|
||||
themeJSON[@"name"] = name;
|
||||
if (iconPathMap.count > 0) {
|
||||
themeJSON[@"key_icons"] = iconPathMap.copy;
|
||||
}
|
||||
|
||||
NSString *bgPath = [skinRoot stringByAppendingPathComponent:@"background.png"];
|
||||
NSData *bgData = [NSData dataWithContentsOfFile:bgPath];
|
||||
|
||||
BOOL themeOK = [[KBSkinManager shared] applyThemeFromJSON:themeJSON];
|
||||
if (bgData.length > 0) {
|
||||
[[KBSkinManager shared] applyImageSkinWithData:bgData skinId:currentSkinId name:name];
|
||||
}
|
||||
|
||||
NSLog(@"[SkinBridge] reloadCurrentSkinIconMap: applied themeOK=%d", themeOK);
|
||||
return themeOK;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user