Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
e75362a
feat: 初始化项目,提交完整代码
chenjianing123 Apr 28, 2026
a2efa29
固件
chenjianing123 Apr 28, 2026
ac45857
图片
chenjianing123 Apr 28, 2026
f3aa76e
修复typeless录音失效问题
chenjianing123 Apr 28, 2026
56ecc02
修复typeless录音失效问题
chenjianing123 Apr 28, 2026
44b4908
授权弹窗优化
chenjianing123 Apr 28, 2026
e3a6420
Initial project import
ShawnYins Apr 30, 2026
272c1a8
Merge remote main history
ShawnYins Apr 30, 2026
3518af2
适配codex
chenjianing123 May 1, 2026
e47f8b2
Merge remote-tracking branch 'origin/main'
chenjianing123 May 1, 2026
f2c0fb0
新增 AhaType 并优化 macOS 兼容与连接状态
ShawnYins May 5, 2026
c62457c
!1 新增 AhaType 功能,适配 macOS 12/15 并优化连接状态
ShawnYins May 5, 2026
cebc963
win版适配codex
May 11, 2026
3aa1bc2
win版适配codex
May 11, 2026
dd7679b
win版适配codex
May 11, 2026
9a17ab5
win版优化语音输入-todo
May 12, 2026
bb4bf53
适配codex+调试日志
chenjianing123 May 18, 2026
ede5c15
适配kimi先提交一版
chenjianing123 May 19, 2026
78b82e1
适配kimi拨杆
chenjianing123 May 20, 2026
fb3819e
优化新手引导授权与语音输入适配
ShawnYins May 18, 2026
a187a32
新增虚拟拨杆、实时灯效/OLED 还原与画布响应优化
ShawnYins May 28, 2026
8f0664e
默认 OLED 切换 Cursor/Codex GIF + 自动同步、画布 OLED 修复、帮助中心内嵌
ShawnYins May 29, 2026
038b186
画布元件防交叠、修改按钮按 macOS HIG 收窄、Mode 描述与 ⋯ 菜单微调
ShawnYins May 29, 2026
fc3b3c0
修复 DMG 安装包样式:HFS+ + 等 Finder 看到卷再跑 AppleScript
ShawnYins May 29, 2026
5d95944
Fix agent launch handoff and DMG packaging
ShawnYins Jun 2, 2026
f0a5b1c
修复 Agent 生命周期管理与编辑模式卡死,优化 DMG 打包流程
ShawnYins Jun 2, 2026
d3e47dd
合并 github/main-anpx:整合 .gitignore 规则
ShawnYins Jun 2, 2026
9cd4117
修复 macOS 26 首次启动无响应:补全权限描述项 + 降低灯条动画 CPU 占用
ShawnYins Jun 5, 2026
61183f5
修复从 DMG 拖出安装后无法打开:打包前先对 App Bundle 单独公证并 staple
ShawnYins Jun 5, 2026
3664784
Fix macOS 26 launch and signing packaging
ShawnYins Jun 7, 2026
01279bd
修改swift目录
Jun 10, 2026
e154975
更新固件
Jun 10, 2026
f24ab88
feat: 灯效自定义配置、4 Mode 支持、权限延迟申请、编辑态 UI 优化
Jun 10, 2026
a18cb6d
fix: Mode Tab 名称编辑在切换 tab、点击其他位置时也自动保存
Jun 10, 2026
d754f97
java win版
Jun 12, 2026
0085fd2
整理目录
Jun 12, 2026
3a1587a
claude hook
Jun 12, 2026
a59b0a9
Update macOS client for latest firmware sync
Jun 12, 2026
4a0a07e
Fix AhaKey light preview and backspace icon
Jun 13, 2026
b21b9bd
Merge remote-tracking branch 'origin/main-anpx' into main-anpx
Jun 14, 2026
35bbfe6
Refine macOS voice presets and write completion flow
Jun 15, 2026
534121e
Fix write completion dialog and key capture
Jun 15, 2026
bfb4584
Refine primary key input modes
Jun 15, 2026
944d42c
Adjust primary key input layout
Jun 15, 2026
919ecb3
Combine primary key input controls
Jun 15, 2026
1df7387
Fix macOS package entrypoints for source builds
Jun 16, 2026
2bfad6d
Update AhaType cloud service endpoint
Jun 16, 2026
d55242e
Fix AhaType login failure messaging
Jun 16, 2026
31dbc3c
Fix production AhaType API compatibility
Jun 16, 2026
4ad5f3c
提交ubuntu初始架构
Jun 17, 2026
a2a0140
Merge remote-tracking branch 'origin/main-anpx' into main-anpx
Jun 17, 2026
73026f6
Fix payment refresh order status handling
Jun 17, 2026
0f002bf
chore: stop tracking build artifacts and ignore them
ZephyrKeXiner Jun 18, 2026
05f9242
Sync physical switch state to agent
Jun 21, 2026
774344e
Force fresh account refresh after payment
Jun 22, 2026
86331f5
claude hook
Jun 22, 2026
4812844
常规优化
Jun 22, 2026
87626b4
Merge remote-tracking branch 'origin/main-anpx' into main-anpx
Jun 22, 2026
3d986a2
双套任务状态 GIF:固件 0x84/0x85/0x86/0x90 + 客户端 + CI 构建
ShawnYins Jun 23, 2026
87f4a4b
Merge remote main-anpx into local ui-iteration (保留固件新特性)
ShawnYins Jun 23, 2026
37a7701
Fix CH582 firmware build for GCC 14 + xpack toolchain
ShawnYins Jun 23, 2026
c7fec7e
CI: use xpack riscv-none-elf-gcc 14.2.0 + fix LIB_DIR path
ShawnYins Jun 23, 2026
4096eec
Clean firmware and old mac client from main-anpx
starinthenorthernsky Jul 13, 2026
2c564f8
Merge pull request #44 from AhakeyAI/codex/clean-main-anpx-firmware-o…
TheNorthStarYang Jul 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ logs/
**/config_client.json
**/settings.json.bak.*
**/hooks.json.bak.*
scripts/build.local.env

