Просмотр исходного кода

Merge pull request #142 from dnzxy/fix-temptarget-shortcut

Fix Temp Target Shortcut
polscm32 1 год назад
Родитель
Сommit
2ad93988b4

+ 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...")