Przeglądaj źródła

Merge branch 'dnzxy:core-data-sync-trio' into settings-update

tmhastings 1 rok temu
rodzic
commit
53deb6bd58

+ 1 - 0
FreeAPS/Resources/Info.plist

@@ -101,6 +101,7 @@
 		<string>bluetooth-peripheral</string>
 		<string>fetch</string>
 		<string>processing</string>
+                <string>remote-notification</string>
 	</array>
 	<key>UIFileSharingEnabled</key>
 	<true/>

+ 24 - 23
FreeAPS/Sources/Modules/CGM/View/CGMRootView.swift

@@ -220,6 +220,7 @@ extension CGM {
                 .onAppear(perform: configureView)
                 .navigationTitle("CGM")
                 .navigationBarTitleDisplayMode(.automatic)
+                .navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
                 .sheet(isPresented: $shouldDisplayHint) {
                     SettingInputHintView(
                         hintDetent: $hintDetent,
@@ -229,29 +230,6 @@ extension CGM {
                         sheetTitle: "Help"
                     )
                 }
-                .sheet(isPresented: $setupCGM) {
-                    if let cgmFetchManager = state.cgmManager,
-                       let cgmManager = cgmFetchManager.cgmManager,
-                       state.cgmCurrent.type == cgmFetchManager.cgmGlucoseSourceType,
-                       state.cgmCurrent.id == cgmFetchManager.cgmGlucosePluginId
-                    {
-                        CGMSettingsView(
-                            cgmManager: cgmManager,
-                            bluetoothManager: state.provider.apsManager.bluetoothManager!,
-                            unit: state.settingsManager.settings.units,
-                            completionDelegate: state
-                        )
-                    } else {
-                        CGMSetupView(
-                            CGMType: state.cgmCurrent,
-                            bluetoothManager: state.provider.apsManager.bluetoothManager!,
-                            unit: state.settingsManager.settings.units,
-                            completionDelegate: state,
-                            setupDelegate: state,
-                            pluginCGMManager: self.state.pluginCGMManager
-                        )
-                    }
-                }
                 .onChange(of: setupCGM) { _, setupCGM in
                     state.setupCGM = setupCGM
                 }
@@ -260,6 +238,29 @@ extension CGM {
                 }
                 .screenNavigation(self)
             }
+            .sheet(isPresented: $setupCGM) {
+                if let cgmFetchManager = state.cgmManager,
+                   let cgmManager = cgmFetchManager.cgmManager,
+                   state.cgmCurrent.type == cgmFetchManager.cgmGlucoseSourceType,
+                   state.cgmCurrent.id == cgmFetchManager.cgmGlucosePluginId
+                {
+                    CGMSettingsView(
+                        cgmManager: cgmManager,
+                        bluetoothManager: state.provider.apsManager.bluetoothManager!,
+                        unit: state.settingsManager.settings.units,
+                        completionDelegate: state
+                    )
+                } else {
+                    CGMSetupView(
+                        CGMType: state.cgmCurrent,
+                        bluetoothManager: state.provider.apsManager.bluetoothManager!,
+                        unit: state.settingsManager.settings.units,
+                        completionDelegate: state,
+                        setupDelegate: state,
+                        pluginCGMManager: self.state.pluginCGMManager
+                    )
+                }
+            }
         }
     }
 }

+ 1 - 3
FreeAPS/Sources/Modules/Home/View/Chart/ChartElements/SelectionPopoverView.swift