# Local backups / temp
*.bak
Expand All @@ -72,3 +73,19 @@ logs/
# Local model / runtime payloads
internal/
.gstack/

# Java / Maven build output
target/
*.class

# Swift build artifacts
.build/
.swiftpm/
DerivedData/
*.xcuserstate

# Packaged outputs
dist/

# Local env (signing creds etc.)
scripts/build.local.env
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
169 changes: 169 additions & 0 deletions README-sharing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# AhaKeyConfig — AhaKey-X1 原生 macOS 配置工具

## 项目简介

这是一个用 Swift + SwiftUI 写的 macOS 原生应用,直接通过 CoreBluetooth 连接 AhaKey-X1(Vibecoding Keyboard),**不需要 TCP 桥接层**。

原厂工具的架构是 Python (PySide6) → .NET TCP Bridge → Swift BLE Helper,三层转接。这个项目把整个链路压缩成一个 Swift 应用,直连 BLE。

### 功能

- BLE 自动扫描/连接/重连 AhaKey-X1 设备
- 设备状态查询(电量、固件版本、工作模式、灯光、拨杆)
- 4 键 × 3 模式的键位映射(快捷键 + LCD 描述文字)
- IDE 状态同步 → LED 变色(Claude Code hooks 集成)
- LCD 图片/GIF 管理界面(协议已实现,上传功能 TODO)
- 后台守护进程维持 BLE 连接(LaunchAgent)

### 协议实现完整度

BLE 协议已从原厂工具反编译完整还原,包括:
- 帧格式(AA BB ... CC DD)
- 全部 DeviceCmd(0x00-0x90)
- 按键配置(快捷键/宏/描述 三种子类型)
- 大数据写入流程( LCD 图片)
- IDE 状态同步(0x90)

详见 `docs/ble-protocol.md`。

---

## 构建说明

### 环境要求

- macOS 15.0+
- Xcode 15+(或等效 Swift toolchain)
- Swift 5.9+
- Apple Silicon(arm64)

### 编译

```bash
# 仅编译
swift build -c release --arch arm64 --product AhaKeyConfig

# 编译 + 打包 .app bundle(含图标生成、代码签名)
bash scripts/build.sh

# 编译 + 安装到 /Applications
INSTALL_TO_APPLICATIONS=1 bash scripts/build.sh

# 编译 + 安装 + 启动
INSTALL_TO_APPLICATIONS=1 LAUNCH_AFTER_INSTALL=1 bash scripts/build.sh
```

