Files
keyboard/Shared/KBConfig.h
2026-03-09 17:34:08 +08:00

145 lines
5.1 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// KBConfig.h
// 主 App 与键盘扩展共用的配置/宏。
//
// 在此处修改后,会通过 PCH 被两个 target 同步引用。
//
#ifndef KBConfig_h
#define KBConfig_h
// UIKit is needed for CGFloat and UIScreen used by size-adaptation helpers
#if __OBJC__
#import <UIKit/UIKit.h>
#import "UIColor+Extension.h"
#endif
/// APP名称
#define AppName @"Key of Love"
/// APP Groups
#define AppGroup @"group.com.loveKey.nyx"
/// 键盘JSON数据
#define AppGroup_MyKbJson @"AppGroup_MyKbJson"
/// 键盘 -> 主 App 订阅页预填充数据(用于免二次请求)
#define AppGroup_SubscriptionPrefillPayload @"AppGroup_SubscriptionPrefillPayload"
/// 用户头像 URL主 App 写入,键盘扩展读取)
#define AppGroup_UserAvatarURL @"AppGroup_UserAvatarURL"
/// 键盘扩展聊天更新的 companionId键盘写入主 App 读取后刷新对应聊天记录)
#define AppGroup_ChatUpdatedCompanionId @"AppGroup_ChatUpdatedCompanionId"
/// 当前选中的输入配置(主 App 写入,键盘扩展读取)
#define AppGroup_SelectedKeyboardProfileId @"AppGroup_SelectedKeyboardProfileId"
#define AppGroup_SelectedKeyboardLanguageCode @"AppGroup_SelectedKeyboardLanguageCode"
#define AppGroup_SelectedKeyboardLayoutVariant @"AppGroup_SelectedKeyboardLayoutVariant"
/// 是否用户手动选择过键盘输入配置(语言/布局/profile
/// YES主 App 不再自动把键盘配置跟随 App 语言变更(避免覆盖用户手选)。
/// NO :主 App 会在“App 语言变化且未手动选择键盘配置”时同步更新键盘配置,使键盘语言/布局与 App 一致。
#define AppGroup_DidUserSelectKeyboardProfile @"AppGroup_DidUserSelectKeyboardProfile"
/// Darwin 跨进程通知:键盘扩展发送聊天消息后通知主 App 刷新
#define kKBDarwinChatUpdated @"com.loveKey.nyx.chat.updated"
/// 皮肤图标加载模式:
/// 0 = 使用本地 Assets 图片名key_icons 的 value 写成图片名,例如 "kb_q_melon"
/// 1 = 使用远程 Zip 皮肤包skinJSON 中提供 zip_urlkey_icons 的 value 写成 Zip 内图标文件名,例如 "key_a"
#ifndef KB_SKIN_ICON_USE_REMOTE
#define KB_SKIN_ICON_USE_REMOTE 1
#endif
// 基础baseUrl
#ifndef KB_BASE_URL
#define KB_BASE_URL @"https://devcallback.loveamorkey.com/api"
#endif
#import "KBFont.h"
// Universal Links 通用链接
#ifndef KB_UL_BASE
#define KB_UL_BASE @"https://app.tknb.net/ul"
#endif
#define KB_UL_LOGIN KB_UL_BASE @"/login"
#define KB_UL_SETTINGS KB_UL_BASE @"/settings"
// 充值入口的通用链接:当前复用 /login 路径,通过 query 区分(避免额外配置 AASA 路径)
#define KB_UL_RECHARGE KB_UL_BASE @"/recharge"
#define KB_UL_LEGAL KB_UL_BASE @"/legal"
// 法律文档 URL。
// 若未配置线上地址,主 App 会自动回退到内置 HTML 页面,避免出现空入口。
#ifndef KB_TERMS_OF_SERVICE_URL
#define KB_TERMS_OF_SERVICE_URL @"https://loveamorkey.com/agreement/user"
#endif
#ifndef KB_PRIVACY_POLICY_URL
#define KB_PRIVACY_POLICY_URL @"https://loveamorkey.com/agreement/privacy"
#endif
#ifndef KB_MEMBERSHIP_AGREEMENT_URL
#define KB_MEMBERSHIP_AGREEMENT_URL @"https://loveamorkey.com/agreement/vip"
#endif
#ifndef KB_AUTO_RENEWAL_AGREEMENT_URL
#define KB_AUTO_RENEWAL_AGREEMENT_URL @"https://loveamorkey.com/agreement/aotu"
#endif
#endif /* KBConfig_h */
// --- 认证/共享钥匙串 配置 ---
// 若已在 Capabilities 中启用 Keychain Sharing并添加访问组
// $(AppIdentifierPrefix)com.loveKey.nyx.shared
// 运行时会展开为TN6HHV45BB.com.loveKey.nyx.shared
// KBAuthManager 通过下面的宏定位访问组;如需修改,可在 Build Settings 或前缀头中覆盖该宏。
#ifndef KB_KEYCHAIN_ACCESS_GROUP
#define KB_KEYCHAIN_ACCESS_GROUP @"TN6HHV45BB.com.loveKey.nyx.shared"
#endif
// 键盘扩展的 Bundle Identifier用于 App 侧检测是否已添加该键盘)
#ifndef KB_KEYBOARD_EXTENSION_BUNDLE_ID
#define KB_KEYBOARD_EXTENSION_BUNDLE_ID @"com.loveKey.nyx.CustomKeyboard"
#endif
// --- 应用自定义 Scheme ---
// 主 App 在 Info.plist 中注册的 URL Scheme用于从键盘扩展唤起容器 App。
// 注意AppDelegate 中对 scheme 做了小写化比较kbkeyboardappextensioniOS 对大小写不敏感;
// 这里统一通过宏引用,避免出现与 App 端不一致的字符串。
#ifndef KB_APP_SCHEME
#define KB_APP_SCHEME @"kbkeyboardAppExtension"
#endif
// --- 尺寸适配(以 375 设计稿为基准) ---
// 用法:传入设计稿上的数值,返回按当前屏幕宽度缩放后的值。
// 例如CGFloat padding = KBFit(16);
#ifndef KB_DESIGN_WIDTH
#define KB_DESIGN_WIDTH 375.0
#endif
#if __OBJC__
static inline CGFloat KBScreenWidth(void) {
CGSize size = [UIScreen mainScreen].bounds.size;
return MIN(size.width, size.height);
}
static inline CGFloat KBScaleFactor(void) {
return KBScreenWidth() / (CGFloat)KB_DESIGN_WIDTH;
}
static inline CGFloat KBFit(CGFloat designValue) {
return designValue * KBScaleFactor();
}
#endif
// --- 常用宏 ---
// 弱引用 self在 block 中避免循环引用):使用处直接写 KBWeakSelf;
#ifndef KBWeakSelf
#define KBWeakSelf __weak __typeof(self) weakSelf = self;
#endif