Improve dashboard

This commit is contained in:
世界
2023-08-02 16:47:07 +08:00
parent b9a7ea4afa
commit 5e0573d15c
24 changed files with 619 additions and 257 deletions
@@ -17,48 +17,54 @@ public struct GroupItemView: View {
@State private var alert: Alert?
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 {
Button(action: {
if group.selectable, group.selected != item.tag {
Task.detached {
selectOutbound()
}
}
}
}, label: {
HStack {
VStack {
HStack {
Text(item.tag)
.font(.caption)
.foregroundStyle(.foreground)
.lineLimit(1)
.truncationMode(.tail)
Spacer(minLength: 0)
}
Spacer(minLength: 8)
HStack {
Text(item.type)
.font(.caption)
.foregroundColor(.secondary)
Spacer(minLength: 0)
}
}
Spacer(minLength: 0)
VStack {
if group.selected == item.tag {
Image(systemName: "checkmark.circle.fill")
.foregroundStyle(Color.accentColor)
}
Spacer(minLength: 0)
if item.urlTestDelay > 0 {
Text(item.delayString)
.font(.caption)
.foregroundColor(item.delayColor)
}
}
}
})
#if !os(tvOS)
.buttonStyle(.borderless)
.padding(EdgeInsets(top: 10, leading: 13, bottom: 10, trailing: 13))
.background(backgroundColor)
.cornerRadius(10)
#endif
.alertBinding($alert)
}
@@ -23,7 +23,6 @@ public struct GroupListView: View {
}, set: { newValue in
groupExpand[it.tag] = newValue
}))
Spacer()
}
}.padding()
}
@@ -40,7 +39,6 @@ public struct GroupListView: View {
}
commandClient = nil
}
.navigationTitle("Groups")
}
private func doReload() {
@@ -51,7 +49,7 @@ public struct GroupListView: View {
OutboundGroupItem(tag: "server2", type: "WireGuard", urlTestTime: .now, urlTestDelay: 34),
OutboundGroupItem(tag: "auto", type: "URLTest", urlTestTime: .now, urlTestDelay: 100),
]),
OutboundGroup(tag: "group2", type: "urltest", selected: "client", selectable: false, items:
OutboundGroup(tag: "group2", type: "urltest", selected: "client", selectable: true, items:
(0 ..< 234).map { index in
OutboundGroupItem(tag: "client\(index)", type: "Shadowsocks", urlTestTime: .now, urlTestDelay: UInt16(100 + index * 10))
}),
+23 -13
View File
@@ -15,12 +15,12 @@ public struct GroupView: View {
private var title: some View {
HStack {
Text(group.tag)
.font(.system(size: 17))
.font(.headline)
Text(group.displayType)
.font(.system(size: 13))
.font(.subheadline)
.foregroundColor(.secondary)
Text("\(group.items.count)")
.font(.system(size: 11))
.font(.subheadline)
.padding(EdgeInsets(top: 2, leading: 4, bottom: 2, trailing: 4))
.background(Color.gray.opacity(0.5))
.cornerRadius(4)
@@ -33,7 +33,7 @@ public struct GroupView: View {
Image(systemName: "arrow.up.to.line")
}
}
#if os(macOS)
#if os(macOS) || os(tvOS)
.buttonStyle(.plain)
#endif
Button {
@@ -43,11 +43,10 @@ public struct GroupView: View {
} label: {
Image(systemName: "bolt.fill")
}
#if os(macOS)
#if os(macOS) || os(tvOS)
.buttonStyle(.plain)
#endif
Spacer(minLength: 6)
}
}.padding([.top, .bottom], 8)
}
public var body: some View {
@@ -61,13 +60,17 @@ public struct GroupView: View {
}
}
} else {
VStack {
VStack(spacing: 5) {
ForEach(Array(itemGroups.enumerated()), id: \.offset) { items in
HStack {
HStack(spacing: 5) {
ForEach(items.element, id: \.tag) { it in
Rectangle()
.fill(it.delayColor)
#if !os(tvOS)
.frame(width: 10, height: 10)
#else
.frame(width: 30, height: 30)
#endif
}
}.frame(maxWidth: .infinity, alignment: .topLeading)
}
@@ -93,7 +96,12 @@ public struct GroupView: View {
}
private var itemGroups: [[OutboundGroupItem]] {
let count = Int(Int(geometryWidth) / 20)
let count: Int
#if os(tvOS)
count = Int(Int(geometryWidth) / 40)
#else
count = Int(Int(geometryWidth) / 20)
#endif
if count == 0 {
return [group.items]
} else {
@@ -104,11 +112,13 @@ public struct GroupView: View {
}
private func explandColumnCount() -> Int {
let count = Int(Int(geometryWidth) / 180)
let standardCount = Int(Int(geometryWidth) / 180)
#if os(iOS)
return count < 2 ? 2 : count
return standardCount < 2 ? 2 : standardCount
#elseif os(tvOS)
return Int(Int(geometryWidth) / 400)
#else
return count < 1 ? 1 : count
return standardCount < 1 ? 1 : standardCount
#endif
}