Przeglądaj źródła

Introducing debug logging, implemented advanced settings as SwiftUI

Jonas Björkert 1 rok temu
rodzic
commit
5b670f7001

+ 16 - 4
LoopFollow.xcodeproj/project.pbxproj

@@ -24,6 +24,8 @@
 		DD16AF0D2C98485400FB655A /* SecureStorageValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD16AF0C2C98485400FB655A /* SecureStorageValue.swift */; };
 		DD16AF0F2C99592F00FB655A /* HKQuantityInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD16AF0E2C99592F00FB655A /* HKQuantityInputView.swift */; };
 		DD16AF112C997B4600FB655A /* LoadingButtonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD16AF102C997B4600FB655A /* LoadingButtonView.swift */; };
+		DD1A97142D4294A5000DDC11 /* AdvancedSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD1A97132D4294A4000DDC11 /* AdvancedSettingsView.swift */; };
+		DD1A97162D4294B3000DDC11 /* AdvancedSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD1A97152D4294B2000DDC11 /* AdvancedSettingsViewModel.swift */; };
 		DD2C2E4F2D3B8AF1006413A5 /* NightscoutSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2C2E4E2D3B8AEC006413A5 /* NightscoutSettingsView.swift */; };
 		DD2C2E512D3B8B0C006413A5 /* NightscoutSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2C2E502D3B8B0B006413A5 /* NightscoutSettingsViewModel.swift */; };
 		DD2C2E542D3C37DC006413A5 /* DexcomSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD2C2E532D3C37D7006413A5 /* DexcomSettingsViewModel.swift */; };
@@ -94,7 +96,6 @@
 		DDCF979624C1443C002C9752 /* GeneralSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCF979524C1443C002C9752 /* GeneralSettingsViewController.swift */; };
 		DDCF979824C1489C002C9752 /* GraphSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCF979724C1489C002C9752 /* GraphSettingsViewController.swift */; };
 		DDCF979A24C14DB4002C9752 /* WatchSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCF979924C14DB4002C9752 /* WatchSettingsViewController.swift */; };
-		DDCF979C24C14EFB002C9752 /* AdvancedSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCF979B24C14EFB002C9752 /* AdvancedSettingsViewController.swift */; };
 		DDCF979E24C2382A002C9752 /* AppStateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDCF979D24C2382A002C9752 /* AppStateController.swift */; };
 		DDCFCAF22B17273200BE5751 /* LoopFollowDisplayNameConfig.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = DDCFCAF12B17273200BE5751 /* LoopFollowDisplayNameConfig.xcconfig */; };
 		DDD10EFF2C510C3C00D76A8E /* ObservableUserDefaultsValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDD10EFE2C510C3C00D76A8E /* ObservableUserDefaultsValue.swift */; };
