Mac Quick Send:全局热键 + 菜单栏(Phase 4c)

- MacQuickSend(@Observable 单例):激活 app + NSOpenPanel 多选文件 → 置 pending;MacRootView 观察 pending → 切到「传输」区 + 弹 MacComposeSheet 选目标设备发送(复用现有发送流程与 engine.sendFile)
- MacHotkey:Carbon RegisterEventHotKey 全局热键 ⌃⌥⌘S(无须辅助功能权限)触发 Quick Send。事件处理器须 C 函数指针,用不捕获闭包(只调静态 MacQuickSend.trigger)+ dispatch 主队列再弹模态(避免 Carbon 回调内跑模态)。登录(MacRootView onAppear)注册、登出(onDisappear)注销
- 菜单栏加「快速发送文件…」(登录态)
- 桌面 Wails 实际未实现全局热键(仅曾计划),此为原生 Mac 增益。键位暂固定 ⌃⌥⌘S,后续可做成设置项
- 验证:just mac-build(CommilitiaDropMac.app)BUILD SUCCEEDED;iOS 无关(仅改 macOS-only 文件),不受影响
This commit is contained in:
2026-07-08 00:15:10 +08:00
parent 92e2d550d2
commit f273f2466e
4 changed files with 91 additions and 2 deletions
+38
View File
@@ -0,0 +1,38 @@
#if os(macOS)
import AppKit
import Carbon.HIToolbox
// Carbon RegisterEventHotKeyS Quick Send
// RegisterEventHotKey C
// MacQuickSend.trigger dispatch NSOpenPanel Carbon
final class MacHotkey
{
static let shared = MacHotkey()
private init() {}
private var hotKeyRef: EventHotKeyRef?
private var handlerRef: EventHandlerRef?
func register()
{
guard hotKeyRef == nil else { return }
var spec = EventTypeSpec(eventClass: OSType(kEventClassKeyboard),
eventKind: OSType(kEventHotKeyPressed))
InstallEventHandler(GetApplicationEventTarget(),
{ _, _, _ in DispatchQueue.main.async { MacQuickSend.trigger() }; return noErr },
1, &spec, nil, &handlerRef)
var hotID = EventHotKeyID(signature: OSType(0x4344_5248), id: 1) // 'CDRH'
RegisterEventHotKey(UInt32(kVK_ANSI_S),
UInt32(controlKey | optionKey | cmdKey),
hotID, GetApplicationEventTarget(), 0, &hotKeyRef)
}
func unregister()
{
if let hotKeyRef { UnregisterEventHotKey(hotKeyRef) }
hotKeyRef = nil
if let handlerRef { RemoveEventHandler(handlerRef) }
handlerRef = nil
}
}
#endif