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:
@@ -0,0 +1,38 @@
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
import Carbon.HIToolbox
|
||||
|
||||
// 全局热键(Carbon RegisterEventHotKey,无须辅助功能权限):⌃⌥⌘S 触发 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
|
||||
Reference in New Issue
Block a user