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

@@ -373,37 +373,18 @@ final class SubscriptionFeedCache {
}
/// Gets the authenticated Invidious instance and session ID.
///
/// Resolved through the selected account and nothing else: a second login on
/// the same instance has its own credential, and the instance-keyed lookup
/// this used to fall back to cannot tell the two apart.
private func getInvidiousAuth(using appEnvironment: AppEnvironment) -> (Instance, String)? {
// Resolve through the selected account so a second login on the same
// instance uses its own credential.
if let account = appEnvironment.account(forSelectedContext: .invidious),
let instance = appEnvironment.accountsManager.instance(for: account),
let sid = appEnvironment.accountCredentialsManager(for: account)?.credential(for: account) {
return (instance, sid)
}
let legacyAccount = appEnvironment.settingsManager.subscriptionAccount
let instance: Instance?
if let instanceID = legacyAccount.instanceID {
instance = appEnvironment.instancesManager.instances.first { $0.id == instanceID }
} else {
// Fall back to first enabled Invidious instance
instance = appEnvironment.instancesManager.instances.first {
$0.type == .invidious && $0.isEnabled
}
}
guard let instance else {
LoggingService.shared.debug("No Invidious instance found for subscription account", category: .general)
guard let account = appEnvironment.account(forSelectedContext: .invidious),
let instance = appEnvironment.accountsManager.instance(for: account),
let sid = appEnvironment.accountCredentialsManager(for: account)?.credential(for: account) else {
LoggingService.shared.debug("No Invidious account resolved for the selected context", category: .general)
return nil
}
guard let sid = appEnvironment.credential(forInstance: instance) else {
LoggingService.shared.debug("No session ID found for Invidious instance: \(instance.id)", category: .general)
return nil
}
return (instance, sid)
}
@@ -451,22 +432,14 @@ final class SubscriptionFeedCache {
/// Gets the authenticated Piped instance and auth token.
private func getPipedAuth(using appEnvironment: AppEnvironment) -> (Instance, String)? {
if let account = appEnvironment.account(forSelectedContext: .piped),
let instance = appEnvironment.accountsManager.instance(for: account),
let token = appEnvironment.accountCredentialsManager(for: account)?.credential(for: account) {
return (instance, token)
}
let legacyAccount = appEnvironment.settingsManager.subscriptionAccount
guard let instanceID = legacyAccount.instanceID,
let instance = appEnvironment.instancesManager.instances.first(where: { $0.id == instanceID }),
let authToken = appEnvironment.credential(forInstance: instance) else {
LoggingService.shared.debug("No authenticated Piped instance found for subscription account", category: .general)
guard let account = appEnvironment.account(forSelectedContext: .piped),
let instance = appEnvironment.accountsManager.instance(for: account),
let token = appEnvironment.accountCredentialsManager(for: account)?.credential(for: account) else {
LoggingService.shared.debug("No Piped account resolved for the selected context", category: .general)
return nil
}
return (instance, authToken)
return (instance, token)
}
// MARK: - Invidious Feed