Ivan Valkou 5 роки тому
батько
коміт
baf1ff2c51

+ 2 - 1
FreeAPS/Resources/json/defaults/freeaps/freeaps_settings.json

@@ -5,5 +5,6 @@
     "useAutotune": false
     "isUploadEnabled": true,
     "useLocalGlucoseSource": false,
-    "localGlucosePort": 8080
+    "localGlucosePort": 8080,
+    "debugOptions": false
 }

+ 1 - 1
FreeAPS/Sources/APS/APSManager.swift

@@ -83,7 +83,7 @@ final class BaseAPSManager: APSManager, Injectable {
     }
 
     private func fetchAndLoop() {
-        if settings.allowAnnouncements {
+        if settings.allowAnnouncements ?? false {
             nightscout.fetchAnnouncements()
                 .sink { [weak self] in
                     guard let self = self else { return }

+ 0 - 1
FreeAPS/Sources/Logger/Logger.swift

@@ -266,7 +266,6 @@ final class Logger {
     }
 
     private func showAlert(_ message: String) {
-//        let category = self.category
         DispatchQueue.main.async {
             router.alertMessage.send(message)
         }

+ 1 - 0
FreeAPS/Sources/Models/FreeAPSSettings.swift

@@ -8,4 +8,5 @@ struct FreeAPSSettings: JSON {
     var isUploadEnabled: Bool?
     var useLocalGlucoseSource: Bool?
     var localGlucosePort: Int?
+    var debugOptions: Bool?
 }

+ 4 - 0
FreeAPS/Sources/Modules/ConfigEditor/ConfigEditorProvider.swift

@@ -11,6 +11,10 @@ extension ConfigEditor {
         }
 
         func save(_ value: RawJSON, as file: String) {
+            guard let data = value.data(using: .utf8), (try? JSONSerialization.jsonObject(with: data, options: [])) != nil else {
+                warning(.service, "Invalid JSON")
+                return
+            }
             storage.save(value, as: file)
         }
     }

+ 1 - 1
FreeAPS/Sources/Modules/ConfigEditor/ConfigEditorViewModel.swift

@@ -12,7 +12,7 @@ extension ConfigEditor {
         }
 
         required init(provider _: Provider, resolver _: Resolver) {
-            fatalError("init(provider:resolver:) has not been implemented")
+            error(.default, "init(provider:resolver:) has not been implemented")
         }
 
         override func subscribe() {

+ 6 - 6
FreeAPS/Sources/Modules/PreferencesEditor/PreferencesEditorViewModel.swift

@@ -100,12 +100,12 @@ extension PreferencesEditor {
                     value: preferences.enableUAM,
                     settable: self
                 ),
-                Field(
-                    displayName: "A52 Risk Enable",
-                    keypath: \.a52RiskEnable,
-                    value: preferences.a52RiskEnable,
-                    settable: self
-                ),
+//                Field(
+//                    displayName: "A52 Risk Enable",
+//                    keypath: \.a52RiskEnable,
+//                    value: preferences.a52RiskEnable,
+//                    settable: self
+//                ),
                 Field(
                     displayName: "Enable SMB With COB",
                     keypath: \.enableSMBWithCOB,

+ 5 - 0
FreeAPS/Sources/Modules/PreferencesEditor/View/PreferencesEditorRootView.swift

@@ -39,6 +39,11 @@ extension PreferencesEditor {
                         }
                     }
                 }
+
+                Section {
+                    Text("Edit settings json").chevronCell()
+                        .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
+                }
             }
             .navigationTitle("Preferences")
             .navigationBarTitleDisplayMode(.automatic)

+ 4 - 0
FreeAPS/Sources/Modules/Settings/SettingsViewModel.swift

@@ -6,8 +6,11 @@ extension Settings {
         @Injected() private var broadcaster: Broadcaster!
         @Published var closedLoop = false
 
+        @Published var debugOptions = false
+
         override func subscribe() {
             closedLoop = settingsManager.settings.closedLoop
+            debugOptions = settingsManager.settings.debugOptions ?? false
 
             $closedLoop
                 .removeDuplicates()
@@ -23,5 +26,6 @@ extension Settings {
 extension Settings.ViewModel: SettingsObserver {
     func settingsDidChange(_ settings: FreeAPSSettings) {
         closedLoop = settings.closedLoop
+        debugOptions = settings.debugOptions ?? false
     }
 }

+ 45 - 42
FreeAPS/Sources/Modules/Settings/View/SettingsRootView.swift

@@ -19,57 +19,60 @@ extension Settings {
                 }
 
                 Section(header: Text("Configuration")) {
+                    Text("Preferences").chevronCell().navigationLink(to: .preferencesEditor, from: self)
                     Text("Pump Settings").chevronCell().navigationLink(to: .pumpSettingsEditor, from: self)
                     Text("Basal Profile").chevronCell().navigationLink(to: .basalProfileEditor, from: self)
                     Text("Insulin Sensitivities").chevronCell().navigationLink(to: .isfEditor, from: self)
                     Text("Carb Ratios").chevronCell().navigationLink(to: .crEditor, from: self)
                     Text("Target Ranges").chevronCell().navigationLink(to: .targetsEditor, from: self)
-                    Text("Preferences").chevronCell().navigationLink(to: .preferencesEditor, from: self)
                     Text("Autotune").chevronCell().navigationLink(to: .autotuneConfig, from: self)
                 }
 
-                Section(header: Text("Config files")) {
-                    Group {
-                        Text("Preferences").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
-                        Text("Pump Settings").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
-                        Text("Autosense").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
-                        Text("Pump History").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
-                        Text("Basal profile").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
-                        Text("Targets ranges").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
-                        Text("Carb ratios").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.carbRatios), from: self)
-                        Text("Insulin sensitivities").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.insulinSensitivities), from: self)
-                        Text("Temp targets").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
-                    }
+                if viewModel.debugOptions {
+                    Section(header: Text("Config files")) {
+                        Group {
+                            Text("Preferences").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
+                            Text("Pump Settings").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
+                            Text("Autosense").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
+                            Text("Pump History").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
+                            Text("Basal profile").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
+                            Text("Targets ranges").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
+                            Text("Carb ratios").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.carbRatios), from: self)
+                            Text("Insulin sensitivities").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.insulinSensitivities), from: self)
+                            Text("Temp targets").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
+                        }
 
-                    Group {
-                        Text("IOB").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Monitor.iob), from: self)
-                        Text("Pump profile").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
-                        Text("Profile").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
-                        Text("Glucose").chevronCell().navigationLink(to: .configEditor(file: OpenAPS.Monitor.glucose), from: self)
-                        Text("Carbs").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
-                        Text("Suggested").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Enact.suggested), from: self)
-                        Text("Enacted").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Enact.enacted), from: self)
-                        Text("Announcements").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
-                        Text("Enacted announcements").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
-                        Text("Autotune").chevronCell()
-                            .navigationLink(to: .configEditor(file: OpenAPS.Settings.autotune), from: self)
+                        Group {
+                            Text("IOB").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Monitor.iob), from: self)
+                            Text("Pump profile").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
+                            Text("Profile").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
+                            Text("Glucose").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Monitor.glucose), from: self)
+                            Text("Carbs").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
+                            Text("Suggested").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Enact.suggested), from: self)
+                            Text("Enacted").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Enact.enacted), from: self)
+                            Text("Announcements").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
+                            Text("Enacted announcements").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
+                            Text("Autotune").chevronCell()
+                                .navigationLink(to: .configEditor(file: OpenAPS.Settings.autotune), from: self)
+                        }
                     }
                 }
             }