也可以用 Makefile:

```bash
make build # 等同 bash scripts/build.sh
make install # 等同 INSTALL_TO_APPLICATIONS=1 LAUNCH_AFTER_INSTALL=1 bash scripts/build.sh
```

### 代码签名

`scripts/build.sh` 会自动查找本机的 Developer ID Application 或 Apple Development 证书。如需指定:

```bash
SIGNING_IDENTITY="你的签名身份" bash scripts/build.sh
```

**重要**:当前 bundle ID 是 `lab.jawa.ahakeyconfig`,你们需要改成自己的(搜索替换即可,出现在 `Package.swift` 的 product name 不需要改,主要改 `scripts/build.sh` 里的 `APP_IDENTIFIER` 和源码里的 Logger subsystem)。

### 蓝牙权限

App 需要 Bluetooth entitlement 才能使用 CoreBluetooth:

```xml
<key>com.apple.security.device.bluetooth</key>
<true/>
```

`scripts/build.sh` 会自动生成 entitlements 文件并签名。如果用 Xcode 打开项目,需要在 Signing & Capabilities 里手动添加 Bluetooth。

---

## 项目结构

```
ahakeyconfig/
├── Package.swift # SPM 包定义,两个 target
├── Makefile # 快捷构建命令
├── scripts/
│ ├── build.sh # 完整构建脚本(编译+打包+签名+安装)
│ ├── ahakey-state.sh # Claude hooks 用的 LED 状态同步脚本
│ └── generate_icons.swift # 程序化生成 app icon
├── Sources/
│ ├── AhaKeyConfigApp.swift # App 入口,单实例控制
│ ├── BLE/
│ │ ├── AhaKeyProtocol.swift # ★ 协议编解码(帧格式、命令、HID 键码表)
│ │ └── AhaKeyBLEManager.swift # ★ CoreBluetooth 通信管理器
│ ├── Views/
│ │ ├── ContentView.swift # Tab 容器
│ │ ├── DeviceInfoView.swift # 设备信息 + LED 测试 + BLE 日志
│ │ ├── KeyMappingView.swift # 键位映射配置 + 预设方案
│ │ └── LCDManagerView.swift # LCD 图片/GIF 管理
│ ├── Utilities/
│ │ └── AgentManager.swift # LaunchAgent 守护进程管理 + Claude hooks 安装
│ └── Agent/
│ ├── AhaKeyAgent.swift # 轻量 BLE 守护进程(Unix socket 接收状态命令)
│ └── main.swift # Agent 入口
├── docs/
│ └── ble-protocol.md # ★ 完整 BLE 协议文档
└── .gitignore
```

### 重点文件

| 文件 | 说明 |
|------|------|
| `Sources/BLE/AhaKeyProtocol.swift` | 你们的协议完整实现——帧编解码、所有 DeviceCmd、HID 键码表、响应解析 |
| `Sources/BLE/AhaKeyBLEManager.swift` | 直接 CoreBluetooth 通信,自动扫描/连接/重连,写入队列防过载 |
| `docs/ble-protocol.md` | 协议完整文档(从原厂工具反编译 + 抓包验证) |
| `Sources/Agent/AhaKeyAgent.swift` | 后台守护进程,通过 Unix socket 接收 LED 状态命令 |
| `Sources/Utilities/AgentManager.swift` | Claude Code hooks 自动安装/卸载(追加模式,不覆盖已有 hooks) |

---

## 架构说明

### 与原厂工具的对比

```
原厂: Python (PySide6) ←TCP→ .NET (BleTcpBridge) ←stdin/stdout→ Swift (ble_helper)
本项目: Swift (SwiftUI + CoreBluetooth) ──BLE──> 键盘
```

省掉了 TCP 桥接层,连接更稳定,延迟更低,部署更简单(单个 .app)。

### 双进程架构

1. **AhaKeyConfig**(主进程):SwiftUI GUI,键位配置、设备管理、LCD 管理
2. **ahakeyconfig-agent**(守护进程):无 UI,LaunchAgent 管理,维持 BLE 连接 + 接收 Unix socket 命令

