Add system proxy toggle

This commit is contained in:
世界
2023-09-03 22:59:51 +08:00
parent 4e5b251d6f
commit 30bff41517
7 changed files with 120 additions and 41 deletions
@@ -12,6 +12,8 @@ public struct ActiveDashboardView: View {
@State private var selectedProfileID: Int64!
@State private var alert: Alert?
@State private var selection = DashboardPage.overview
@State private var systemProxyAvailable = false
@State private var systemProxyEnabled = false
public init() {}
public var body: some View {
@@ -37,16 +39,16 @@ public struct ActiveDashboardView: View {
#endif
TabView(selection: $selection) {
ForEach(DashboardPage.allCases) { page in
page.contentView($profileList, $selectedProfileID)
page.contentView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
.tag(page)
}
}
.tabViewStyle(.page(indexDisplayMode: .always))
} else {
OverviewView($profileList, $selectedProfileID)
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
}
#elseif os(macOS)
OverviewView($profileList, $selectedProfileID)
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
#endif
}
#if os(iOS) || os(tvOS)
@@ -65,6 +67,13 @@ public struct ActiveDashboardView: View {
}
}
#endif
.onChangeCompat(of: profile.status) { newStatus in
if newStatus == .connected {
Task.detached {
await doReloadSystemProxy()
}
}
}
.alertBinding($alert)
}
}
@@ -100,4 +109,14 @@ public struct ActiveDashboardView: View {
}
}
}
private func doReloadSystemProxy() {
do {
let status = try LibboxNewStandaloneCommandClient()!.getSystemProxyStatus()
systemProxyAvailable = status.available
systemProxyEnabled = status.enabled
} catch {
alert = Alert(error)
}
}
}