Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Package.resolved

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

33 changes: 30 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,40 @@ import PackageDescription
let package = Package(
name: "AhaKeyConfig",
platforms: [
.macOS("12.0")
.macOS(.v13)
],
products: [
.executable(name: "AhaKeyConfig", targets: ["AhaKeyConfig"]),
.executable(name: "ahakeyconfig-agent", targets: ["AhaKeyConfigAgent"]),
.executable(name: "PluginShowcase", targets: ["PluginShowcase"]),
.library(name: "AhaKeyPluginKit", targets: ["AhaKeyPluginKit"]),
],
dependencies: [
.package(path: "vibebar"),
],

targets: [
.target(
name: "AhaKeyPluginKit",
path: "ahakeyconfig-mac/Sources/AhaKeyPluginKit"
),
.executableTarget(
name: "Plugin",
dependencies: ["AhaKeyPluginKit"],
path: "ahakeyconfig-mac/Sources/AhaKeyPlugin"
),
.executableTarget(
name: "PluginShowcase",
dependencies: ["AhaKeyPluginKit"],
path: "ahakeyconfig-mac/Sources/AhaKeyPluginShowcase"
),
.executableTarget(
name: "AhaKeyConfig",
dependencies: [
"AhaKeyPluginKit",
.product(name: "VibeBar", package: "VibeBar"),
],
path: "ahakeyconfig-mac/Sources",
exclude: ["Agent"],
exclude: ["Agent", "AhaKeyPlugin", "AhaKeyPluginKit", "AhaKeyPluginShowcase"],
// 与 scripts/build.sh 中 Info.plist 一致。嵌入 __info_plist 段后 TCC 可识别。
// Debug 使用单独 plist:系统在「隐私与安全性」列表中显示为「AhaKey Studio(调试)」,与正式包区分。
linkerSettings: [
Expand All @@ -37,5 +59,10 @@ let package = Package(
name: "AhaKeyConfigAgent",
path: "ahakeyconfig-mac/Sources/Agent"
),
.testTarget(
name: "AhaKeyConfigTests",
dependencies: ["AhaKeyConfig"],
path: "ahakeyconfig-mac/Tests/AhaKeyConfigTests"
),
]
)
14 changes: 14 additions & 0 deletions ahakeyconfig-mac/Package.resolved

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

15 changes: 13 additions & 2 deletions ahakeyconfig-mac/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import PackageDescription
let package = Package(
name: "AhaKeyConfig",
platforms: [
.macOS("12.0")
.macOS(.v13)
],
products: [
.executable(name: "AhaKeyConfig", targets: ["AhaKeyConfig"]),
.executable(name: "ahakeyconfig-agent", targets: ["AhaKeyConfigAgent"]),
.executable(name: "PluginShowcase", targets: ["PluginShowcase"]),
.library(name: "AhaKeyPluginKit", targets: ["AhaKeyPluginKit"]),
],
dependencies: [
.package(path: "../vibebar"),
],

targets: [
.target(
Expand All @@ -30,7 +33,10 @@ let package = Package(
),
.executableTarget(
name: "AhaKeyConfig",
dependencies: ["AhaKeyPluginKit"],
dependencies: [
"AhaKeyPluginKit",
.product(name: "VibeBar", package: "VibeBar"),
],
path: "Sources",
exclude: ["Agent", "AhaKeyPlugin", "AhaKeyPluginKit", "AhaKeyPluginShowcase"],
// 与 scripts/build.sh 中 Info.plist 一致。嵌入 __info_plist 段后 TCC 可识别。
Expand All @@ -54,5 +60,10 @@ let package = Package(
name: "AhaKeyConfigAgent",
path: "Sources/Agent"
),
.testTarget(
name: "AhaKeyConfigTests",
dependencies: ["AhaKeyConfig"],
path: "Tests/AhaKeyConfigTests"
),
]
)
12 changes: 9 additions & 3 deletions ahakeyconfig-mac/Sources/Agent/AhaKeyAgent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ final class AhaKeyAgent: NSObject, CBCentralManagerDelegate, CBPeripheralDelegat
private let serviceUUID = CBUUID(string: "7340")
private let commandCharUUID = CBUUID(string: "7343")
private let notifyCharUUID = CBUUID(string: "7344")
private let deviceNamePrefix = "AhaKey"
/// 设备名前缀白名单:官方 "AhaKey" 及 vibe coding 固件的 "vibe code"(与主 App 保持一致)。
private let deviceNamePrefixes = ["AhaKey", "vibe code"]
private let socketPath: String

private func matchesDeviceName(_ name: String?) -> Bool {
guard let lower = name?.lowercased() else { return false }
return deviceNamePrefixes.contains { lower.hasPrefix($0.lowercased()) }
}

private let header: [UInt8] = [0xAA, 0xBB]
private let trailer: [UInt8] = [0xCC, 0xDD]

Expand Down Expand Up @@ -442,7 +448,7 @@ final class AhaKeyAgent: NSObject, CBCentralManagerDelegate, CBPeripheralDelegat

// 2. 系统已连接
let connected = central.retrieveConnectedPeripherals(withServices: [serviceUUID])
if let p = connected.first(where: { ($0.name ?? "").lowercased().hasPrefix(deviceNamePrefix.lowercased()) }) {
if let p = connected.first(where: { matchesDeviceName($0.name) }) {
emit("系统已连接: \(p.name ?? "?")")
peripheral = p
p.delegate = self
Expand Down Expand Up @@ -472,7 +478,7 @@ final class AhaKeyAgent: NSObject, CBCentralManagerDelegate, CBPeripheralDelegat
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral,
advertisementData: [String: Any], rssi RSSI: NSNumber) {
let name = peripheral.name ?? advertisementData[CBAdvertisementDataLocalNameKey] as? String ?? ""
guard name.lowercased().hasPrefix(deviceNamePrefix.lowercased()) else { return }
guard matchesDeviceName(name) else { return }
central.stopScan()
emit("发现: \(name)")
self.peripheral = peripheral
Expand Down
8 changes: 8 additions & 0 deletions ahakeyconfig-mac/Sources/AhaKeyConfigApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ import SwiftUI
import AVFoundation
import Speech
import UserNotifications
import VibeBar

@main
struct AhaKeyConfigApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject private var bleManager = AhaKeyBLEManager()
@State private var vibeBarBridge = VibeBarBridge()

var body: some Scene {
WindowGroup("AhaKey Studio") {
ContentView(bleManager: bleManager)
.frame(minWidth: 1180, minHeight: 680)
.onAppear {
vibeBarBridge.attach(bleManager: bleManager) { [weak appDelegate] in
appDelegate?.reopenMainWindow()
}
VibeBarController.shared.start(state: vibeBarBridge.state)
}
}
.windowStyle(.titleBar)

Expand Down
Loading
Loading