feat(macos): add macOS menu-bar app and harden cross-device iCloud sync

Introduce a standalone macOS menu-bar app (OSGKeyboardMac) that reuses the
platform-agnostic OSGKeyboardShared core: record -> cloud/local ASR -> polish
-> insert. Local mode uses Qwen3-ASR via mlx-swift-asr (macOS 15+, Apple
Silicon); iOS targets stay zero-SPM.

Harden iCloud sync for multi-device correctness:
- Per-field settings merge (appSettings.v2) so concurrent edits no longer
  clobber each other's unrelated fields.
- Per-device usage statistics (G-Counter) that sum instead of max().
- Tombstoned dictionary/history merge so deletes propagate and entries can't
  resurrect.
- API keys replicate via iCloud Keychain, never iCloud KVS JSON; pulling a
  legacy blob without key fields no longer wipes local Keychain entries.
- Add a low-risk "Sync Now" action in Settings.

Fix Flow keyboard mic state: stay orange until the host publishes a real ready
contract, share a single MicVoiceAvailability gate, and self-heal stale
cross-process heartbeat jitter instead of getting stuck.

Extract shared storage (SpeechHistoryStore/UsageStatisticsStore,
ConfigurationStore) into OSGKeyboardShared and add tests for the new
sync/merge logic.
This commit is contained in:
Rocky
2026-07-08 18:13:56 +08:00
parent 128aab1b02
commit c2f07bd8d2
99 changed files with 6735 additions and 740 deletions
@@ -99,3 +99,105 @@
"keyboard.translation.offMenu" = "不翻译";
"keyboard.translation.a11y" = "翻译";
"keyboard.translation.a11yHint" = "切换翻译或更改目标语言。";
/* macOS 应用 */
"mac.section.dashboard" = "仪表盘";
"mac.section.history" = "历史";
"mac.section.dictionary" = "个性词库";
"mac.section.settings" = "设置";
"mac.brand.subtitle" = "AI 听写";
"mac.devices" = "设备";
"mac.status.ready" = "准备听写…";
"mac.status.listening" = "录音中…";
"mac.status.transcribing" = "识别中…";
"mac.status.copied" = "已复制到剪贴板";
"mac.status.pasted" = "已插入前台应用";
"mac.status.copiedAndPasted" = "已复制并插入";
"mac.stat.dictationTime" = "听写时长";
"mac.stat.words" = "听写字数";
"mac.stat.translation" = "翻译字数";
"mac.stat.dictionary" = "词库";
"mac.stat.cumulativeDuration" = "累计时长";
"mac.stat.transcribed" = "累计转写";
"mac.stat.cumulativeTranslation" = "累计翻译";
"mac.stat.customTerms" = "自定义词条";
"mac.status.chipReady" = "就绪";
"mac.status.chipProcessing" = "处理中";
"mac.record.start" = "开始录音";
"mac.record.stop" = "停止";
"mac.record.pressStop" = "点击停止";
"mac.copy" = "复制";
"mac.openWindow" = "打开主窗口";
"mac.quit" = "退出";
"mac.mode.cloud" = "云端模式";
"mac.mode.local" = "本地模式";
"mac.connected" = "已连接";
"mac.offline" = "离线";
"mac.history.recent" = "最近";
"mac.history.empty" = "还没有语音识别记录。";
"mac.history.select" = "选择一条记录";
"mac.history.clearTitle" = "清空全部历史?";
"mac.history.clearMessage" = "此操作无法撤销。";
"mac.history.clearConfirm" = "全部清空";
"mac.dict.health" = "词库健康度";
"mac.dict.healthDesc" = "影响识别偏置且润色时不会被改写的自定义词条。";
"mac.dict.search" = "搜索词条";
"mac.dict.empty" = "还没有词条";
"mac.dict.emptyBody" = "在 iPhone 或 iPad 上添加词条以提升识别准确性,它们会通过 iCloud 同步到这里。";
"mac.dict.noMatch" = "无匹配结果";
"mac.cancel" = "取消";
"mac.delete" = "删除";
"mac.dict.deleteTitle" = "删除该词条?";
"mac.dict.deleteMessage" = "此操作无法撤销。";
"mac.hint.holdOption" = "长按 Option 开始听写";
"mac.settings.cloudProvider" = "云端服务商";
"mac.settings.service" = "服务商";
"mac.settings.apiKey" = "API 密钥";
"mac.settings.model" = "模型";
"mac.settings.recognition" = "识别方式";
"mac.settings.cloudEngine" = "云端引擎与 AI 润色";
"mac.settings.cloudEngineDesc" = "通过服务商 API 进行高质量转写,并自动润色语法与风格。";
"mac.settings.localEngine" = "本地识别(Qwen3-ASR";
"mac.settings.localEngineDesc" = "使用 Qwen3-ASR 1.7BMLX)本地转写,高隐私、低延迟。";
"mac.settings.localSpeechFallback" = "本地识别(Apple Speech";
"mac.settings.localSpeechFallbackDesc" = "未安装 Qwen3 模型时,使用 Apple 本地语音识别。";
"mac.settings.about" = "关于";
"mac.settings.general" = "通用";
"mac.settings.input" = "输入与快捷键";
"mac.settings.recognitionLanguage" = "识别语言";
"mac.settings.interfaceLanguage" = "界面语言";
"mac.settings.autoPaste" = "听写后自动粘贴";
"mac.settings.autoPasteDesc" = "转写完成后向前台应用模拟 ⌘V(需辅助功能权限)。";
"mac.settings.hotkey" = "全局快捷键";
"mac.settings.hotkeyDesc" = "按住 Option (⌥) 键即可从任意应用开始听写。";
"mac.settings.qwen3Model" = "Qwen3 模型目录";
"mac.settings.qwen3ModelDesc" = "需包含 config.json、model.safetensors、vocab.json 与 merges.txt。";
"mac.settings.qwen3Browse" = "选择文件夹…";
"mac.settings.qwen3Missing" = "未找到 Qwen3 模型,暂时使用 Apple Speech。";
"mac.settings.accessibility" = "辅助功能";
"mac.settings.accessibilityDesc" = "全局快捷键与自动粘贴需要此权限。";
"mac.settings.openAccessibility" = "打开系统设置";
"mac.settings.appearance" = "外观";
"mac.settings.appearanceDesc" = "跟随系统,或强制使用浅色 / 深色。";
"mac.appearance.system" = "跟随系统";
"mac.appearance.light" = "浅色";
"mac.appearance.dark" = "深色";
"mac.error.noAudio" = "没有捕获到音频";
"mac.error.noCloudASR" = "当前服务商不支持云端语音识别";
"mac.error.emptyTranscript" = "没有识别到语音";
"mac.error.qwen3ModelMissing" = "未安装 Qwen3-ASR 模型";
"mac.error.qwen3LoadFailed" = "Qwen3 模型加载失败:%@";
"mac.error.qwen3InferenceFailed" = "Qwen3 转写失败:%@";
"mac.error.accessibilityRequired" = "请在系统设置中为 OSGKeyboard 启用辅助功能";
"mac.foregroundApp" = "前台应用:%@";
"mac.sync.settingsTitle" = "iCloud 同步";
"mac.sync.settingsSubtitle" = "通过 iCloud 在多台设备间同步设置、使用统计、语音历史与 API 密钥。";
"mac.sync.syncNow" = "立即同步";
"mac.sync.dictTitle" = "个人词库 iCloud 同步";
"mac.sync.dictSubtitle" = "在所有设备间同步个人词库。";
"mac.sync.error.generic" = "无法与 iCloud 同步,请稍后重试。";
"mac.sync.error.dictTooLarge" = "词库过大,无法通过 iCloud 同步。";
"settings.appLanguage.auto" = "自动";
"settings.appLanguage.english" = "英文";
"settings.appLanguage.chinese" = "中文";