Put the account switcher where the data is, and retire the old setting

Switching accounts was buried in Subscriptions settings behind a picker
and a confirmation dialog, and it wrote two stores that could disagree.
One shared switcher now sits in the Subscriptions and Playlists
toolbars, the macOS sidebar footer and the Settings root, and every path
goes through AppEnvironment.switchDataContext(to:) so a switch behaves
the same wherever it is made. Switching is one tap: it is reversible, so
there is nothing to confirm.

Rows come from DataContextValidator.availableContexts, name themselves
through displayName(for:), and carry a status suffix when the account is
not signed in — plus the instance host when two accounts share a name.
tvOS gets the same rows as a full-screen picker.

Subscriptions also explains itself when the selected account cannot
answer: a thin banner names the cause and says the data below is local.
This is the first consumer of the validator's unavailability, and
correctIfContextRemoved() now runs on foreground activation, where
SubscriptionAccountValidator used to auto-correct any selection it could
not immediately verify.

With the switcher reading the context directly, the legacy
subscriptionAccount setting has no readers left: the setting, its
validator, the mirror that kept it in step and the feed cache's
instance-keyed fallbacks all go. The cache invalidation the mirror also
carried stays, under its own name. AccountsManager still reads the raw
legacy key for the one-way context migration.
This commit is contained in:
Arkadiusz Fal
2026-09-03 23:59:32 +02:00
parent afc016c5ce
commit 175b98097a
14 changed files with 525 additions and 576 deletions

View File

@@ -324,6 +324,15 @@ struct SubscriptionsView: View {
return progress > 0 && progress < 1 ? progress : nil
}
/// Why the selected account is not the one answering, when it is not.
///
/// Only for an account context: local data is never unavailable, and the
/// fallback the banner explains is local data itself.
private var contextUnavailability: DataContextUnavailability? {
guard appEnvironment?.accountsManager.currentContext.isLocal == false else { return nil }
return appEnvironment?.dataContextValidator.unavailability
}
/// View options button lives on the leading edge on macOS, trailing elsewhere.
private var viewOptionsPlacement: ToolbarItemPlacement {
#if os(macOS)
@@ -430,6 +439,13 @@ struct SubscriptionsView: View {
}
#endif
}
// Above the feed rather than inside it: the feed is local data
// while this is showing, and nothing else on screen says so.
.safeAreaInset(edge: .top, spacing: 0) {
if let unavailability = contextUnavailability {
DataContextUnavailableBanner(reason: unavailability)
}
}
#if !os(tvOS)
.navigationTitle(String(localized: "tabs.subscriptions"))
#if os(iOS)
@@ -438,6 +454,9 @@ struct SubscriptionsView: View {
.toolbarTitleDisplayMode(.inlineLarge)
#endif
.toolbar {
ToolbarItem(placement: viewOptionsPlacement) {
DataContextSwitcherMenu()
}
ToolbarItem(placement: viewOptionsPlacement) {
Button {
showViewOptions = true
@@ -812,12 +831,16 @@ struct SubscriptionsView: View {
#if os(tvOS)
private var tvOSViewOptionsButton: some View {
Button {
showViewOptions = true
} label: {
Label(String(localized: "viewOptions.title"), systemImage: "slider.horizontal.3")
HStack(spacing: 16) {
Button {
showViewOptions = true
} label: {
Label(String(localized: "viewOptions.title"), systemImage: "slider.horizontal.3")
}
.buttonStyle(.bordered)
DataContextSwitcherButton()
}
.buttonStyle(.bordered)
}
private var tvOSChannelsSidebar: some View {