fix: deactivate the active server when it's modified

fixes #127
This commit is contained in:
Kenta Kubo 2025-09-08 23:02:58 +09:00
parent 5516a3f1e0
commit 87c6069581
No known key found for this signature in database
GPG key ID: 3D79E20285C94BE8
2 changed files with 5 additions and 27 deletions

View file

@ -9,7 +9,6 @@
import SwiftUI
struct ContentView {
@Environment(\.scenePhase) private var scenePhase
@Environment(\.horizontalSizeClass) private var hSizeClass
@Binding var servers: Resolvers
@Binding var usedID: String?
@ -239,19 +238,6 @@ extension ContentView: View {
self.updateStatus()
}
}
.onChange(of: self.scenePhase) { phase in
if phase == .background {
// FIXME: This is a workaround for self.$severs[i].
// That cannot save settings as soon as it is modified.
guard let id = self.usedID,
let uuid = UUID(uuidString: id),
let server = self.servers.find(by: uuid)
else {
return
}
self.saveSettings(of: server)
}
}
}
@available(iOS, deprecated: 16)
@ -307,19 +293,6 @@ extension ContentView: View {
self.updateStatus()
}
}
.onChange(of: self.scenePhase) { phase in
if phase == .background {
// FIXME: This is a workaround for self.$severs[i].
// That cannot save settings as soon as it is modified.
guard let id = self.usedID,
let uuid = UUID(uuidString: id),
let server = self.servers.find(by: uuid)
else {
return
}
self.saveSettings(of: server)
}
}
}
@ToolbarContentBuilder private var toolbarContent: some ToolbarContent {

View file

@ -85,6 +85,11 @@ extension DetailView: View {
}
}
.navigationTitle(self.server.name)
.onChange(of: self.server) { [oldValue = self.server] newValue in
guard self.isSelected, oldValue.id == newValue.id else { return }
// When the selected server's configuration is modified, the server will be deactivated or deselected so that the user can save the changes by toggling the Use This Server switch again.
self.isSelected = false
}
}
@ViewBuilder private var serverConfigurationSections: some View {