mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-29 03:31:02 +00:00
43 lines
1.3 KiB
Swift
43 lines
1.3 KiB
Swift
import AppAccount
|
|
import AppIntents
|
|
import Env
|
|
import Foundation
|
|
import Models
|
|
import Network
|
|
|
|
extension IntentDescription: @unchecked Sendable {}
|
|
extension TypeDisplayRepresentation: @unchecked Sendable {}
|
|
|
|
public struct AppAccountEntity: Identifiable, AppEntity {
|
|
public var id: String { account.id }
|
|
|
|
public let account: AppAccount
|
|
|
|
public static let defaultQuery = DefaultAppAccountEntityQuery()
|
|
|
|
public static let typeDisplayRepresentation: TypeDisplayRepresentation = "AppAccount"
|
|
|
|
public var displayRepresentation: DisplayRepresentation {
|
|
DisplayRepresentation(title: "\(account.accountName ?? account.server)")
|
|
}
|
|
}
|
|
|
|
public struct DefaultAppAccountEntityQuery: EntityQuery {
|
|
public init() {}
|
|
|
|
public func entities(for identifiers: [AppAccountEntity.ID]) async throws -> [AppAccountEntity] {
|
|
return await AppAccountsManager.shared.availableAccounts.filter { account in
|
|
identifiers.contains { id in
|
|
id == account.id
|
|
}
|
|
}.map { AppAccountEntity(account: $0) }
|
|
}
|
|
|
|
public func suggestedEntities() async throws -> [AppAccountEntity] {
|
|
await AppAccountsManager.shared.availableAccounts.map { .init(account: $0) }
|
|
}
|
|
|
|
public func defaultResult() async -> AppAccountEntity? {
|
|
await .init(account: AppAccountsManager.shared.currentAccount)
|
|
}
|
|
}
|