Refactor to use consolidated CommandClient

This commit is contained in:
世界
2025-11-26 22:25:48 +08:00
parent b71cbae382
commit 39b10d707e
11 changed files with 79 additions and 99 deletions
@@ -3,7 +3,7 @@ import SwiftUI
@MainActor
public struct ConnectionListView: View {
@Environment(\.scenePhase) private var scenePhase
@EnvironmentObject private var commandClient: CommandClient
@StateObject private var viewModel = ConnectionListViewModel()
public init() {}
@@ -56,18 +56,12 @@ public struct ConnectionListView: View {
#endif
.alertBinding($viewModel.alert)
.onAppear {
viewModel.setCommandClient(commandClient)
viewModel.connect()
}
.onDisappear {
viewModel.disconnect()
}
.onChangeCompat(of: scenePhase) { newValue in
if newValue == .active {
viewModel.connect()
} else {
viewModel.disconnect()
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
#if os(iOS)
.background(Color(uiColor: .systemGroupedBackground))