feat(glass+ios): 新增音量/亮度调节 + 眼镜状态回读 + 亮度授权引导
- 眼镜端 MouseService: 新增 volume/brightness/status/grant_write_settings 命令, adjustVolume/adjustBrightness(currentBrightness 走 Settings.System), 亮度依赖 WRITE_SETTINGS - AndroidManifest: 声明 WRITE_SETTINGS 特殊权限(需眼镜手动授予一次) - iOS GlassBLEManager: volumeUp/Down brightnessUp/Down queryStatus, 新增 glassVolume/Brightness/WriteSettings 等 @Published 状态, brightness no_permission 纠正 - ControlView: 音量/亮度 avBar + 未授权引导条, 链路 ready 时回读眼镜状态纠正 UI Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
b9327eee8b
commit
b8cfb58e96
5 files changed
+266
-52
No files matched your search
@@ -10,7 +10,6 @@ struct ControlView: View {
|
||||
@EnvironmentObject var ble: GlassBLEManager
|
||||
@AppStorage("sensitivity") private var sensitivity = 1.6
|
||||
@AppStorage("cursorOn") private var cursorOn = true
|
||||
@AppStorage("screenOn") private var screenOnPref = true
|
||||
@AppStorage("centerMode") private var centerMode: String = "cursor" // 默认 = 光标移动;"swipe" = 真实 touch 短滑
|
||||
// 启动时强制检查:如果默认值是 swipe(v15 留下的),改回 cursor
|
||||
private let didInitMode: Bool = {
|
||||
@@ -30,8 +29,14 @@ struct ControlView: View {
|
||||
funcIcons
|
||||
gesturePadCard
|
||||
bottomBar
|
||||
avBar
|
||||
if ble.glassWriteSettings == false { brightnessHint }
|
||||
}
|
||||
.padding(.horizontal, 16).padding(.top, 8).padding(.bottom, 4)
|
||||
// 链路就绪后回读眼镜状态(音量/亮度/授权),纠正「UI 与眼镜实际状态不一致」
|
||||
.onChange(of: ble.connectionState) { _, state in
|
||||
if state == .ready { ble.queryStatus() }
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: 顶部 3 个功能图标
|
||||
@@ -47,11 +52,6 @@ struct ControlView: View {
|
||||
cursorOn.toggle()
|
||||
ble.setCursor(cursorOn)
|
||||
}
|
||||
iconBtn(system: screenOnPref ? "sun.max.fill" : "moon.fill",
|
||||
label: screenOnPref ? "常亮" : "节能") {
|
||||
screenOnPref.toggle()
|
||||
ble.screenOn()
|
||||
}
|
||||
iconBtn(system: centerMode == "cursor" ? "scope" : "hand.draw.fill",
|
||||
label: centerMode == "cursor" ? "光标模式" : "短滑模式") {
|
||||
centerMode = centerMode == "cursor" ? "swipe" : "cursor"
|
||||
@@ -222,25 +222,12 @@ struct ControlView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: 底部三按钮(屏幕开/关 + 返回 + 主页 + 拍照)
|
||||
// MARK: 底部三按钮(返回 + 主页 + 拍照)
|
||||
private var bottomBar: some View {
|
||||
HStack {
|
||||
screenBtn(system: "power", label: "屏幕", isOn: screenOnPref) {
|
||||
if screenOnPref {
|
||||
ble.screenOff()
|
||||
screenOnPref = false
|
||||
} else {
|
||||
ble.screenOn()
|
||||
screenOnPref = true
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
HStack(spacing: 0) {
|
||||
circleBtn(system: "arrow.uturn.backward", label: "返回") { ble.key("back") }
|
||||
Spacer()
|
||||
circleBtn(system: "house.fill", label: "主页") { ble.key("home") }
|
||||
Spacer()
|
||||
circleBtn(system: "camera.fill", label: "拍照") { ble.camera() }
|
||||
Spacer()
|
||||
}
|
||||
.padding(.horizontal, 8).padding(.vertical, 10)
|
||||
.background(Color(.secondarySystemGroupedBackground))
|
||||
@@ -248,20 +235,6 @@ struct ControlView: View {
|
||||
.shadow(color: .black.opacity(0.08), radius: 8, y: 2)
|
||||
}
|
||||
|
||||
private func screenBtn(system: String, label: String, isOn: Bool, action: @escaping () -> Void) -> some View {
|
||||
Button(action: action) {
|
||||
VStack(spacing: 4) {
|
||||
Image(systemName: system)
|
||||
.font(.title3)
|
||||
.frame(width: 48, height: 48)
|
||||
.background(isOn ? Color.yellow.opacity(0.18) : Color(.systemGroupedBackground))
|
||||
.clipShape(Circle())
|
||||
.foregroundColor(isOn ? .yellow : .primary)
|
||||
Text(label).font(.caption2).foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func circleBtn(system: String, label: String, action: @escaping () -> Void) -> some View {
|
||||
Button(action: action) {
|
||||
VStack(spacing: 4) {
|
||||
@@ -274,5 +247,53 @@ struct ControlView: View {
|
||||
Text(label).font(.caption2).foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
// MARK: 音量 / 亮度 调节条
|
||||
private var avBar: some View {
|
||||
HStack(spacing: 0) {
|
||||
avBtn(system: "speaker.slash.fill", label: "音量−") { ble.volumeDown() }
|
||||
avBtn(system: "speaker.wave.3.fill", label: "音量+") { ble.volumeUp() }
|
||||
Rectangle()
|
||||
.fill(Color.secondary.opacity(0.22))
|
||||
.frame(width: 1, height: 36)
|
||||
.padding(.horizontal, 4)
|
||||
avBtn(system: "sun.min.fill", label: "亮度−") { ble.brightnessDown() }
|
||||
avBtn(system: "sun.max.fill", label: "亮度+") { ble.brightnessUp() }
|
||||
}
|
||||
.padding(.horizontal, 10).padding(.vertical, 8)
|
||||
.background(Color(.secondarySystemGroupedBackground))
|
||||
.clipShape(RoundedRectangle(cornerRadius: 18))
|
||||
.shadow(color: .black.opacity(0.08), radius: 8, y: 2)
|
||||
}
|
||||
|
||||
private func avBtn(system: String, label: String, action: @escaping () -> Void) -> some View {
|
||||
Button(action: action) {
|
||||
VStack(spacing: 3) {
|
||||
Image(systemName: system)
|
||||
.font(.title3)
|
||||
.frame(width: 42, height: 42)
|
||||
.background(Color(.systemGroupedBackground))
|
||||
.clipShape(Circle())
|
||||
.foregroundColor(.primary)
|
||||
Text(label).font(.caption2).foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
/// 亮度未授权时的引导条:点一下跳到眼镜的「修改系统设置」页
|
||||
private var brightnessHint: some View {
|
||||
Button(action: { ble.grantWriteSettings() }) {
|
||||
HStack(spacing: 5) {
|
||||
Image(systemName: "exclamationmark.triangle.fill").font(.caption2)
|
||||
Text("亮度需先授予「修改系统设置」,点此前往").font(.caption2)
|
||||
}
|
||||
.foregroundColor(.orange)
|
||||
.padding(.vertical, 7).padding(.horizontal, 12)
|
||||
.background(Color.orange.opacity(0.12))
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user