Restart service when settings change
This commit is contained in:
@@ -3,7 +3,9 @@ import Library
|
||||
import SwiftUI
|
||||
|
||||
public struct OnDemandRulesView: View {
|
||||
@EnvironmentObject private var environments: ExtensionEnvironments
|
||||
@State private var isLoading = true
|
||||
@State private var alert: AlertState?
|
||||
@State private var alwaysOn = false
|
||||
|
||||
public init() {}
|
||||
@@ -23,11 +25,13 @@ public struct OnDemandRulesView: View {
|
||||
This should not be an intended use of the API, so you cannot disable VPN in system settings. To stop the service manually, use the in-app interface or simply delete the VPN profile.
|
||||
""", $alwaysOn) { newValue in
|
||||
await SharedPreferences.alwaysOn.set(newValue)
|
||||
await restartService()
|
||||
}
|
||||
|
||||
FormButton {
|
||||
Task {
|
||||
await SharedPreferences.resetOnDemandRules()
|
||||
await restartService()
|
||||
isLoading = true
|
||||
}
|
||||
} label: {
|
||||
@@ -38,11 +42,23 @@ public struct OnDemandRulesView: View {
|
||||
}
|
||||
}
|
||||
.navigationTitle("On Demand Rules")
|
||||
.alert($alert)
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
#endif
|
||||
}
|
||||
|
||||
private func restartService() async {
|
||||
guard let profile = environments.extensionProfile, profile.status.isConnected else {
|
||||
return
|
||||
}
|
||||
do {
|
||||
try await profile.restart()
|
||||
} catch {
|
||||
alert = AlertState(error: error)
|
||||
}
|
||||
}
|
||||
|
||||
private func loadSettings() async {
|
||||
alwaysOn = await SharedPreferences.alwaysOn.get()
|
||||
isLoading = false
|
||||
|
||||
Reference in New Issue
Block a user