Redesign dashboard

This commit is contained in:
世界
2025-11-26 22:25:51 +08:00
parent b7a810b168
commit 68b4142340
17 changed files with 759 additions and 89 deletions
@@ -0,0 +1,52 @@
import Libbox
import Library
import SwiftUI
public struct ClashModeCard: View {
@EnvironmentObject private var commandClient: CommandClient
@State private var clashMode: String = ""
@State private var alert: Alert?
public init() {}
public var body: some View {
if shouldShowPicker {
DashboardCardView(title: "Mode", isHalfWidth: false) {
Picker("", selection: Binding(get: {
clashMode
}, set: { newMode in
clashMode = newMode
Task {
await setClashMode(newMode)
}
})) {
ForEach(commandClient.clashModeList, id: \.self) { mode in
Text(mode)
}
}
.pickerStyle(.segmented)
}
.onAppear {
clashMode = commandClient.clashMode
}
.onChangeCompat(of: commandClient.clashMode) { newValue in
clashMode = newValue
}
.alertBinding($alert)
}
}
private var shouldShowPicker: Bool {
commandClient.clashModeList.count > 1
}
private nonisolated func setClashMode(_ newMode: String) async {
do {
try LibboxNewStandaloneCommandClient()!.setClashMode(newMode)
} catch {
await MainActor.run {
alert = Alert(error)
}
}
}
}