feat: hide proxy names

This commit is contained in:
mrFq1
2023-05-16 15:24:56 +08:00
parent adcfb183f9
commit 8e9bf8c6cc
4 changed files with 37 additions and 4 deletions

View File

@@ -10,6 +10,8 @@ struct ProxyGroupRowView: View {
@ObservedObject var proxyGroup: DBProxyGroup @ObservedObject var proxyGroup: DBProxyGroup
@EnvironmentObject var hideProxyNames: HideProxyNames
var body: some View { var body: some View {
NavigationLink { NavigationLink {
ProxyGroupView(proxyGroup: proxyGroup) ProxyGroupView(proxyGroup: proxyGroup)
@@ -21,7 +23,9 @@ struct ProxyGroupRowView: View {
var labelView: some View { var labelView: some View {
VStack(spacing: 2) { VStack(spacing: 2) {
HStack(alignment: .center) { HStack(alignment: .center) {
Text(proxyGroup.name) Text(hideProxyNames.hide
? String(proxyGroup.id.prefix(8))
: proxyGroup.name)
.font(.system(size: 15)) .font(.system(size: 15))
Spacer() Spacer()
if let proxy = proxyGroup.currentProxy { if let proxy = proxyGroup.currentProxy {
@@ -34,7 +38,11 @@ struct ProxyGroupRowView: View {
HStack { HStack {
Text(proxyGroup.type.rawValue) Text(proxyGroup.type.rawValue)
Spacer() Spacer()
Text(proxyGroup.now ?? "") if let proxy = proxyGroup.currentProxy {
Text(hideProxyNames.hide
? String(proxy.id.prefix(8))
: proxy.name)
}
} }
.font(.system(size: 11)) .font(.system(size: 11))
.foregroundColor(.secondary) .foregroundColor(.secondary)

View File

@@ -11,6 +11,8 @@ struct ProxyGroupView: View {
@ObservedObject var proxyGroup: DBProxyGroup @ObservedObject var proxyGroup: DBProxyGroup
@EnvironmentObject var searchString: ProxiesSearchString @EnvironmentObject var searchString: ProxiesSearchString
@EnvironmentObject var hideProxyNames: HideProxyNames
@State private var columnCount: Int = 3 @State private var columnCount: Int = 3
@State private var isUpdatingSelect = false @State private var isUpdatingSelect = false
@State private var selectable = false @State private var selectable = false
@@ -56,7 +58,9 @@ struct ProxyGroupView: View {
var proxyInfoView: some View { var proxyInfoView: some View {
HStack() { HStack() {
Text(proxyGroup.name) Text(hideProxyNames.hide
? String(proxyGroup.id.prefix(8))
: proxyGroup.name)
.font(.system(size: 17)) .font(.system(size: 17))
Text(proxyGroup.type.rawValue) Text(proxyGroup.type.rawValue)
.font(.system(size: 13)) .font(.system(size: 13))

View File

@@ -11,6 +11,8 @@ struct ProxyItemView: View {
@Binding var proxy: DBProxy @Binding var proxy: DBProxy
@State var selectable: Bool @State var selectable: Bool
@EnvironmentObject var hideProxyNames: HideProxyNames
init(proxy: Binding<DBProxy>, selectable: Bool) { init(proxy: Binding<DBProxy>, selectable: Bool) {
self._proxy = proxy self._proxy = proxy
self.selectable = selectable self.selectable = selectable
@@ -24,7 +26,9 @@ struct ProxyItemView: View {
var body: some View { var body: some View {
VStack { VStack {
HStack(alignment: .center) { HStack(alignment: .center) {
Text(proxy.name) Text(hideProxyNames.hide
? String(proxy.id.prefix(8))
: proxy.name)
.truncationMode(.tail) .truncationMode(.tail)
.lineLimit(1) .lineLimit(1)
Spacer(minLength: 6) Spacer(minLength: 6)

View File

@@ -6,11 +6,18 @@
import SwiftUI import SwiftUI
class HideProxyNames: ObservableObject, Identifiable {
let id = UUID().uuidString
@Published var hide = false
}
struct ContentView: View { struct ContentView: View {
private let runningState = NotificationCenter.default.publisher(for: .init("ClashRunningStateChanged")) private let runningState = NotificationCenter.default.publisher(for: .init("ClashRunningStateChanged"))
@State private var isRunning = false @State private var isRunning = false
@StateObject private var hideProxyNames = HideProxyNames()
var body: some View { var body: some View {
Group { Group {
if !isRunning { if !isRunning {
@@ -24,6 +31,7 @@ struct ContentView: View {
} }
} }
} }
.environmentObject(hideProxyNames)
.toolbar { .toolbar {
ToolbarItem(placement: .navigation) { ToolbarItem(placement: .navigation) {
Button { Button {
@@ -34,6 +42,15 @@ struct ContentView: View {
.help("Toggle Sidebar") .help("Toggle Sidebar")
.disabled(!isRunning) .disabled(!isRunning)
} }
ToolbarItem {
Button {
hideProxyNames.hide = !hideProxyNames.hide
} label: {
Image(systemName: hideProxyNames.hide ? "eyeglasses" : "wand.and.stars")
}
.disabled(!isRunning)
}
} }
.onReceive(runningState) { _ in .onReceive(runningState) { _ in
isRunning = ConfigManager.shared.isRunning isRunning = ConfigManager.shared.isRunning