1
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#import "KBLocalizationManager.h"
|
||||
#import "KBSkinManager.h"
|
||||
#import "KBSuggestionEngine.h"
|
||||
#import "KBKeyboardLayoutResolver.h"
|
||||
#import <SDWebImage/SDWebImage.h>
|
||||
|
||||
#if DEBUG
|
||||
@@ -48,6 +49,7 @@ static NSString *KBFormatMB(uint64_t bytes) {
|
||||
|
||||
{
|
||||
BOOL _kb_didTriggerLoginDeepLinkOnce;
|
||||
NSString *_kb_lastLoadedProfileId; // 记录上次加载的 profileId
|
||||
#if DEBUG
|
||||
BOOL _kb_debugDidCountAlive;
|
||||
#endif
|
||||
@@ -97,6 +99,9 @@ static NSString *KBFormatMB(uint64_t bytes) {
|
||||
[self kb_registerDarwinSkinInstallObserver];
|
||||
[self kb_consumePendingShopSkin];
|
||||
[self kb_applyDefaultSkinIfNeeded];
|
||||
|
||||
// 监听 App Group 配置变化,动态切换键盘布局
|
||||
[self kb_checkAndApplyLayoutIfNeeded];
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
@@ -198,6 +203,9 @@ static NSString *KBFormatMB(uint64_t bytes) {
|
||||
if (self.kb_defaultGradientLayer) {
|
||||
self.kb_defaultGradientLayer.frame = self.bgImageView.bounds;
|
||||
}
|
||||
|
||||
// 每次布局时检查是否需要切换键盘布局
|
||||
[self kb_checkAndApplyLayoutIfNeeded];
|
||||
}
|
||||
|
||||
- (void)viewWillTransitionToSize:(CGSize)size
|
||||
@@ -238,4 +246,39 @@ static NSString *KBFormatMB(uint64_t bytes) {
|
||||
#endif
|
||||
}
|
||||
|
||||
#pragma mark - Layout Switching
|
||||
|
||||
- (void)kb_checkAndApplyLayoutIfNeeded {
|
||||
NSString *currentProfileId = [[KBKeyboardLayoutResolver sharedResolver] currentProfileId];
|
||||
if (currentProfileId.length == 0) {
|
||||
currentProfileId = @"en_US_qwerty"; // 默认回退
|
||||
}
|
||||
|
||||
// 如果 profileId 没有变化,不需要重新加载
|
||||
if ([currentProfileId isEqualToString:_kb_lastLoadedProfileId]) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSLog(@"[KeyboardViewController] Detected profileId change: %@ -> %@", _kb_lastLoadedProfileId, currentProfileId);
|
||||
_kb_lastLoadedProfileId = currentProfileId;
|
||||
|
||||
// 通知 KBKeyBoardMainView 切换布局
|
||||
if (self.keyBoardMainView && [self.keyBoardMainView respondsToSelector:@selector(reloadLayoutWithProfileId:)]) {
|
||||
[self.keyBoardMainView performSelector:@selector(reloadLayoutWithProfileId:) withObject:currentProfileId];
|
||||
}
|
||||
|
||||
// 更新联想引擎类型
|
||||
NSString *suggestionEngine = [[KBKeyboardLayoutResolver sharedResolver] suggestionEngineForProfileId:currentProfileId];
|
||||
if (suggestionEngine.length > 0) {
|
||||
[self kb_updateSuggestionEngineType:suggestionEngine];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)kb_updateSuggestionEngineType:(NSString *)engineType {
|
||||
// 根据 engineType 切换不同的联想引擎
|
||||
// 例如:latin, pinyin_traditional, pinyin_simplified, bopomofo
|
||||
NSLog(@"[KeyboardViewController] Switching suggestion engine to: %@", engineType);
|
||||
[[KBSuggestionEngine shared] setEngineTypeFromString:engineType];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user