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) {
guard account != current else {
return

View File

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

View File

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

View File

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