Switch to private account on selecting to not use public location (#212)

This commit is contained in:
Arkadiusz Fal 2022-07-03 22:39:10 +02:00
parent 02a27b4f95
commit 9cb6ff64ff
4 changed files with 13 additions and 8 deletions

View File

@ -54,6 +54,15 @@ final class AccountsModel: ObservableObject {
) )
} }
func configureAccount() {
if let account = lastUsed ??
InstancesModel.lastUsed?.anonymousAccount ??
InstancesModel.all.first?.anonymousAccount
{
setCurrent(account)
}
}
func setCurrent(_ account: Account! = nil) { func setCurrent(_ account: Account! = nil) {
guard account != current else { guard account != current else {
return return

View File

@ -14,7 +14,7 @@ final class InstancesModel: ObservableObject {
return InstancesModel.find(id) return InstancesModel.find(id)
} }
var lastUsed: Instance? { static var lastUsed: Instance? {
guard let id = Defaults[.lastInstanceID] else { guard let id = Defaults[.lastInstanceID] else {
return nil return nil
} }

View File

@ -31,7 +31,7 @@ final class InstancesManifest: Service, ObservableObject {
guard let country = country else { guard let country = country else {
accounts.publicAccount = nil accounts.publicAccount = nil
if asCurrent { if asCurrent {
accounts.setCurrent(nil) accounts.configureAccount()
} }
return return
} }

View File

@ -174,12 +174,8 @@ struct YatteeApp: App {
} }
#endif #endif
if Defaults[.lastAccountID] != "public", if Defaults[.lastAccountID] != "public" {
let account = accounts.lastUsed ?? accounts.configureAccount()
instances.lastUsed?.anonymousAccount ??
InstancesModel.all.first?.anonymousAccount
{
accounts.setCurrent(account)
} }
let countryOfPublicInstances = Defaults[.countryOfPublicInstances] let countryOfPublicInstances = Defaults[.countryOfPublicInstances]