守护进程的存在是为了在 GUI 关闭后仍能接收 Claude Code hooks 的 LED 状态推送。

### LED 状态同步流程

```
Claude Code hook → ahakey-state.sh → Unix socket → ahakeyconfig-agent → BLE 0x90 → 键盘 LED
```

---

## 已知限制 / TODO

1. ** LCD 图片上传**:协议已文档化(见 `ble-protocol.md` 第 8 节),UI 已有,但分包上传逻辑未实现
2. **宏录入 UI**:协议支持宏(sub_type 0x74),但 UI 只做了快捷键映射
3. **多模式切换**:代码支持 3 种工作模式(mode 0/1/2),但 UI 目前只操作 mode 0
4. **拨杆联动**:原厂的拨杆→自动授权功能未移植(需要在 PermissionRequest hook 中查询 SwitchState)

---

## 许可说明

本项目无偿共享,欢迎自由使用、修改、集成到你们的官方工具中。无需署名,无附加条件。

协议文档 (`docs/ble-protocol.md`) 基于原厂工具反编译整理,版权归原始作者所有。

如有问题欢迎随时沟通。
Binary file added Resources/AppIcon/AhaKeyStudioIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/DefaultOLED/codex.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Resources/DefaultOLED/cursor.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
162 changes: 162 additions & 0 deletions Resources/Help/AhaKeyStudioHelp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>AhaKey Studio 帮助中心</title>
<style>
:root {
color-scheme: light dark;
font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", sans-serif;
line-height: 1.65;
color: CanvasText;
background: Canvas;
}
body {
margin: 0;
padding: 44px 28px 72px;
}
main {
max-width: 920px;
margin: 0 auto;
}
h1 {
font-size: 34px;
line-height: 1.18;
margin: 0 0 10px;
}
h2 {
font-size: 22px;
margin: 34px 0 12px;
padding-top: 8px;
border-top: 1px solid color-mix(in srgb, CanvasText 14%, transparent);
}
h3 {
font-size: 17px;
margin: 22px 0 8px;
}
p, li {
font-size: 15px;
}
p {
margin: 8px 0;
}
ul, ol {
padding-left: 24px;
}
.lead {
color: color-mix(in srgb, CanvasText 70%, transparent);
font-size: 16px;
margin-bottom: 24px;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 12px;
margin: 18px 0;
}
.card {
border: 1px solid color-mix(in srgb, CanvasText 14%, transparent);
border-radius: 8px;
padding: 16px;
background: color-mix(in srgb, Canvas 92%, CanvasText 4%);
}
.card strong {
display: block;
margin-bottom: 6px;
font-size: 15px;
}
code {
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
font-size: 0.92em;
padding: 2px 5px;
border-radius: 5px;
background: color-mix(in srgb, CanvasText 10%, transparent);
}
.note {
border-left: 3px solid #0a84ff;
padding: 10px 14px;
background: color-mix(in srgb, #0a84ff 10%, Canvas);
border-radius: 6px;
margin: 16px 0;
}
</style>
</head>
<body>
<main>
<h1>AhaKey Studio 帮助中心</h1>
<p class="lead">这份本地说明对应当前客户端界面和代码逻辑,适用于首次设置、权限排查、AhaType 云端整理和键盘配置。</p>

<h2>首次启动流程</h2>
<p>首次打开 AhaKey Studio 会进入新手引导。引导顶部按步骤显示,底部使用“上一步”和“下一步”推进。</p>
<div class="grid">
<div class="card">
<strong>欢迎</strong>
介绍连接键盘、后台语音键接管、macOS 原生语音和体验输入。
</div>
<div class="card">
<strong>系统授权</strong>
检查蓝牙、输入监控和辅助功能。蓝牙用于发现和连接键盘,输入监控与辅助功能用于后台接管实体语音键。
</div>
<div class="card">
<strong>语音授权</strong>
检查麦克风、语音转写、Siri 与听写。默认 macOS 原生语音需要这些能力都可用。
</div>
<div class="card">
<strong>开始体验</strong>
使用客户端内同一套语音链路试说一句话,确认识别和写入链路正常。
</div>
</div>

<h2>需要开启的系统权限</h2>
<ol>
<li><strong>蓝牙:</strong>在“隐私与安全性 > 蓝牙”允许 AhaKey Studio,并确保系统蓝牙已打开。</li>
<li><strong>输入监控:</strong>在“隐私与安全性 > 输入监控”允许 AhaKey Studio,用于后台监听实体语音键。</li>
<li><strong>辅助功能:</strong>在“隐私与安全性 > 辅助功能”允许 AhaKey Studio,用于把语音键转换成 macOS 原生转写或 Fn/Globe 行为。</li>
<li><strong>麦克风:</strong>在“隐私与安全性 > 麦克风”允许 AhaKey Studio,用于苹果原生语音采集。</li>
<li><strong>语音转写:</strong>在“隐私与安全性 > 语音识别”允许 AhaKey Studio,用于系统语音识别。</li>
<li><strong>Siri:</strong>在“系统设置 > Siri 与聚焦”开启 Siri。</li>
<li><strong>听写:</strong>在“系统设置 > 键盘 > 听写”开启听写。</li>
</ol>
<div class="note">如果系统设置里已经打开权限,但客户端仍显示未开启,请完全退出 AhaKey Studio 后重新打开。输入监控和辅助功能常按进程生效,重启后状态会与系统设置一致。</div>

<h2>主界面区域</h2>
<h3>顶部状态栏</h3>
<p>顶部显示设备连接状态、电量、拨杆状态、AhaType 开关和键盘控制状态。“更多”菜单提供重新连接设备、清空 LCD 预览、设备信息、云端账号和退出等入口。</p>

<h3>Keyboard Mode</h3>
<p>Mode 标签对应键盘不同工作模式。Claude Code、Cursor、Codex 三个预设会影响实体按键写入内容和语音键路由。</p>

<h3>配置区</h3>
<p>点击灯条、屏幕、四个按键或拨杆可以进入对应配置。修改会先保存到本地,连接设备并进入编辑配置后再同步到键盘。</p>

<h3>右侧检查面板</h3>
<p>“后台监听中”展示输入监控和辅助功能状态;“苹果原生转写”展示麦克风、语音转写、Siri 与听写状态;“AhaType 云端整理”展示云端整理开关、账号状态和额度信息。</p>

<h2>AhaType 云端整理</h2>
<p>开启 AhaType 后,语音识别结果会先发送到云端整理,再写入当前光标。若未登录、登录过期或额度不足,客户端会退回写入原始转写文本。</p>
<p>可在“更多 > 云端账号 · AhaType”登录、注册、刷新额度、兑换或购买额度。</p>

<h2>语音键体验</h2>
<ol>
<li>保持 AhaKey Studio 在后台运行。</li>
<li>确认权限检查里输入监控、辅助功能、麦克风、语音转写、Siri 与听写均已开启。</li>
<li>确认设备当前在 Mode 0,或在目标 Mode 中已配置语音键。</li>
<li>按一次实体语音键开始录音,再按一次结束并写入当前光标。</li>
</ol>

<h2>底部状态栏</h2>
<p>底部会显示当前选中的部件和模式、未同步改动数量、同步提示和最近同步时间。右下角的“新手引导”可重新进入分步引导,“帮助中心”会打开本文件。</p>

<h2>常见问题</h2>
<h3>为什么麦克风已打开仍提示未开启?</h3>
<p>请完全退出并重新打开 AhaKey Studio。若应用路径或签名发生变化,macOS 可能把新版本视为另一个应用,需要对当前正式包重新授权。</p>

<h3>为什么系统设置没有自动跳到准确页面?</h3>
<p>不同 macOS 版本的系统设置 URL 支持不完全一致。客户端会优先打开最接近的权限页;如果没有定位到目标项,请在“隐私与安全性”中手动选择对应权限。</p>

<h3>为什么连接状态显示由 Agent 控制?</h3>
<p>日常使用由后台 Agent 持有蓝牙连接;需要改键、LCD、同步或本机灯效测试时,点击“编辑配置”由 AhaKey Studio 临时接管蓝牙。</p>
</main>
</body>
</html>
Loading