diff --git a/ClashX Dashboard Kit/Sources/ClashX Dashboard Kit/Views/SidebarView/SidebarListView.swift b/ClashX Dashboard Kit/Sources/ClashX Dashboard Kit/Views/SidebarView/SidebarListView.swift index dd1f88c..b543425 100644 --- a/ClashX Dashboard Kit/Sources/ClashX Dashboard Kit/Views/SidebarView/SidebarListView.swift +++ b/ClashX Dashboard Kit/Sources/ClashX Dashboard Kit/Views/SidebarView/SidebarListView.swift @@ -5,57 +5,65 @@ // import SwiftUI +import Introspect struct SidebarListView: View { - @Binding var selectionName: String? + @Binding var selectionName: SidebarItem? var body: some View { List { - NavigationLink(destination: OverviewView(), - tag: SidebarItem.overview.rawValue, + tag: SidebarItem.overview, selection: $selectionName) { Label(SidebarItem.overview.rawValue, systemImage: "chart.bar.xaxis") } NavigationLink(destination: ProxiesView(), - tag: SidebarItem.proxies.rawValue, + tag: SidebarItem.proxies, selection: $selectionName) { Label(SidebarItem.proxies.rawValue, systemImage: "globe.asia.australia") } NavigationLink(destination: ProvidersView(), - tag: SidebarItem.providers.rawValue, + tag: SidebarItem.providers, selection: $selectionName) { Label(SidebarItem.providers.rawValue, systemImage: "link.icloud") } NavigationLink(destination: RulesView(), - tag: SidebarItem.rules.rawValue, + tag: SidebarItem.rules, selection: $selectionName) { Label(SidebarItem.rules.rawValue, systemImage: "waveform.and.magnifyingglass") } NavigationLink(destination: ConnectionsView(), - tag: SidebarItem.conns.rawValue, + tag: SidebarItem.conns, selection: $selectionName) { Label(SidebarItem.conns.rawValue, systemImage: "app.connected.to.app.below.fill") } NavigationLink(destination: ConfigView(), - tag: SidebarItem.config.rawValue, + tag: SidebarItem.config, selection: $selectionName) { Label(SidebarItem.config.rawValue, systemImage: "slider.horizontal.3") } NavigationLink(destination: LogsView(), - tag: SidebarItem.logs.rawValue, + tag: SidebarItem.logs, selection: $selectionName) { Label(SidebarItem.logs.rawValue, systemImage: "wand.and.stars.inverse") } - + } + .introspectTableView { + if selectionName == nil { + selectionName = SidebarItem.overview + $0.allowsEmptySelection = false + if $0.selectedRow == -1 { + $0.selectRowIndexes(.init(integer: 0), byExtendingSelection: false) + } + } } .listStyle(.sidebar) } diff --git a/ClashX Dashboard Kit/Sources/ClashX Dashboard Kit/Views/SidebarView/SidebarView.swift b/ClashX Dashboard Kit/Sources/ClashX Dashboard Kit/Views/SidebarView/SidebarView.swift index b1d7246..3a847c9 100644 --- a/ClashX Dashboard Kit/Sources/ClashX Dashboard Kit/Views/SidebarView/SidebarView.swift +++ b/ClashX Dashboard Kit/Sources/ClashX Dashboard Kit/Views/SidebarView/SidebarView.swift @@ -13,10 +13,10 @@ struct SidebarView: View { private let connsQueue = DispatchQueue(label: "thread-safe-connsQueue", attributes: .concurrent) private let timer = Timer.publish(every: 1, on: .main, in: .default).autoconnect() - @State private var sidebarSelectionName: String? = "Overview" + @State private var sidebarSelectionName: SidebarItem? var body: some View { - ScrollViewReader { scrollViewProxy in + Group { SidebarListView(selectionName: $sidebarSelectionName) } .environmentObject(clashApiDatasStorage.overviewData) @@ -27,8 +27,6 @@ struct SidebarView: View { ConfigManager.selectLoggingApiLevel = .info } - sidebarItemChanged(sidebarSelectionName) - clashApiDatasStorage.resetStreamApi() connsQueue.sync { clashApiDatasStorage.connsStorage.conns @@ -57,9 +55,8 @@ struct SidebarView: View { } } - func sidebarItemChanged(_ name: String?) { - guard let str = name, - let item = SidebarItem(rawValue: str) else { return } + func sidebarItemChanged(_ item: SidebarItem?) { + guard let item else { return } NotificationCenter.default.post(name: .sidebarItemChanged, object: nil, userInfo: ["item": item]) }