Improve Start/Stop button

This commit is contained in:
世界
2025-11-26 22:25:52 +08:00
parent 32f5bf1f3b
commit 4f0d1098e6
10 changed files with 176 additions and 45 deletions
+97 -23
View File
@@ -1,6 +1,7 @@
import ApplicationLibrary
import Libbox
import Library
import NetworkExtension
import SwiftUI
struct MainView: View {
@@ -21,35 +22,108 @@ struct MainView: View {
}
var body1: some View {
TabView(selection: $selection) {
ForEach(NavigationPage.allCases, id: \.self) { page in
NavigationStackCompat {
page.contentView
.navigationTitle(page.title)
viewBuilder {
if #available(iOS 26.0, *), !Variant.debugNoIOS26 {
TabView(selection: $selection) {
ForEach(NavigationPage.allCases, id: \.self) { page in
NavigationStackCompat {
page.contentView
.navigationTitle(page.title)
}
.tag(page)
.tabItem { page.label }
}
}
.tag(page)
.tabItem { page.label }
.tabViewBottomAccessory {
HStack(spacing: 12) {
if let profile = environments.extensionProfile {
StatusText(profile: profile)
}
Spacer()
StartStopButton()
}
.padding(.horizontal)
}
.onAppear {
environments.postReload()
}
.alertBinding($alert)
.onChangeCompat(of: scenePhase) { newValue in
if newValue == .active {
environments.postReload()
}
}
.onChangeCompat(of: selection) { newValue in
if newValue == .logs {
environments.connect()
}
}
.environment(\.selection, $selection)
.environment(\.importProfile, $importProfile)
.environment(\.importRemoteProfile, $importRemoteProfile)
.handlesExternalEvents(preferring: [], allowing: ["*"])
.onOpenURL(perform: openURL)
} else {
TabView(selection: $selection) {
ForEach(NavigationPage.allCases, id: \.self) { page in
NavigationStackCompat {
page.contentView
.navigationTitle(page.title)
}
.tag(page)
.tabItem { page.label }
}
}
.onAppear {
environments.postReload()
}
.alertBinding($alert)
.onChangeCompat(of: scenePhase) { newValue in
if newValue == .active {
environments.postReload()
}
}
.onChangeCompat(of: selection) { newValue in
if newValue == .logs {
environments.connect()
}
}
.environment(\.selection, $selection)
.environment(\.importProfile, $importProfile)
.environment(\.importRemoteProfile, $importRemoteProfile)
.handlesExternalEvents(preferring: [], allowing: ["*"])
.onOpenURL(perform: openURL)
}
}
.onAppear {
environments.postReload()
}
private struct StatusText: View {
@ObservedObject var profile: ExtensionProfile
var body: some View {
Text(statusText)
.font(.subheadline)
.foregroundStyle(.secondary)
}
.alertBinding($alert)
.onChangeCompat(of: scenePhase) { newValue in
if newValue == .active {
environments.postReload()
private var statusText: String {
switch profile.status {
case .invalid:
return "Invalid"
case .disconnected:
return "Stopped"
case .connecting:
return "Starting"
case .connected:
return "Started"
case .reasserting:
return "Reasserting"
case .disconnecting:
return "Stopping"
@unknown default:
return "Unknown"
}
}
.onChangeCompat(of: selection) { newValue in
if newValue == .logs {
environments.connect()
}
}
.environment(\.selection, $selection)
.environment(\.importProfile, $importProfile)
.environment(\.importRemoteProfile, $importRemoteProfile)
.handlesExternalEvents(preferring: [], allowing: ["*"])
.onOpenURL(perform: openURL)
}
private func openURL(url: URL) {