@@ -70,9 +70,7 @@ struct SelectionPopoverView: ChartContent {
             .font(.body).padding(.bottom, 5)
 
             HStack {
-                Text(units == .mgdL ? glucoseToDisplay.description : glucoseToDisplay.formattedAsMmolL)
-                    .bold()
-                    + Text(" \(units.rawValue)")
+                Text(glucoseToDisplay.description).bold() + Text(" \(units.rawValue)")
             }
             .foregroundStyle(pointMarkColor)
             .font(.body)

+ 18 - 18
FreeAPS/Sources/Modules/PumpConfig/View/PumpConfigRootView.swift

@@ -96,24 +96,6 @@ extension PumpConfig {
                 .navigationTitle("Insulin Pump")
                 .navigationBarTitleDisplayMode(.automatic)
                 .navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
-                .sheet(isPresented: $state.setupPump) {
-                    if let pumpManager = state.provider.apsManager.pumpManager {
-                        PumpSettingsView(
-                            pumpManager: pumpManager,
-                            bluetoothManager: state.provider.apsManager.bluetoothManager!,
-                            completionDelegate: state,
-                            setupDelegate: state
-                        )
-                    } else {
-                        PumpSetupView(
-                            pumpType: state.setupPumpType,
-                            pumpInitialSettings: state.initialSettings,
-                            bluetoothManager: state.provider.apsManager.bluetoothManager!,
-                            completionDelegate: state,
-                            setupDelegate: state
-                        )
-                    }
-                }
                 .sheet(isPresented: $shouldDisplayHint) {
                     SettingInputHintView(
                         hintDetent: $hintDetent,
@@ -130,6 +112,24 @@ extension PumpConfig {
                     Button("Pump Simulator") { state.addPump(.simulator) }
                 } message: { Text("Select Pump Model") }
             }
+            .sheet(isPresented: $state.setupPump) {
+                if let pumpManager = state.provider.apsManager.pumpManager {
+                    PumpSettingsView(
+                        pumpManager: pumpManager,
+                        bluetoothManager: state.provider.apsManager.bluetoothManager!,
+                        completionDelegate: state,
+                        setupDelegate: state
+                    )
+                } else {
+                    PumpSetupView(
+                        pumpType: state.setupPumpType,
+                        pumpInitialSettings: state.initialSettings,
+                        bluetoothManager: state.provider.apsManager.bluetoothManager!,
+                        completionDelegate: state,
+                        setupDelegate: state
+                    )
+                }
+            }
         }
     }
 }

+ 1 - 1
FreeAPS/Sources/Services/Network/Nightscout/NightscoutManager.swift

@@ -192,7 +192,7 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
             .sink { [weak self] _ in
                 guard let self = self else { return }
                 Task {
-                    await self.uploadOverrides()
+                    await self.uploadTempTargets()
 
                     // Post a notification indicating that the upload has finished and that we can end the background task in the TempTargetPresetsIntentRequest
                     Foundation.NotificationCenter.default.post(name: .didUpdateTempTargetConfiguration, object: nil)

+ 3 - 3
FreeAPS/Sources/Shortcuts/TempPresets/ApplyTempPresetIntent.swift

@@ -54,7 +54,7 @@ struct ApplyTempPresetIntent: AppIntent {
             let displayName: String = presetToApply.name
             if confirmBeforeApplying {
                 try await requestConfirmation(
-                    result: .result(dialog: "Confirm to apply temporary target '\(displayName)'")
+                    result: .result(dialog: "Confirm to apply Temporary Target '\(displayName)'")
                 )
             }
 
@@ -62,7 +62,7 @@ struct ApplyTempPresetIntent: AppIntent {
                 return .result(
                     dialog: IntentDialog(
                         LocalizedStringResource(
-                            "TempTarget '\(presetToApply.name)' applied",
+                            "Temporary Target '\(presetToApply.name)' applied",
                             table: "ShortcutsDetail"
                         )
                     )
@@ -71,7 +71,7 @@ struct ApplyTempPresetIntent: AppIntent {
                 return .result(
                     dialog: IntentDialog(
                         LocalizedStringResource(
-                            "TempTarget '\(presetToApply.name)' failed",
+                            "Temporary Target '\(presetToApply.name)' failed",
                             table: "ShortcutsDetail"
                         )
                     )

+ 20 - 0
FreeAPS/Sources/Shortcuts/TempPresets/TempPresetsIntentRequest.swift

@@ -132,6 +132,26 @@ final class TempPresetsIntentRequest: BaseIntentsRequest {
 
                 // Await the notification
                 print("Waiting for notification...")
+
+                guard let tempTargetDate = tempTargetObject.date, let tempTarget = tempTargetObject.target,
+                      let tempTargetDuration = tempTargetObject.duration else { return false }
+
+                let tempTargetToStoreAsJSON = TempTarget(
+                    name: tempTargetObject.name,
+                    createdAt: tempTargetDate,
+                    targetTop: tempTarget as Decimal,
+                    targetBottom: tempTarget as Decimal,
+                    duration: tempTargetDuration as Decimal,
+                    enteredBy: TempTarget.local,
+                    reason: TempTarget.custom,
+                    isPreset: tempTargetObject.isPreset,
+                    enabled: tempTargetObject.enabled,
+                    halfBasalTarget: tempTargetObject.halfBasalTarget as Decimal?
+                )
+
+                // Save the temp targets to JSON so that they get used by oref
+                tempTargetsStorage.saveTempTargetsToStorage([tempTargetToStoreAsJSON])
+
                 await awaitNotification(.didUpdateTempTargetConfiguration)
                 print("Notification received, continuing...")