another.im-ios/ConversationsClassic/AppData/Store/GlobalSettingsStore.swift
2024-10-15 13:39:23 +02:00

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
}
}
}