33 lines
751 B
Swift
33 lines
751 B
Swift
|
import Combine
|
||
|
import Foundation
|
||
|
import GRDB
|
||
|
import Photos
|
||
|
import SwiftUI
|
||
|
|
||
|
@MainActor
|
||
|
final class GlobalSettingsStore: ObservableObject {
|
||
|
static let shared = GlobalSettingsStore()
|
||
|
|
||
|
@Published var credentials: [Credentials] = []
|
||
|
|
||
|
private var credentialsCancellable: AnyCancellable?
|
||
|
|
||
|
init() {
|
||
|
subscribe()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private extension GlobalSettingsStore {
|
||
|
func subscribe() {
|
||
|
credentialsCancellable = ValueObservation.tracking(Credentials
|
||
|
.fetchAll
|
||
|
)
|
||
|
.publisher(in: Database.shared.dbQueue, scheduling: .immediate)
|
||
|
.receive(on: DispatchQueue.main)
|
||
|
.sink { _ in
|
||
|
} receiveValue: { [weak self] credentials in
|
||
|
self?.credentials = credentials
|
||
|
}
|
||
|
}
|
||
|
}
|