+ 3 - 3
FreeAPS/Sources/Services/SettingsManager/SettingsManager.swift

@@ -12,6 +12,8 @@ protocol SettingsObserver {
 
 final class BaseSettingsManager: SettingsManager, Injectable {
     @Injected() var broadcaster: Broadcaster!
+    @Injected() var storage: FileStorage!
+
     var settings: FreeAPSSettings {
         didSet {
             save()
@@ -23,13 +25,11 @@ final class BaseSettingsManager: SettingsManager, Injectable {
         }
     }
 
-    @Injected() var storage: FileStorage!
-
     init(resolver: Resolver) {
         let storage = resolver.resolve(FileStorage.self)!
         settings = storage.retrieve(OpenAPS.FreeAPS.settings, as: FreeAPSSettings.self)
             ?? FreeAPSSettings(from: OpenAPS.defaults(for: OpenAPS.FreeAPS.settings))
-            ?? FreeAPSSettings(units: .mmolL, closedLoop: false, allowAnnouncements: false, useAutotune: false)
+            ?? FreeAPSSettings(units: .mmolL, closedLoop: false, allowAnnouncements: false, useAutotune: true, isUploadEnabled: true, useLocalGlucoseSource: false, localGlucosePort: nil, debugOptions: false)
 
         injectServices(resolver)
     }