Fix setting account

This commit is contained in:
Arkadiusz Fal 2021-09-28 23:47:48 +02:00
parent 78a0291e5d
commit d061664570
3 changed files with 7 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import Foundation
struct Instance: Defaults.Serializable, Hashable, Identifiable {
struct Account: Defaults.Serializable, Hashable, Identifiable {
static var bridge = AccountsBridge()
static var empty = Account(instanceID: UUID(), name: "Signed Out", url: "", sid: "")
let id: UUID
let instanceID: UUID
@ -36,6 +37,10 @@ struct Instance: Defaults.Serializable, Hashable, Identifiable {
(name != nil && name!.isEmpty) ? "Unnamed (\(anonymizedSID))" : name!
}
var isEmpty: Bool {
self == Account.empty
}
func hash(into hasher: inout Hasher) {
hasher.combine(sid)
}

View File

@ -6,7 +6,7 @@ import SwiftyJSON
final class InvidiousAPI: Service, ObservableObject {
static let basePath = "/api/v1"
@Published var account: Instance.Account!
@Published var account: Instance.Account! = .empty
@Published var validInstance = true
@Published var signedIn = true

View File

@ -40,7 +40,7 @@ struct PearvidiousApp: App {
search.api = api
subscriptions.api = api
if let account = instances.defaultAccount, api.account.isNil {
if let account = instances.defaultAccount, api.account.isEmpty {
api.setAccount(account)
}
}