Init commit
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import Libbox
|
||||
import Library
|
||||
import SwiftUI
|
||||
|
||||
public struct GroupItemView: View {
|
||||
private let _group: Binding<OutboundGroup>
|
||||
private var group: OutboundGroup {
|
||||
_group.wrappedValue
|
||||
}
|
||||
|
||||
private let item: OutboundGroupItem
|
||||
public init(_ group: Binding<OutboundGroup>, _ item: OutboundGroupItem) {
|
||||
_group = group
|
||||
self.item = item
|
||||
}
|
||||
|
||||
@State private var errorPresented = false
|
||||
@State private var errorMessage = ""
|
||||
|
||||
public var body: some View {
|
||||
HStack {
|
||||
if group.selected == item.tag {
|
||||
Rectangle()
|
||||
.fill(Color.accentColor)
|
||||
.frame(width: 6)
|
||||
} else {
|
||||
Rectangle()
|
||||
.fill(.clear)
|
||||
.frame(width: 6)
|
||||
}
|
||||
VStack {
|
||||
HStack {
|
||||
Text(item.tag)
|
||||
.truncationMode(.tail)
|
||||
.lineLimit(1)
|
||||
.font(.system(size: 14))
|
||||
Spacer(minLength: 6)
|
||||
}
|
||||
Spacer(minLength: 6)
|
||||
HStack(alignment: .center) {
|
||||
Text(item.type)
|
||||
.foregroundColor(.secondary)
|
||||
.font(.system(size: 12))
|
||||
Spacer(minLength: 6)
|
||||
if item.urlTestDelay > 0 {
|
||||
Text(item.delayString)
|
||||
.foregroundColor(item.delayColor)
|
||||
.font(.system(size: 11))
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: 36)
|
||||
.padding([.top, .bottom, .trailing], 12)
|
||||
}
|
||||
.background(backgroundColor)
|
||||
.onTapGesture {
|
||||
if group.selectable, group.selected != item.tag {
|
||||
Task.detached {
|
||||
selectOutbound()
|
||||
}
|
||||
}
|
||||
}
|
||||
.alert(isPresented: $errorPresented) {
|
||||
Alert(
|
||||
title: Text("Error"),
|
||||
message: Text(errorMessage),
|
||||
dismissButton: .default(Text("Ok"))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private func selectOutbound() {
|
||||
do {
|
||||
try LibboxNewStandaloneCommandClient(FilePath.sharedDirectory.relativePath)!.selectOutbound(group.tag, outboundTag: item.tag)
|
||||
var newGroup = group
|
||||
newGroup.selected = item.tag
|
||||
_group.wrappedValue = newGroup
|
||||
} catch {
|
||||
errorMessage = error.localizedDescription
|
||||
errorPresented = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
private var backgroundColor: Color {
|
||||
#if os(iOS)
|
||||
return Color(uiColor: .secondarySystemGroupedBackground)
|
||||
#elseif os(macOS)
|
||||
return Color(nsColor: .textBackgroundColor)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user