mirror of
https://github.com/yJason/ClashX-Dashboard.git
synced 2026-03-01 00:35:19 +08:00
fix: spm
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// ProxiesView.swift
|
||||
// ClashX Dashboard
|
||||
//
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Introspect
|
||||
|
||||
class ProxiesSearchString: ObservableObject, Identifiable {
|
||||
let id = UUID().uuidString
|
||||
@Published var string: String = ""
|
||||
}
|
||||
|
||||
struct ProxiesView: View {
|
||||
|
||||
@ObservedObject var proxyStorage = DBProxyStorage()
|
||||
|
||||
@State private var searchString = ProxiesSearchString()
|
||||
@State private var isGlobalMode = false
|
||||
|
||||
@StateObject private var hideProxyNames = HideProxyNames()
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
List(proxyStorage.groups, id: \.id) { group in
|
||||
ProxyGroupRowView(proxyGroup: group)
|
||||
}
|
||||
.introspectTableView {
|
||||
$0.refusesFirstResponder = true
|
||||
$0.doubleAction = nil
|
||||
}
|
||||
.listStyle(.plain)
|
||||
EmptyView()
|
||||
}
|
||||
.searchable(text: $searchString.string)
|
||||
.onReceive(NotificationCenter.default.publisher(for: .toolbarSearchString)) {
|
||||
guard let string = $0.userInfo?["String"] as? String else { return }
|
||||
searchString.string = string
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .hideNames)) {
|
||||
guard let hide = $0.userInfo?["hide"] as? Bool else { return }
|
||||
hideProxyNames.hide = hide
|
||||
}
|
||||
.environmentObject(searchString)
|
||||
.onAppear {
|
||||
loadProxies()
|
||||
}
|
||||
.environmentObject(hideProxyNames)
|
||||
.toolbar {
|
||||
ToolbarItem {
|
||||
Button {
|
||||
hideProxyNames.hide = !hideProxyNames.hide
|
||||
} label: {
|
||||
Image(systemName: hideProxyNames.hide ? "eyeglasses" : "wand.and.stars")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func loadProxies() {
|
||||
// self.isGlobalMode = ConfigManager.shared.currentConfig?.mode == .global
|
||||
ApiRequest.getMergedProxyData {
|
||||
guard let resp = $0 else { return }
|
||||
proxyStorage.groups = DBProxyStorage(resp).groups.filter {
|
||||
isGlobalMode ? true : $0.name != "GLOBAL"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//struct ProxiesView_Previews: PreviewProvider {
|
||||
// static var previews: some View {
|
||||
// ProxiesView()
|
||||
// }
|
||||
//}
|
||||
Reference in New Issue
Block a user