Fix preview

This commit is contained in:
世界
2023-09-20 21:17:05 +08:00
parent 9dc7713bd0
commit 390e063f20
13 changed files with 150 additions and 80 deletions
@@ -24,60 +24,68 @@ public struct ActiveDashboardView: View {
}
}
} else {
VStack {
#if os(iOS) || os(tvOS)
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict {
Picker("Page", selection: $selection) {
ForEach(DashboardPage.allCases) { page in
page.label
if ApplicationLibrary.inPreview {
body1
} else {
body1
.onChangeCompat(of: profile.status) { newStatus in
if newStatus == .connected {
Task.detached {
await doReloadSystemProxy()
}
}
.pickerStyle(.segmented)
#if os(iOS)
.padding([.leading, .trailing])
.navigationBarTitleDisplayMode(.inline)
#endif
TabView(selection: $selection) {
ForEach(DashboardPage.allCases) { page in
page.contentView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
.tag(page)
}
}
.tabViewStyle(.page(indexDisplayMode: .always))
} else {
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
}
#elseif os(macOS)
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
#endif
}
#if os(iOS) || os(tvOS)
.onChangeCompat(of: scenePhase) { newValue in
if newValue == .active {
Task.detached {
await doReload()
}
}
}
.onChangeCompat(of: parentSelection.wrappedValue) { newValue in
if newValue == .dashboard {
Task.detached {
await doReload()
}
}
}
#endif
.onChangeCompat(of: profile.status) { newStatus in
if newStatus == .connected {
Task.detached {
await doReloadSystemProxy()
}
}
}
.alertBinding($alert)
}
}
private var body1: some View {
VStack {
#if os(iOS) || os(tvOS)
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict {
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.allCases) { page in
page.contentView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
.tag(page)
}
}
.tabViewStyle(.page(indexDisplayMode: .always))
} else {
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
}
#elseif os(macOS)
OverviewView($profileList, $selectedProfileID, $systemProxyAvailable, $systemProxyEnabled)
#endif
}
#if os(iOS) || os(tvOS)
.onChangeCompat(of: scenePhase) { newValue in
if newValue == .active {
Task.detached {
await doReload()
}
}
}
.onChangeCompat(of: parentSelection.wrappedValue) { newValue in
if newValue == .dashboard {
Task.detached {
await doReload()
}
}
}
#endif
.alertBinding($alert)
}
private func doReload() {
defer {
isLoading = false
@@ -87,6 +95,8 @@ public struct ActiveDashboardView: View {
Profile(id: 0, name: "profile local", type: .local, path: ""),
Profile(id: 1, name: "profile remote", type: .remote, path: "", lastUpdated: Date(timeIntervalSince1970: 0)),
]
systemProxyAvailable = true
systemProxyEnabled = true
selectedProfileID = 0
} else {
do {
@@ -27,7 +27,7 @@ public struct ExtensionStatusView: View {
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: columnCount), alignment: .leading) {
if ApplicationLibrary.inPreview {
StatusItem("Status") {
StatusLine("Memory", "6.4 MiB")
StatusLine("Memory", "6.4 MB")
StatusLine("Goroutines", "89")
}
StatusItem("Connections") {
@@ -36,15 +36,15 @@ public struct ExtensionStatusView: View {
}
StatusItem("Traffic") {
StatusLine("Uplink", "38 B/s")
StatusLine("Downlink", "249 MiB/s")
StatusLine("Downlink", "249 MB/s")
}
StatusItem("TrafficTotal") {
StatusLine("Uplink", "52 MiB")
StatusLine("Downlink", "5.6 GiB")
StatusLine("Uplink", "52 MB")
StatusLine("Downlink", "5.6 GB")
}
} else if let message = commandClient.status {
StatusItem("Status") {
StatusLine("Memory", LibboxFormatBytes(message.memory))
StatusLine("Memory", LibboxFormatMemoryBytes(message.memory))
StatusLine("Goroutines", "\(message.goroutines)")
}
StatusItem("Connections") {
@@ -35,7 +35,7 @@ public struct OverviewView: View {
FormView {
#if os(iOS) || os(tvOS)
StartStopButton()
if profile.status.isConnectedStrict, systemProxyAvailable {
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict, systemProxyAvailable {
Toggle("HTTP Proxy", isOn: $systemProxyEnabled)
.onChangeCompat(of: systemProxyEnabled) { newValue in
Task.detached {
@@ -52,7 +52,7 @@ public struct OverviewView: View {
.pickerStyle(.inline)
}
#elseif os(macOS)
if profile.status.isConnectedStrict, systemProxyAvailable {
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict, systemProxyAvailable {
Toggle("HTTP Proxy", isOn: $systemProxyEnabled)
.onChangeCompat(of: systemProxyEnabled) { newValue in
Task.detached {
@@ -72,7 +72,6 @@ public struct OverviewView: View {
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
.alertBinding($alert)
.onChangeCompat(of: selectedProfileID) {
reasserting = true