Add connections dashboard

This commit is contained in:
世界
2024-10-06 21:41:07 +08:00
parent c223f50ffb
commit 9dadf5f648
17 changed files with 670 additions and 25 deletions
@@ -50,23 +50,24 @@ public struct ActiveDashboardView: View {
VStack {
#if os(iOS) || os(tvOS)
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict {
Picker("Page", selection: $selection) {
ForEach(DashboardPage.allCases) { page in
page.label
}
viewBuilder {
#if os(iOS)
if #available(iOS 16.0, *) {
content1
} else {
content0
}
#else
content0
#endif
}
.pickerStyle(.segmented)
#if os(iOS)
.padding([.leading, .trailing])
.navigationBarTitleDisplayMode(.inline)
.navigationBarTitleDisplayMode(.inline)
#endif
TabView(selection: $selection) {
ForEach(DashboardPage.allCases) { page in
page.contentView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
.tag(page)
}
.onAppear {
UIScrollView.appearance().isScrollEnabled = false
}
.tabViewStyle(.page(indexDisplayMode: .always))
.tabViewStyle(.page(indexDisplayMode: .never))
} else {
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
}
@@ -90,6 +91,45 @@ public struct ActiveDashboardView: View {
.alertBinding($alert)
}
@ViewBuilder
private var content0: some View {
Picker("Page", selection: $selection) {
ForEach(DashboardPage.allCases) { page in
page.label
}
}
.pickerStyle(.segmented)
#if os(iOS)
.padding([.leading, .trailing])
.navigationBarTitleDisplayMode(.inline)
#endif
TabView(selection: $selection) {
ForEach(DashboardPage.enabledCases) { page in
page.contentView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
.tag(page)
}
}
}
@ViewBuilder
private var content1: some View {
TabView(selection: $selection) {
ForEach(DashboardPage.enabledCases) { page in
page.contentView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
.tag(page)
}
}
.toolbar {
ToolbarTitleMenu {
Picker("Page", selection: $selection) {
ForEach(DashboardPage.allCases) { page in
page.label
}
}
}
}
}
private func doReload() async {
defer {
isLoading = false
@@ -9,6 +9,22 @@ public enum DashboardPage: Int, CaseIterable, Identifiable {
case overview
case groups
case connections
}
public extension DashboardPage {
#if !os(tvOS)
static var enabledCases: [DashboardPage] = [
.overview,
.groups,
.connections,
]
#else
static var enabledCases: [DashboardPage] = [
.overview,
.groups,
]
#endif
}
public extension DashboardPage {
@@ -18,15 +34,19 @@ public extension DashboardPage {
return NSLocalizedString("Overview", comment: "")
case .groups:
return NSLocalizedString("Groups", comment: "")
case .connections:
return NSLocalizedString("Connections", comment: "")
}
}
var label: some View {
switch self {
case .overview:
return Label("Overview", systemImage: "text.and.command.macwindow")
return Label(title, systemImage: "text.and.command.macwindow")
case .groups:
return Label("Groups", systemImage: "rectangle.3.group.fill")
return Label(title, systemImage: "rectangle.3.group.fill")
case .connections:
return Label(title, systemImage: "list.bullet.rectangle.portrait.fill")
}
}
@@ -38,6 +58,8 @@ public extension DashboardPage {
OverviewView(profileList, selectedProfileID, systemProxyAvailable, systemProxyEnabled)
case .groups:
GroupListView()
case .connections:
ConnectionListView()
}
}
}