feat: update the activation status in real time

The activation status on the bottom bar is now updated in real time. So
we don't need the refresh button anymore.
This commit is contained in:
Kenta Kubo 2025-05-05 02:25:11 +09:00
parent 89c35e840e
commit 1adf591e1c
No known key found for this signature in database
GPG key ID: 3D79E20285C94BE8

View file

@ -197,10 +197,16 @@ extension ContentView: View {
}
}
.onAppear(perform: self.updateStatus)
.onChange(of: self.scenePhase) { phase in
if phase == .active {
.task {
for await _ in NotificationCenter.default
.notifications(named: .NEDNSSettingsConfigurationDidChange)
.map(\.name)
{
self.updateStatus()
} else if phase == .background {
}
}
.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,
@ -274,10 +280,16 @@ extension ContentView: View {
}
}
.onAppear(perform: self.updateStatus)
.onChange(of: self.scenePhase) { phase in
if phase == .active {
.task {
for await _ in NotificationCenter.default
.notifications(named: .NEDNSSettingsConfigurationDidChange)
.map(\.name)
{
self.updateStatus()
} else if phase == .background {
}
}
.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,
@ -345,14 +357,6 @@ extension ContentView: View {
}
}
}
#if targetEnvironment(macCatalyst)
ToolbarItemGroup(placement: .bottomBar) {
Spacer()
Button(action: self.updateStatus) {
Label("Refresh", systemImage: "arrow.clockwise")
}
}
#endif
}
private func sidebarRow(at i: Int) -> some View {