From 8e9bf8c6cc56f27c53b8fb58d87d533e05d7ba91 Mon Sep 17 00:00:00 2001 From: mrFq1 <1xxbx0il0@mozmail.com> Date: Tue, 16 May 2023 15:24:56 +0800 Subject: [PATCH] feat: hide proxy names --- .../ContentTabs/Proxies/ProxyGroupRowView.swift | 12 ++++++++++-- .../ContentTabs/Proxies/ProxyGroupView.swift | 6 +++++- .../ContentTabs/Proxies/ProxyItemView.swift | 6 +++++- ClashX Dashboard/Views/ContentView.swift | 17 +++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyGroupRowView.swift b/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyGroupRowView.swift index 816b4c5..f7895d7 100644 --- a/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyGroupRowView.swift +++ b/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyGroupRowView.swift @@ -10,6 +10,8 @@ struct ProxyGroupRowView: View { @ObservedObject var proxyGroup: DBProxyGroup + @EnvironmentObject var hideProxyNames: HideProxyNames + var body: some View { NavigationLink { ProxyGroupView(proxyGroup: proxyGroup) @@ -21,7 +23,9 @@ struct ProxyGroupRowView: View { var labelView: some View { VStack(spacing: 2) { HStack(alignment: .center) { - Text(proxyGroup.name) + Text(hideProxyNames.hide + ? String(proxyGroup.id.prefix(8)) + : proxyGroup.name) .font(.system(size: 15)) Spacer() if let proxy = proxyGroup.currentProxy { @@ -34,7 +38,11 @@ struct ProxyGroupRowView: View { HStack { Text(proxyGroup.type.rawValue) Spacer() - Text(proxyGroup.now ?? "") + if let proxy = proxyGroup.currentProxy { + Text(hideProxyNames.hide + ? String(proxy.id.prefix(8)) + : proxy.name) + } } .font(.system(size: 11)) .foregroundColor(.secondary) diff --git a/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyGroupView.swift b/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyGroupView.swift index 1e1d7e9..3a7ee5f 100644 --- a/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyGroupView.swift +++ b/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyGroupView.swift @@ -11,6 +11,8 @@ struct ProxyGroupView: View { @ObservedObject var proxyGroup: DBProxyGroup @EnvironmentObject var searchString: ProxiesSearchString + @EnvironmentObject var hideProxyNames: HideProxyNames + @State private var columnCount: Int = 3 @State private var isUpdatingSelect = false @State private var selectable = false @@ -56,7 +58,9 @@ struct ProxyGroupView: View { var proxyInfoView: some View { HStack() { - Text(proxyGroup.name) + Text(hideProxyNames.hide + ? String(proxyGroup.id.prefix(8)) + : proxyGroup.name) .font(.system(size: 17)) Text(proxyGroup.type.rawValue) .font(.system(size: 13)) diff --git a/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyItemView.swift b/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyItemView.swift index d2e28f2..4c18870 100644 --- a/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyItemView.swift +++ b/ClashX Dashboard/Views/ContentTabs/Proxies/ProxyItemView.swift @@ -11,6 +11,8 @@ struct ProxyItemView: View { @Binding var proxy: DBProxy @State var selectable: Bool + @EnvironmentObject var hideProxyNames: HideProxyNames + init(proxy: Binding, selectable: Bool) { self._proxy = proxy self.selectable = selectable @@ -24,7 +26,9 @@ struct ProxyItemView: View { var body: some View { VStack { HStack(alignment: .center) { - Text(proxy.name) + Text(hideProxyNames.hide + ? String(proxy.id.prefix(8)) + : proxy.name) .truncationMode(.tail) .lineLimit(1) Spacer(minLength: 6) diff --git a/ClashX Dashboard/Views/ContentView.swift b/ClashX Dashboard/Views/ContentView.swift index 1b52a95..cc4085a 100644 --- a/ClashX Dashboard/Views/ContentView.swift +++ b/ClashX Dashboard/Views/ContentView.swift @@ -6,11 +6,18 @@ import SwiftUI +class HideProxyNames: ObservableObject, Identifiable { + let id = UUID().uuidString + @Published var hide = false +} + struct ContentView: View { private let runningState = NotificationCenter.default.publisher(for: .init("ClashRunningStateChanged")) @State private var isRunning = false + @StateObject private var hideProxyNames = HideProxyNames() + var body: some View { Group { if !isRunning { @@ -24,6 +31,7 @@ struct ContentView: View { } } } + .environmentObject(hideProxyNames) .toolbar { ToolbarItem(placement: .navigation) { Button { @@ -34,6 +42,15 @@ struct ContentView: View { .help("Toggle Sidebar") .disabled(!isRunning) } + + ToolbarItem { + Button { + hideProxyNames.hide = !hideProxyNames.hide + } label: { + Image(systemName: hideProxyNames.hide ? "eyeglasses" : "wand.and.stars") + } + .disabled(!isRunning) + } } .onReceive(runningState) { _ in isRunning = ConfigManager.shared.isRunning