| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import SwiftUI
- extension Settings {
- final class StateModel: BaseStateModel<Provider> {
- @Injected() private var broadcaster: Broadcaster!
- @Injected() private var fileManager: FileManager!
- @Injected() private var nightscoutManager: NightscoutManager!
- @Published var closedLoop = false
- @Published var debugOptions = false
- @Published var animatedBackground = false
- private(set) var buildNumber = ""
- private(set) var versionNumber = ""
- private(set) var branch = ""
- private(set) var copyrightNotice = ""
- override func subscribe() {
- subscribeSetting(\.debugOptions, on: $debugOptions) { debugOptions = $0 }
- subscribeSetting(\.closedLoop, on: $closedLoop) { closedLoop = $0 }
- broadcaster.register(SettingsObserver.self, observer: self)
- buildNumber = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "Unknown"
- versionNumber = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "Unknown"
- branch = Bundle.main.infoDictionary?["BuildBranch"] as? String ?? "Unknown"
- copyrightNotice = Bundle.main.infoDictionary?["NSHumanReadableCopyright"] as? String ?? ""
- subscribeSetting(\.animatedBackground, on: $animatedBackground) { animatedBackground = $0 }
- }
- func logItems() -> [URL] {
- var items: [URL] = []
- if fileManager.fileExists(atPath: SimpleLogReporter.logFile) {
- items.append(URL(fileURLWithPath: SimpleLogReporter.logFile))
- }
- if fileManager.fileExists(atPath: SimpleLogReporter.logFilePrev) {
- items.append(URL(fileURLWithPath: SimpleLogReporter.logFilePrev))
- }
- return items
- }
- func uploadProfileAndSettings(_ force: Bool) {
- NSLog("SettingsState Upload Profile and Settings")
- nightscoutManager.uploadProfileAndSettings(force)
- }
- func hideSettingsModal() {
- hideModal()
- }
- }
- }
- extension Settings.StateModel: SettingsObserver {
- func settingsDidChange(_ settings: FreeAPSSettings) {
- closedLoop = settings.closedLoop
- debugOptions = settings.debugOptions
- }
- }
|