Merge pull request #149 from kkebo/127-deactivate-on-editing

fix: deactivate the active server when it's modified
This commit is contained in:
Kenta Kubo 2025-09-08 23:10:23 +09:00 committed by GitHub
commit e5c25ad31d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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 {