Restart service when settings change

This commit is contained in:
世界
2025-12-07 10:28:51 +08:00
parent bd5e5f3a79
commit 39338ab133
10 changed files with 77 additions and 22 deletions
@@ -1,8 +1,11 @@
import Libbox
import Library
import SwiftUI
public struct ProfileOverrideView: View {
@EnvironmentObject private var environments: ExtensionEnvironments
@State private var isLoading = true
@State private var alert: AlertState?
@State private var excludeDefaultRoute = false
@State private var autoRouteUseSubRangesByDefault = false
@State private var excludeAPNsRoute = false
@@ -20,6 +23,7 @@ public struct ProfileOverrideView: View {
FormView {
FormToggle("Hide VPN Icon", "Append `0.0.0.0/31` and `::/127` to `route_exclude_address` if not exists.", $excludeDefaultRoute) { newValue in
await SharedPreferences.excludeDefaultRoute.set(newValue)
await reloadService()
}
FormToggle("No Default Route", """
@@ -27,15 +31,18 @@ public struct ProfileOverrideView: View {
If `<route_address/route_exclude_address>` exists in the configuration, this item will not take effect on the corresponding network (commonly used to resolve HomeKit compatibility issues).
""", $autoRouteUseSubRangesByDefault) { newValue in
await SharedPreferences.autoRouteUseSubRangesByDefault.set(newValue)
await reloadService()
}
FormToggle("Exclude APNs Route", "Append `push.apple.com` to `bypass_domain`, and `17.0.0.0/8` to `route_exclude_address`.", $excludeAPNsRoute) { newValue in
await SharedPreferences.excludeAPNsRoute.set(newValue)
await reloadService()
}
FormButton {
Task {
await SharedPreferences.resetProfileOverride()
await reloadService()
isLoading = true
}
} label: {
@@ -46,11 +53,23 @@ public struct ProfileOverrideView: View {
}
}
.navigationTitle("Profile Override")
.alert($alert)
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
#endif
}
private func reloadService() async {
guard let profile = environments.extensionProfile, profile.status.isConnected else {
return
}
do {
try LibboxNewStandaloneCommandClient()?.serviceReload()
} catch {
alert = AlertState(error: error)
}
}
private func loadSettings() async {
excludeDefaultRoute = await SharedPreferences.excludeDefaultRoute.get()
autoRouteUseSubRangesByDefault = await SharedPreferences.autoRouteUseSubRangesByDefault.get()