Fix publishing changes during view updates warning
Defer state mutations in .onReceive handlers to next run loop
by wrapping them in Task { @MainActor in ... }
This commit is contained in:
@@ -155,19 +155,23 @@ import SwiftUI
|
|||||||
}
|
}
|
||||||
#if os(iOS) || os(tvOS)
|
#if os(iOS) || os(tvOS)
|
||||||
.onReceive(environments.commandClient.$groups) { _ in
|
.onReceive(environments.commandClient.$groups) { _ in
|
||||||
updateButtonVisibility()
|
Task { @MainActor in
|
||||||
#if os(iOS)
|
updateButtonVisibility()
|
||||||
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
|
#if os(iOS)
|
||||||
coordinator.selection = .overview
|
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
|
||||||
}
|
coordinator.selection = .overview
|
||||||
#endif
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}.onReceive(profile.$status) { _ in
|
}.onReceive(profile.$status) { _ in
|
||||||
updateButtonVisibility()
|
Task { @MainActor in
|
||||||
#if os(iOS)
|
updateButtonVisibility()
|
||||||
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
|
#if os(iOS)
|
||||||
coordinator.selection = .overview
|
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
|
||||||
}
|
coordinator.selection = .overview
|
||||||
#endif
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}.onAppear {
|
}.onAppear {
|
||||||
updateButtonVisibility()
|
updateButtonVisibility()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,13 +77,15 @@ public struct MainView: View {
|
|||||||
}
|
}
|
||||||
.onReceive(NotificationCenter.default.publisher(for: .navigateToSettingsPage)) { notification in
|
.onReceive(NotificationCenter.default.publisher(for: .navigateToSettingsPage)) { notification in
|
||||||
guard let page = notification.object as? SettingsPage else { return }
|
guard let page = notification.object as? SettingsPage else { return }
|
||||||
pendingSettingsPage = page
|
Task { @MainActor in
|
||||||
if viewModel.selection == .settings {
|
pendingSettingsPage = page
|
||||||
settingsNavigationPath = NavigationPath()
|
if viewModel.selection == .settings {
|
||||||
settingsNavigationPath.append(page)
|
settingsNavigationPath = NavigationPath()
|
||||||
pendingSettingsPage = nil
|
settingsNavigationPath.append(page)
|
||||||
} else {
|
pendingSettingsPage = nil
|
||||||
viewModel.selection = .settings
|
} else {
|
||||||
|
viewModel.selection = .settings
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.environment(\.selection, $viewModel.selection)
|
.environment(\.selection, $viewModel.selection)
|
||||||
|
|||||||
+6
-6
@@ -92,22 +92,22 @@ struct MainView: View {
|
|||||||
updateButtonVisibility()
|
updateButtonVisibility()
|
||||||
}
|
}
|
||||||
.onReceive(environments.commandClient.$groups) { _ in
|
.onReceive(environments.commandClient.$groups) { _ in
|
||||||
updateButtonVisibility()
|
Task { @MainActor in updateButtonVisibility() }
|
||||||
}
|
}
|
||||||
.onReceive(environments.commandClient.$connections) { _ in
|
.onReceive(environments.commandClient.$connections) { _ in
|
||||||
updateButtonVisibility()
|
Task { @MainActor in updateButtonVisibility() }
|
||||||
}
|
}
|
||||||
.onReceive(environments.commandClient.$hasAnyConnection) { _ in
|
.onReceive(environments.commandClient.$hasAnyConnection) { _ in
|
||||||
updateButtonVisibility()
|
Task { @MainActor in updateButtonVisibility() }
|
||||||
}
|
}
|
||||||
.onReceive(NotificationCenter.default.publisher(for: .NEVPNStatusDidChange)) { _ in
|
.onReceive(NotificationCenter.default.publisher(for: .NEVPNStatusDidChange)) { _ in
|
||||||
updateButtonVisibility()
|
Task { @MainActor in updateButtonVisibility() }
|
||||||
}
|
}
|
||||||
.onReceive(environments.$extensionProfile) { _ in
|
.onReceive(environments.$extensionProfile) { _ in
|
||||||
updateButtonVisibility()
|
Task { @MainActor in updateButtonVisibility() }
|
||||||
}
|
}
|
||||||
.onReceive(environments.$emptyProfiles) { _ in
|
.onReceive(environments.$emptyProfiles) { _ in
|
||||||
updateButtonVisibility()
|
Task { @MainActor in updateButtonVisibility() }
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $showGroups) {
|
.sheet(isPresented: $showGroups) {
|
||||||
GroupsSheetContent()
|
GroupsSheetContent()
|
||||||
|
|||||||
Reference in New Issue
Block a user