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
@@ -7,37 +7,22 @@ final class ClashModeViewModel: ObservableObject {
@Published var clashMode = ""
@Published var alert: Alert?
private let commandClient = CommandClient(.clashMode)
var commandClient: CommandClient?
var clashModeList: [String] {
commandClient.clashModeList
commandClient?.clashModeList ?? []
}
var shouldShowPicker: Bool {
commandClient.clashModeList.count > 1
(commandClient?.clashModeList.count ?? 0) > 1
}
init() {
commandClient.$clashMode
func setCommandClient(_ client: CommandClient) {
commandClient = client
client.$clashMode
.assign(to: &$clashMode)
}
func connect() {
commandClient.connect()
}
func disconnect() {
commandClient.disconnect()
}
func handleScenePhase(_ phase: ScenePhase) {
if phase == .active {
connect()
} else {
disconnect()
}
}
nonisolated func setClashMode(_ newMode: String) async {
do {
try LibboxNewStandaloneCommandClient()!.setClashMode(newMode)