From 8e692647d34a66c80b51da806d1f5ff953114674 Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Thu, 8 Jan 2026 17:23:22 +0800 Subject: [PATCH] 2 --- CustomKeyboard/KeyboardViewController.m | 35 +++++++++++++++++++++++++ CustomKeyboard/View/KBKeyButton.m | 10 +++---- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/CustomKeyboard/KeyboardViewController.m b/CustomKeyboard/KeyboardViewController.m index 742350d..39b1b83 100644 --- a/CustomKeyboard/KeyboardViewController.m +++ b/CustomKeyboard/KeyboardViewController.m @@ -30,6 +30,8 @@ // 以 375 宽设计稿为基准的键盘总高度 static const CGFloat kKBKeyboardBaseHeight = 250.0f; +static NSString * const kKBDefaultSkinId = @"normal_them"; +static NSString * const kKBDefaultSkinZipName = @"normal_them"; static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, void *observer, @@ -97,6 +99,7 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, NULL, CFNotificationSuspensionBehaviorDeliverImmediately); [self kb_consumePendingShopSkin]; + [self kb_applyDefaultSkinIfNeeded]; } @@ -763,6 +766,38 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, }]; } +#pragma mark - Default Skin + +- (void)kb_applyDefaultSkinIfNeeded { + NSDictionary *pending = [KBSkinInstallBridge pendingRequestPayload]; + if (pending.count > 0) { + return; + } + + NSString *currentId = [KBSkinManager shared].current.skinId ?: @""; + BOOL isDefault = (currentId.length == 0 || [currentId isEqualToString:@"default"]); + if (!isDefault && ![currentId isEqualToString:kKBDefaultSkinId]) { + return; + } + if ([currentId isEqualToString:kKBDefaultSkinId]) { + return; + } + + NSError *applyError = nil; + if ([KBSkinInstallBridge applyInstalledSkinWithId:kKBDefaultSkinId error:&applyError]) { + return; + } + + [KBSkinInstallBridge publishBundleSkinRequestWithId:kKBDefaultSkinId + name:kKBDefaultSkinId + zipName:kKBDefaultSkinZipName + iconShortNames:nil]; + [KBSkinInstallBridge consumePendingRequestFromBundle:NSBundle.mainBundle + completion:^(__unused BOOL success, __unused NSError * _Nullable error) { + // 已通过通知触发主题刷新,这里无需额外处理 + }]; +} + #pragma mark - Layout Helpers - (CGFloat)kb_portraitWidth { diff --git a/CustomKeyboard/View/KBKeyButton.m b/CustomKeyboard/View/KBKeyButton.m index 70fb2de..5c09fa2 100644 --- a/CustomKeyboard/View/KBKeyButton.m +++ b/CustomKeyboard/View/KBKeyButton.m @@ -26,10 +26,8 @@ [NSLayoutConstraint activateConstraints:@[ [self.normalImageView.topAnchor constraintEqualToAnchor:self.topAnchor], [self.normalImageView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], -// [self.normalImageView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:2], -// [self.normalImageView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-2], - [self.normalImageView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:0], - [self.normalImageView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-0], + [self.normalImageView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor], + [self.normalImageView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor], ]]; [self applyDefaultStyle]; } @@ -66,8 +64,8 @@ [NSLayoutConstraint activateConstraints:@[ [iv.topAnchor constraintEqualToAnchor:self.topAnchor], [iv.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], - [iv.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:2], - [iv.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-2], + [iv.leadingAnchor constraintEqualToAnchor:self.leadingAnchor], + [iv.trailingAnchor constraintEqualToAnchor:self.trailingAnchor], ]]; self.iconView = iv;