Files
Commilitia-Drop/ios/CDrop/MacApp/MacHotkey.swift
T
admin f273f2466e 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 文件),不受影响
2026-07-08 00:15:10 +08:00

39 lines
1.5 KiB
Swift
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.
#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