mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Save last used account instead of having to set default
This commit is contained in:
@@ -4,24 +4,29 @@ import SwiftUI
|
||||
struct AccountsMenuView: View {
|
||||
@EnvironmentObject<AccountsModel> private var model
|
||||
|
||||
@Default(.accounts) private var accounts
|
||||
@Default(.instances) private var instances
|
||||
|
||||
var body: some View {
|
||||
Menu {
|
||||
ForEach(model.all, id: \.id) { account in
|
||||
ForEach(allAccounts, id: \.id) { account in
|
||||
Button(accountButtonTitle(account: account)) {
|
||||
model.setAccount(account)
|
||||
model.setCurrent(account)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Label(model.account?.name ?? "Select Account", systemImage: "person.crop.circle")
|
||||
Label(model.current?.name ?? "Select Account", systemImage: "person.crop.circle")
|
||||
.labelStyle(.titleAndIcon)
|
||||
}
|
||||
.disabled(instances.isEmpty)
|
||||
.transaction { t in t.animation = .none }
|
||||
}
|
||||
|
||||
func accountButtonTitle(account: Instance.Account) -> String {
|
||||
private var allAccounts: [Instance.Account] {
|
||||
accounts + instances.map(\.anonymousAccount)
|
||||
}
|
||||
|
||||
private func accountButtonTitle(account: Instance.Account) -> String {
|
||||
instances.count > 1 ? "\(account.description) — \(account.instance.description)" : account.description
|
||||
}
|
||||
}
|
||||
|
@@ -62,8 +62,8 @@ struct AppSidebarNavigation: View {
|
||||
.help(
|
||||
"Switch Instances and Accounts\n" +
|
||||
"Current Instance: \n" +
|
||||
"\(accounts.account?.url ?? "Not Set")\n" +
|
||||
"Current User: \(accounts.account?.description ?? "Not set")"
|
||||
"\(accounts.current?.url ?? "Not Set")\n" +
|
||||
"Current User: \(accounts.current?.description ?? "Not set")"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@@ -85,15 +85,17 @@ struct ContentView: View {
|
||||
SiestaLog.Category.enabled = .common
|
||||
|
||||
// TODO: Remove when piped supports videos information
|
||||
if let account = instances.defaultAccount ??
|
||||
accounts.all.first(where: { $0.instance.app == .invidious })
|
||||
if let account = accounts.lastUsed ??
|
||||
instances.lastUsed?.anonymousAccount ??
|
||||
instances.all.first?.anonymousAccount
|
||||
{
|
||||
accounts.setAccount(account)
|
||||
accounts.setCurrent(account)
|
||||
}
|
||||
|
||||
if accounts.account.isNil {
|
||||
if accounts.current.isNil {
|
||||
navigation.presentingWelcomeScreen = true
|
||||
}
|
||||
|
||||
player.accounts = accounts
|
||||
playlists.accounts = accounts
|
||||
search.accounts = accounts
|
||||
@@ -101,7 +103,7 @@ struct ContentView: View {
|
||||
}
|
||||
|
||||
func openWelcomeScreenIfAccountEmpty() {
|
||||
guard accounts.isEmpty else {
|
||||
guard Defaults[.instances].isEmpty else {
|
||||
return
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user