@@ -294,6 +295,8 @@
 		DD16AF0C2C98485400FB655A /* SecureStorageValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecureStorageValue.swift; sourceTree = "<group>"; };
 		DD16AF0E2C99592F00FB655A /* HKQuantityInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HKQuantityInputView.swift; sourceTree = "<group>"; };
 		DD16AF102C997B4600FB655A /* LoadingButtonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingButtonView.swift; sourceTree = "<group>"; };
+		DD1A97132D4294A4000DDC11 /* AdvancedSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsView.swift; sourceTree = "<group>"; };
+		DD1A97152D4294B2000DDC11 /* AdvancedSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsViewModel.swift; sourceTree = "<group>"; };
 		DD2C2E4E2D3B8AEC006413A5 /* NightscoutSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NightscoutSettingsView.swift; sourceTree = "<group>"; };
 		DD2C2E502D3B8B0B006413A5 /* NightscoutSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NightscoutSettingsViewModel.swift; sourceTree = "<group>"; };
 		DD2C2E532D3C37D7006413A5 /* DexcomSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DexcomSettingsViewModel.swift; sourceTree = "<group>"; };
@@ -364,7 +367,6 @@
 		DDCF979524C1443C002C9752 /* GeneralSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralSettingsViewController.swift; sourceTree = "<group>"; };
 		DDCF979724C1489C002C9752 /* GraphSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphSettingsViewController.swift; sourceTree = "<group>"; };
 		DDCF979924C14DB4002C9752 /* WatchSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchSettingsViewController.swift; sourceTree = "<group>"; };
-		DDCF979B24C14EFB002C9752 /* AdvancedSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdvancedSettingsViewController.swift; sourceTree = "<group>"; };
 		DDCF979D24C2382A002C9752 /* AppStateController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStateController.swift; sourceTree = "<group>"; };
 		DDCFCAF12B17273200BE5751 /* LoopFollowDisplayNameConfig.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = LoopFollowDisplayNameConfig.xcconfig; sourceTree = "<group>"; };
 		DDD10EFE2C510C3C00D76A8E /* ObservableUserDefaultsValue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservableUserDefaultsValue.swift; sourceTree = "<group>"; };
@@ -623,6 +625,15 @@
 			path = InfoTable;
 			sourceTree = "<group>";
 		};
+		DD1A97122D429495000DDC11 /* Settings */ = {
+			isa = PBXGroup;
+			children = (
+				DD1A97152D4294B2000DDC11 /* AdvancedSettingsViewModel.swift */,
+				DD1A97132D4294A4000DDC11 /* AdvancedSettingsView.swift */,
+			);
+			path = Settings;
+			sourceTree = "<group>";
+		};
 		DD2C2E4D2D3B8ACF006413A5 /* Nightscout */ = {
 			isa = PBXGroup;
 			children = (
@@ -991,6 +1002,7 @@
 		FC8DEEE32485D1680075863F /* LoopFollow */ = {
 			isa = PBXGroup;
 			children = (
+				DD1A97122D429495000DDC11 /* Settings */,
 				DD2C2E522D3C36A8006413A5 /* Dexcom */,
 				DD2C2E4D2D3B8ACF006413A5 /* Nightscout */,
 				DD9ED0C62D355225000D2A63 /* Log */,
@@ -1093,7 +1105,6 @@
 				DDCF979524C1443C002C9752 /* GeneralSettingsViewController.swift */,
 				DDCF979724C1489C002C9752 /* GraphSettingsViewController.swift */,
 				DDCF979924C14DB4002C9752 /* WatchSettingsViewController.swift */,
-				DDCF979B24C14EFB002C9752 /* AdvancedSettingsViewController.swift */,
 			);
 			path = ViewControllers;
 			sourceTree = "<group>";
@@ -1432,8 +1443,8 @@
 				DDF9676E2AD08C6E00C5EB95 /* SiteChange.swift in Sources */,
 				DD13BC772C3FD64E0062313B /* InfoData.swift in Sources */,
 				DD13BC752C3FD6210062313B /* InfoType.swift in Sources */,
+				DD1A97142D4294A5000DDC11 /* AdvancedSettingsView.swift in Sources */,
 				DD9ACA0A2D33095600415D8A /* MinAgoTask.swift in Sources */,
-				DDCF979C24C14EFB002C9752 /* AdvancedSettingsViewController.swift in Sources */,
 				DD9ED0CC2D35526E000D2A63 /* SearchBar.swift in Sources */,
 				DDD10EFF2C510C3C00D76A8E /* ObservableUserDefaultsValue.swift in Sources */,
 				DD58171A2D299EF80041FB98 /* DexcomHeartbeatBluetoothDevice.swift in Sources */,
@@ -1490,6 +1501,7 @@
 				DDD10F012C510C6B00D76A8E /* ObservableUserDefaults.swift in Sources */,
 				DD16AF0D2C98485400FB655A /* SecureStorageValue.swift in Sources */,
 				DD2C2E4F2D3B8AF1006413A5 /* NightscoutSettingsView.swift in Sources */,
+				DD1A97162D4294B3000DDC11 /* AdvancedSettingsViewModel.swift in Sources */,
 				FCA2DDE62501095000254A8C /* Timers.swift in Sources */,
 				DD2C2E512D3B8B0C006413A5 /* NightscoutSettingsViewModel.swift in Sources */,
 				DD9ED0C82D355244000D2A63 /* LogViewModel.swift in Sources */,

+ 2 - 2
LoopFollow/BackgroundRefresh/BT/BLEManager.swift

@@ -164,7 +164,7 @@ extension BLEManager: CBCentralManagerDelegate {
 
 extension BLEManager: BluetoothDeviceDelegate {
     func didConnectTo(bluetoothDevice: BluetoothDevice) {
-        LogManager.shared.log(category: .bluetooth, message: "Connected to: \(bluetoothDevice.deviceName ?? "Unknown")")
+        LogManager.shared.log(category: .bluetooth, message: "Connected to: \(bluetoothDevice.deviceName ?? "Unknown")", isDebug: true)
 
         findAndUpdateDevice(with: bluetoothDevice.deviceAddress) { device in
             device.isConnected = true
@@ -173,7 +173,7 @@ extension BLEManager: BluetoothDeviceDelegate {
     }
 
     func didDisconnectFrom(bluetoothDevice: BluetoothDevice) {
-        LogManager.shared.log(category: .bluetooth, message: "Disconnect from: \(bluetoothDevice.deviceName ?? "Unknown")")
+        LogManager.shared.log(category: .bluetooth, message: "Disconnect from: \(bluetoothDevice.deviceName ?? "Unknown")", isDebug: true)
 
         findAndUpdateDevice(with: bluetoothDevice.deviceAddress) { device in
             device.isConnected = false

+ 1 - 3
LoopFollow/BackgroundRefresh/BT/BluetoothDevice.swift

@@ -223,9 +223,7 @@ class BluetoothDevice: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate
         timeStampLastStatusUpdate = Date()
 
         if central.state == .poweredOn {
-            if (deviceAddress != nil) {
-                _ = retrievePeripherals(central)
-            }
+            _ = retrievePeripherals(central)
         }
     }
 

+ 1 - 1
LoopFollow/Contact/ContactImageUpdater.swift

@@ -39,7 +39,7 @@ class ContactImageUpdater {
                     let saveRequest = CNSaveRequest()
                     saveRequest.update(mutableContact)
                     try self.contactStore.execute(saveRequest)
-                    LogManager.shared.log(category: .contact, message: "Contact image updated")
+                    LogManager.shared.log(category: .contact, message: "Contact image updated", isDebug: true)
                 } else {
                     let newContact = CNMutableContact()
                     newContact.givenName = contactName

+ 1 - 1
LoopFollow/Controllers/Alarms.swift

@@ -337,7 +337,7 @@ extension MainViewController {
         
         //check for not looping alert
         if IsNightscoutEnabled() {
-//            LogManager.shared.log(category: .alarm, message: "Checking NotLooping LastLoopTime was \(UserDefaultsRepository.alertLastLoopTime.value) that gives a diff of: \(Double(dateTimeUtils.getNowTimeIntervalUTC() - UserDefaultsRepository.alertLastLoopTime.value))")
+            LogManager.shared.log(category: .alarm, message: "Checking NotLooping LastLoopTime was \(UserDefaultsRepository.alertLastLoopTime.value) that gives a diff of: \(Double(dateTimeUtils.getNowTimeIntervalUTC() - UserDefaultsRepository.alertLastLoopTime.value))", isDebug: true)
             if UserDefaultsRepository.alertNotLoopingActive.value
                 && !UserDefaultsRepository.alertNotLoopingIsSnoozed.value
                 && (Double(dateTimeUtils.getNowTimeIntervalUTC() - UserDefaultsRepository.alertLastLoopTime.value) >= Double(UserDefaultsRepository.alertNotLooping.value * 60))

+ 1 - 1
LoopFollow/Controllers/Nightscout/BGData.swift

@@ -33,8 +33,8 @@ extension MainViewController {
             let latestDate = data[0].date
             let now = dateTimeUtils.getNowTimeIntervalUTC()
             if (latestDate + 330) < now && IsNightscoutEnabled() {
+                LogManager.shared.log(category: .dexcom, message: "Dexcom data is old, loading from NS instead")
                 self.webLoadNSBGData()
-                print("Dex data is old, loading from NS instead")
                 return
             }
             

+ 3 - 5
LoopFollow/Controllers/Nightscout/DeviceStatus.swift

@@ -32,11 +32,9 @@ extension MainViewController {
     }
     
     private func handleDeviceStatusError() {
+        LogManager.shared.log(category: .alarm, message: "Device status fetch failed!")
         DispatchQueue.main.async {
-            TaskScheduler.shared.rescheduleTask(
-                id: .deviceStatus,
-                to: Date().addingTimeInterval(10)
-            )
+            TaskScheduler.shared.rescheduleTask(id: .deviceStatus, to: Date().addingTimeInterval(10))
         }
     }
     
@@ -182,7 +180,7 @@ extension MainViewController {
                 )
             }
         }
-//        LogManager.shared.log(category: .alarm, message: "updateDeviceStatusDisplay done")
+        LogManager.shared.log(category: .alarm, message: "updateDeviceStatusDisplay done", isDebug: true)
 
     }
 }

+ 1 - 1
LoopFollow/Controllers/Nightscout/DeviceStatusOpenAPS.swift

@@ -33,7 +33,7 @@ extension MainViewController {
 
                 if wasEnacted {
                     UserDefaultsRepository.alertLastLoopTime.value = lastLoopTime
-//                    LogManager.shared.log(category: .alarm, message: "New LastLoopTime: \(lastLoopTime)")
+                    LogManager.shared.log(category: .alarm, message: "New LastLoopTime: \(lastLoopTime)", isDebug: true)
 
                     evaluateNotLooping(lastLoopTime: UserDefaultsRepository.alertLastLoopTime.value)
                 } else {

+ 2 - 2
LoopFollow/Helpers/BackgroundTaskAudio.swift

@@ -22,7 +22,7 @@ class BackgroundTask {
     func stopBackgroundTask() {
         NotificationCenter.default.removeObserver(self, name: AVAudioSession.interruptionNotification, object: nil)
         player.stop()
-        LogManager.shared.log(category: .general, message: "Silent audio stopped")
+        LogManager.shared.log(category: .general, message: "Silent audio stopped", isDebug: true)
     }
     
     @objc fileprivate func interruptedAudio(_ notification: Notification) {
@@ -48,7 +48,7 @@ class BackgroundTask {
             self.player.volume = 0.01
             self.player.prepareToPlay()
             self.player.play()
-            LogManager.shared.log(category: .general, message: "Silent audio playing")
+            LogManager.shared.log(category: .general, message: "Silent audio playing", isDebug: true)
         } catch {
             LogManager.shared.log(category: .general, message: "playAudio, error: \(error)")
         }

+ 5 - 3
LoopFollow/Log/LogManager.swift

@@ -42,7 +42,7 @@ class LogManager {
         dateFormatter.dateFormat = "yyyy-MM-dd"
     }
 
-    func log(category: Category, message: String) {
+    func log(category: Category, message: String, isDebug: Bool = false) {
         let timestamp = DateFormatter.localizedString(from: Date(), dateStyle: .none, timeStyle: .medium)
         let logMessage = "[\(timestamp)] [\(category.rawValue)] \(message)"
 
@@ -50,8 +50,10 @@ class LogManager {
             print(logMessage)
         }
 
-        let logFileURL = currentLogFileURL
-        append(logMessage + "\n", to: logFileURL)
+        if !isDebug || Storage.shared.debugLogLevel.value {
+            let logFileURL = self.currentLogFileURL
+            self.append(logMessage + "\n", to: logFileURL)
+        }
     }
 
     func cleanupOldLogs() {

+ 45 - 0
LoopFollow/Settings/AdvancedSettingsView.swift

@@ -0,0 +1,45 @@
+//
+//  AdvancedSettingsView.swift
+//  LoopFollow
+//
+//  Created by Jonas Björkert on 2025-01-23.
+//  Copyright © 2025 Jon Fawcett. All rights reserved.
+//
+
+import SwiftUI
+
+struct AdvancedSettingsView: View {
+    @ObservedObject var viewModel: AdvancedSettingsViewModel
+    @Environment(\.presentationMode) var presentationMode
+
+    var body: some View {
+        NavigationView {
+            Form {
+                Section(header: Text("Advanced Settings")) {
+                    Toggle("Download Treatments", isOn: $viewModel.downloadTreatments)
+                    Toggle("Download Prediction", isOn: $viewModel.downloadPrediction)
+                    Toggle("Graph Basal", isOn: $viewModel.graphBasal)
+                    Toggle("Graph Bolus", isOn: $viewModel.graphBolus)
+                    Toggle("Graph Carbs", isOn: $viewModel.graphCarbs)
+                    Toggle("Graph Other Treatments", isOn: $viewModel.graphOtherTreatments)
+
+                    Stepper(value: $viewModel.bgUpdateDelay, in: 1...30, step: 1) {
+                        Text("BG Update Delay (Sec): \(viewModel.bgUpdateDelay)")
+                    }
+                }
+
+                Section(header: Text("Logging Options")) {
+                    Toggle("Debug Log Level", isOn: $viewModel.debugLogLevel)
+                }
+            }
+            .navigationBarTitle("Advanced Settings", displayMode: .inline)
+            .toolbar {
+                ToolbarItem(placement: .navigationBarTrailing) {
+                    Button("Done") {
+                        presentationMode.wrappedValue.dismiss()
+                    }
+                }
+            }
+        }
+    }
+}

+ 62 - 0
LoopFollow/Settings/AdvancedSettingsViewModel.swift

@@ -0,0 +1,62 @@
+//
+//  AdvancedSettingsViewModel.swift
+//  LoopFollow
+//
+//  Created by Jonas Björkert on 2025-01-23.
+//  Copyright © 2025 Jon Fawcett. All rights reserved.
+//
+
+import Foundation
+
+class AdvancedSettingsViewModel: ObservableObject {
+    @Published var downloadTreatments: Bool {
+        didSet {
+            UserDefaultsRepository.downloadTreatments.value = downloadTreatments
+        }
+    }
+    @Published var downloadPrediction: Bool {
+        didSet {
+            UserDefaultsRepository.downloadPrediction.value = downloadPrediction
+        }
+    }
+    @Published var graphBasal: Bool {
+        didSet {
+            UserDefaultsRepository.graphBasal.value = graphBasal
+        }
+    }
+    @Published var graphBolus: Bool {
+        didSet {
+            UserDefaultsRepository.graphBolus.value = graphBolus
+        }
+    }
+    @Published var graphCarbs: Bool {
+        didSet {
+            UserDefaultsRepository.graphCarbs.value = graphCarbs
+        }
+    }
+    @Published var graphOtherTreatments: Bool {
+        didSet {
+            UserDefaultsRepository.graphOtherTreatments.value = graphOtherTreatments
+        }
+    }
+    @Published var bgUpdateDelay: Int {
+        didSet {
+            UserDefaultsRepository.bgUpdateDelay.value = bgUpdateDelay
+        }
+    }
+    @Published var debugLogLevel: Bool {
+        didSet {
+            Storage.shared.debugLogLevel.value = debugLogLevel
+        }
+    }
+    init() {
+        self.downloadTreatments = UserDefaultsRepository.downloadTreatments.value
+        self.downloadPrediction = UserDefaultsRepository.downloadPrediction.value
+        self.graphBasal = UserDefaultsRepository.graphBasal.value
+        self.graphBolus = UserDefaultsRepository.graphBolus.value
+        self.graphCarbs = UserDefaultsRepository.graphCarbs.value
+        self.graphOtherTreatments = UserDefaultsRepository.graphOtherTreatments.value
+        self.bgUpdateDelay = UserDefaultsRepository.bgUpdateDelay.value
+        self.debugLogLevel = Storage.shared.debugLogLevel.value
+    }
+}

+ 2 - 0
LoopFollow/Storage/Storage.swift

@@ -35,6 +35,8 @@ class Storage {
 
     var selectedBLEDevice = StorageValue<BLEDevice?>(key: "selectedBLEDevice", defaultValue: nil)
 
+    var debugLogLevel = StorageValue<Bool>(key: "debugLogLevel", defaultValue: false)
+
 
     static let shared = Storage()
 

+ 8 - 11
LoopFollow/Task/TaskScheduler.swift

@@ -39,17 +39,17 @@ class TaskScheduler {
 
     func scheduleTask(id: TaskID, nextRun: Date, action: @escaping () -> Void) {
         queue.async {
-//            let timeString = self.formatTime(nextRun)
-//            LogManager.shared.log(category: .taskScheduler, message: "scheduleTask(\(id)): nextRun = \(timeString)")
-            
+            let timeString = self.formatTime(nextRun)
+            LogManager.shared.log(category: .taskScheduler, message: "scheduleTask(\(id)): next run = \(timeString)", isDebug: true)
+
             self.tasks[id] = ScheduledTask(nextRun: nextRun, action: action)
             self.rescheduleTimer()
         }
     }
 
     func rescheduleTask(id: TaskID, to newRunDate: Date) {
-//        let timeString = self.formatTime(newRunDate)
-//        LogManager.shared.log(category: .taskScheduler, message: "rescheduleTask(\(id)): nextRun = \(timeString)")
+        let timeString = self.formatTime(newRunDate)
+        LogManager.shared.log(category: .taskScheduler, message: "Reschedule Task \(id): next run = \(timeString)", isDebug: true)
 
         queue.async {
             guard var existingTask = self.tasks[id] else {
@@ -77,10 +77,7 @@ class TaskScheduler {
         currentTimer = nil
 
         guard let (_, earliestTask) = tasks.min(by: { $0.value.nextRun < $1.value.nextRun }) else {
-            LogManager.shared.log(
-                category: .taskScheduler,
-                message: "No tasks, no timer scheduled."
-            )
+            LogManager.shared.log(category: .taskScheduler, message: "No tasks, no timer scheduled.")
             return
         }
 
@@ -118,7 +115,7 @@ class TaskScheduler {
                 }
 
                 if shouldSkip {
-//                    LogManager.shared.log(category: .taskScheduler, message: "Skipping alarmCheck because one of the specified tasks is due or set to distant future.")
+                    //LogManager.shared.log(category: .taskScheduler, message: "Skipping alarmCheck because one of the specified tasks is due or set to distant future.")
                     continue
                 }
             }
@@ -127,7 +124,7 @@ class TaskScheduler {
             updatedTask.nextRun = .distantFuture
             tasks[taskID] = updatedTask
 
-//            LogManager.shared.log(category: .taskScheduler, message: "Executing task \(taskID.description) at \(formatTime(now)).")
+            LogManager.shared.log(category: .taskScheduler, message: "Executing task \(taskID)", isDebug: true)
 
             DispatchQueue.main.async {
                 task.action()

+ 0 - 99
LoopFollow/ViewControllers/AdvancedSettingsViewController.swift

@@ -1,99 +0,0 @@
-//
-//  DebugSettingsViewController.swift
-//  LoopFollow
-//
-//  Created by Jose Paredes on 7/16/20.
-//  Copyright © 2020 Jon Fawcett. All rights reserved.
-//
-
-import Foundation
-import Eureka
-import EventKit
-import EventKitUI
-
-class AdvancedSettingsViewController: FormViewController {
-    
-    var appStateController: AppStateController?
-    
-    override func viewDidLoad()  {
-        super.viewDidLoad()
-        if UserDefaultsRepository.forceDarkMode.value {
-            overrideUserInterfaceStyle = .dark
-        }
-        buildAdvancedSettings()
-    }
-    private func buildAdvancedSettings() {
-        form
-            +++ Section("Advanced Settings")
-            
-            <<< SwitchRow("downloadTreatments"){ row in
-                row.title = "Download Treatments"
-                row.value = UserDefaultsRepository.downloadTreatments.value
-            }.onChange { [weak self] row in
-                guard let value = row.value else { return }
-                UserDefaultsRepository.downloadTreatments.value = value
-            }
-            <<< SwitchRow("downloadPrediction"){ row in
-                row.title = "Download Prediction"
-                row.value = UserDefaultsRepository.downloadPrediction.value
-            }.onChange { [weak self] row in
-                guard let value = row.value else { return }
-                UserDefaultsRepository.downloadPrediction.value = value
-            }
-            <<< SwitchRow("graphBasal"){ row in
-                row.title = "Graph Basal"
-                row.value = UserDefaultsRepository.graphBasal.value
-            }.onChange { [weak self] row in
-                guard let value = row.value else { return }
-                UserDefaultsRepository.graphBasal.value = value
-            }
-            <<< SwitchRow("graphBolus"){ row in
-                row.title = "Graph Bolus"
-                row.value = UserDefaultsRepository.graphBolus.value
-            }.onChange { [weak self] row in
-                guard let value = row.value else { return }
-                UserDefaultsRepository.graphBolus.value = value
-            }
-            <<< SwitchRow("graphCarbs"){ row in
-                row.title = "Graph Carbs"
-                row.value = UserDefaultsRepository.graphCarbs.value
-            }.onChange { [weak self] row in
-                guard let value = row.value else { return }
-                UserDefaultsRepository.graphCarbs.value = value
-            }
-            <<< SwitchRow("graphOtherTreatments"){ row in
-                row.title = "Graph Other Treatments"
-                row.value = UserDefaultsRepository.graphOtherTreatments.value
-            }.onChange { [weak self] row in
-                guard let value = row.value else { return }
-                UserDefaultsRepository.graphOtherTreatments.value = value
-            }
-            <<< StepperRow("bgUpdateDelay") { row in
-                row.title = "BG Update Delay (Sec)"
-                row.cell.stepper.stepValue = 1
-                row.cell.stepper.minimumValue = 1
-                row.cell.stepper.maximumValue = 30
-                row.value = Double(UserDefaultsRepository.bgUpdateDelay.value)
-                row.displayValueFor = { value in
-                        guard let value = value else { return nil }
-                        return "\(Int(value))"
-                    }
-            }.onChange { [weak self] row in
-                    guard let value = row.value else { return }
-                    UserDefaultsRepository.bgUpdateDelay.value = Int(value)
-            }
-
-
-            
-            
-            
-            
-            +++ ButtonRow() {
-                $0.title = "DONE"
-            }.onCellSelection { (row, arg)  in
-                self.dismiss(animated:true, completion: nil)
-            }
-    }
-    
-
-}

+ 17 - 8
LoopFollow/ViewControllers/SettingsViewController.swift

@@ -172,12 +172,9 @@ class SettingsViewController: FormViewController, NightscoutSettingsViewModelDel
             $0.title = "Advanced Settings"
             $0.presentationMode = .show(
                 controllerProvider: .callback(builder: {
-                    let controller = AdvancedSettingsViewController()
-                    controller.appStateController = self.appStateController
-                    return controller
-                }
-                                             ), onDismiss: nil)
-
+                    self.presentAdvancedSettingsView()
+                    return UIViewController()
+                }), onDismiss: nil)
         }
 
         +++ Section("Logging")
@@ -187,8 +184,7 @@ class SettingsViewController: FormViewController, NightscoutSettingsViewModelDel
                 controllerProvider: .callback(builder: {
                     self.presentLogView()
                     return UIViewController()
-                }
-                                             ), onDismiss: nil)
+                }), onDismiss: nil)
         }
         <<< ButtonRow("shareLogs") {
             $0.title = "Share Logs"
@@ -369,6 +365,19 @@ class SettingsViewController: FormViewController, NightscoutSettingsViewModelDel
         present(hostingController, animated: true, completion: nil)
     }
 
+    func presentAdvancedSettingsView() {
+        let viewModel = AdvancedSettingsViewModel()
+        let view = AdvancedSettingsView(viewModel: viewModel)
+        let hostingController = UIHostingController(rootView: view)
+        hostingController.modalPresentationStyle = .formSheet
+
+        if UserDefaultsRepository.forceDarkMode.value {
+            hostingController.overrideUserInterfaceStyle = .dark
+        }
+
+        present(hostingController, animated: true, completion: nil)
+    }
+
     private func shareLogs() {
         let logManager = LogManager.shared
         let logFileURL = logManager.currentLogFileURL