包含本次会话修复: - iOS clickReady 警告 bug(默认 false 永远显示) - BLE 'handle is invalid' 排查(stale handle auto-retry 实验 + 回退) 项目结构: - glass-mouse/: 眼镜端原生 Kotlin App,前台服务 MouseService + 自定义 BLE GATT 桥接 ProxyBleServer + 无障碍 GestureDescription 注入 - ios/GlassRemote/: iPhone 端 SwiftUI + CoreBluetooth,通过 BLE 直连眼镜 - HTTP 投屏服务(:8000) 接 PPT/WPS 备注宏 POST 推送 技术栈: Android Kotlin (gradle 8.14.4, compileSdk 34), iOS Swift 5.10 (Xcode 26.5)
95 lines
3.2 KiB
Swift
95 lines
3.2 KiB
Swift
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
@EnvironmentObject var ble: GlassBLEManager
|
|
@State private var selected = 0
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
// 顶栏(轻量)
|
|
VStack(spacing: 0) {
|
|
topBar
|
|
if ble.connectionState == .ready && ble.hasReceivedClickReadyStatus && !ble.clickReady { smallWarn }
|
|
}
|
|
.background(.regularMaterial)
|
|
|
|
Divider()
|
|
|
|
// 内容区(占满剩余高度,绝不溢出到底栏)
|
|
Group {
|
|
if selected == 0 { ControlView() } else { CastView() }
|
|
}
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
|
|
Divider()
|
|
|
|
// 自定义底部导航栏:全宽钉底
|
|
bottomBar
|
|
}
|
|
.background(Color(.systemGroupedBackground))
|
|
.onAppear { ble.connect() }
|
|
}
|
|
|
|
// 浅色顶栏
|
|
private var topBar: some View {
|
|
HStack(spacing: 10) {
|
|
Image(systemName: "eyeglasses")
|
|
.font(.headline).foregroundColor(.cyan)
|
|
VStack(alignment: .leading, spacing: 1) {
|
|
Text("GlassMouse").font(.subheadline.weight(.semibold))
|
|
HStack(spacing: 5) {
|
|
Circle()
|
|
.fill(ble.connectionState == .ready ? Color.green : Color.orange)
|
|
.frame(width: 7, height: 7)
|
|
Text(ble.connectionState.rawValue)
|
|
.font(.caption2).foregroundColor(.secondary)
|
|
}
|
|
}
|
|
Spacer()
|
|
Button(action: { ble.connect() }) {
|
|
Image(systemName: "arrow.clockwise")
|
|
.font(.subheadline.weight(.semibold))
|
|
.frame(width: 32, height: 32)
|
|
.background(Color.cyan.opacity(0.12))
|
|
.foregroundColor(.cyan)
|
|
.clipShape(Circle())
|
|
}
|
|
}
|
|
.padding(.horizontal, 14).padding(.vertical, 6)
|
|
}
|
|
|
|
// 小条警告
|
|
private var smallWarn: some View {
|
|
HStack(spacing: 6) {
|
|
Image(systemName: "exclamationmark.triangle.fill")
|
|
.font(.caption).foregroundColor(.orange)
|
|
Text("无障碍未开:眼镜上 设置→无障碍→GlassMouse")
|
|
.font(.caption).foregroundColor(.secondary)
|
|
.lineLimit(1)
|
|
}
|
|
.padding(.horizontal, 14).padding(.vertical, 4)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.background(Color.orange.opacity(0.10))
|
|
}
|
|
|
|
// 自定义底部导航栏:全宽钉底
|
|
private var bottomBar: some View {
|
|
HStack(spacing: 0) {
|
|
tabBtn(0, "hand.point.up.left.fill", "控制")
|
|
tabBtn(1, "text.alignleft", "投屏")
|
|
}
|
|
.frame(height: 50)
|
|
.background(.regularMaterial)
|
|
}
|
|
|
|
private func tabBtn(_ idx: Int, _ icon: String, _ label: String) -> some View {
|
|
Button(action: { selected = idx }) {
|
|
VStack(spacing: 2) {
|
|
Image(systemName: icon).font(.system(size: 20))
|
|
Text(label).font(.caption2)
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.foregroundColor(selected == idx ? .cyan : .secondary)
|
|
}
|
|
}
|
|
} |