Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion BuildDetails.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<plist version="1.0">
<dict>
<key>TidepoolServiceClientId</key>
<string>diy-loop</string>
<string>nightscout-trio</string>
<key>TidepoolServiceRedirectURL</key>
<string> org.nightscout.trio.tidepoolkit.auth://redirect</string>
</dict>
</plist>
4 changes: 4 additions & 0 deletions Trio.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@
BD8FC0622D6619E600B95AED /* OverrideStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8FC0612D6619E600B95AED /* OverrideStorageTests.swift */; };
BD8FC0642D6619EF00B95AED /* TempTargetStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8FC0632D6619EF00B95AED /* TempTargetStorageTests.swift */; };
BD8FC0662D661A0000B95AED /* GlucoseStorageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8FC0652D661A0000B95AED /* GlucoseStorageTests.swift */; };
BD8FC0712D661B0000B95AED /* TidepoolTherapySettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD8FC0702D661B0000B95AED /* TidepoolTherapySettingsTests.swift */; };
BDA25EE42D260CD500035F34 /* AppleWatchManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDA25EE32D260CCF00035F34 /* AppleWatchManager.swift */; };
BDA25EE62D260D5E00035F34 /* WatchState.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDA25EE52D260D5800035F34 /* WatchState.swift */; };
BDA25EFD2D261C0000035F34 /* WatchState.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDA25EFC2D261BF200035F34 /* WatchState.swift */; };
Expand Down Expand Up @@ -1249,6 +1250,7 @@
BD8FC0612D6619E600B95AED /* OverrideStorageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverrideStorageTests.swift; sourceTree = "<group>"; };
BD8FC0632D6619EF00B95AED /* TempTargetStorageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TempTargetStorageTests.swift; sourceTree = "<group>"; };
BD8FC0652D661A0000B95AED /* GlucoseStorageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GlucoseStorageTests.swift; sourceTree = "<group>"; };
BD8FC0702D661B0000B95AED /* TidepoolTherapySettingsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TidepoolTherapySettingsTests.swift; sourceTree = "<group>"; };
BDA25EE32D260CCF00035F34 /* AppleWatchManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleWatchManager.swift; sourceTree = "<group>"; };
BDA25EE52D260D5800035F34 /* WatchState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchState.swift; sourceTree = "<group>"; };
BDA25EFC2D261BF200035F34 /* WatchState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WatchState.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2640,6 +2642,7 @@
3B997DCE2DC00A3A006B6BB2 /* JSONImporterTests.swift */,
CE1F6DD82BADF4620064EB8D /* PluginManagerTests.swift */,
BD8FC0532D66186000B95AED /* TestError.swift */,
BD8FC0702D661B0000B95AED /* TidepoolTherapySettingsTests.swift */,
);
path = TrioTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -4793,6 +4796,7 @@
38FCF3F925E902C20078B0D1 /* FileStorageTests.swift in Sources */,
BD8FC0602D6619DB00B95AED /* CarbsStorageTests.swift in Sources */,
BD8FC05E2D6618CE00B95AED /* BolusCalculatorTests.swift in Sources */,
BD8FC0712D661B0000B95AED /* TidepoolTherapySettingsTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 5 additions & 1 deletion Trio/Sources/Localizations/Main/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -264062,6 +264062,9 @@
}
}
}
},
"Use your Tidepool credentials to log in. If you don't have a Tidepool account, you can sign up on the login page.\n\nWhen connected, Trio uploads your glucose, carb entries, insulin (bolus and basal), pump settings, and therapy settings to Tidepool.\n\nTherapy settings include basal schedules, carb ratios, insulin sensitivities, and glucose targets." : {

},
"User Interface" : {
"localizations" : {
Expand Down Expand Up @@ -269847,6 +269850,7 @@
}
},
"When connected, uploading of carbs, bolus, basal and glucose from Trio to your Tidepool account is enabled.\n\nUse your Tidepool credentials to login. If you dont already have a Tidepool account, you can sign up for one on the login page." : {
"extractionState" : "stale",
"localizations" : {
"bg" : {
"stringUnit" : {
Expand Down Expand Up @@ -277249,4 +277253,4 @@
}
},
"version" : "1.1"
}
}
4 changes: 4 additions & 0 deletions Trio/Sources/Models/CarbRatios.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Foundation

protocol CarbRatiosObserver {
func carbRatiosDidChange(_ carbRatios: CarbRatios)
}

struct CarbRatios: JSON {
let units: CarbUnit
let schedule: [CarbRatioEntry]
Expand Down
4 changes: 4 additions & 0 deletions Trio/Sources/Models/InsulinSensitivities.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import Foundation

protocol InsulinSensitivitiesObserver {
func insulinSensitivitiesDidChange(_ sensitivities: InsulinSensitivities)
}

struct InsulinSensitivities: JSON {
var units: GlucoseUnits
var userPreferredUnits: GlucoseUnits
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extension AlgorithmAdvancedSettings {
@Injected() var settings: SettingsManager!
@Injected() var storage: FileStorage!
@Injected() var nightscout: NightscoutManager!
@Injected() private var tidepoolManager: TidepoolManager!

var units: GlucoseUnits = .mgdL

Expand Down Expand Up @@ -78,6 +79,10 @@ extension AlgorithmAdvancedSettings {
)
}
}

Task.detached(priority: .low) {
await self.tidepoolManager.uploadSettings()
}
} receiveValue: {}
.store(in: &lifetime)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import SwiftUI
extension BasalProfileEditor {
@Observable final class StateModel: BaseStateModel<Provider> {
@ObservationIgnored @Injected() private var nightscout: NightscoutManager!
@ObservationIgnored @Injected() private var tidepoolManager: TidepoolManager!
@ObservationIgnored @Injected() private var broadcaster: Broadcaster!

var syncInProgress: Bool = false
Expand Down Expand Up @@ -127,6 +128,10 @@ extension BasalProfileEditor {
debug(.default, "Failed to upload basal rates to Nightscout: \(error)")
}
}

Task.detached(priority: .low) {
await self.tidepoolManager.uploadSettings()
}
case .failure:
// Handle the error, show error message
self.showAlert = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import SwiftUI
extension CarbRatioEditor {
final class StateModel: BaseStateModel<Provider> {
@Injected() private var nightscout: NightscoutManager!
@Injected() private var tidepoolManager: TidepoolManager!
@Injected() private var broadcaster: Broadcaster!
@Published var items: [Item] = []
@Published var initialItems: [Item] = []
@Published var therapyItems: [TherapySettingItem] = []
Expand Down Expand Up @@ -89,6 +91,13 @@ extension CarbRatioEditor {
let profile = CarbRatios(units: .grams, schedule: schedule)
provider.saveProfile(profile)
initialItems = items.map { Item(rateIndex: $0.rateIndex, timeIndex: $0.timeIndex) }

DispatchQueue.main.async {
Comment thread
dnzxy marked this conversation as resolved.
self.broadcaster.notify(CarbRatiosObserver.self, on: .main) {
$0.carbRatiosDidChange(profile)
}
}

Task.detached(priority: .low) {
do {
debug(.nightscout, "Attempting to upload CRs to Nightscout")
Expand All @@ -97,6 +106,10 @@ extension CarbRatioEditor {
debug(.default, "Failed to upload CRs to Nightscout: \(error)")
}
}

Task.detached(priority: .low) {
await self.tidepoolManager.uploadSettings()
}
}

func validate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extension UnitsLimitsSettings {
final class StateModel: BaseStateModel<Provider> {
@Injected() var settings: SettingsManager!
@Injected() var storage: FileStorage!
@Injected() private var tidepoolManager: TidepoolManager!

@Published var units: GlucoseUnits = .mgdL
@Published var unitsIndex = 0 // index 0 is mg/dl
Expand Down Expand Up @@ -56,6 +57,10 @@ extension UnitsLimitsSettings {
let settings = self.provider.settings()
self.maxBasal = settings.maxBasal
self.maxBolus = settings.maxBolus

Task.detached(priority: .low) {
await self.tidepoolManager.uploadSettings()
}
} receiveValue: {}
.store(in: &lifetime)
}
Expand Down
12 changes: 12 additions & 0 deletions Trio/Sources/Modules/ISFEditor/ISFEditorStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extension ISFEditor {
@Observable final class StateModel: BaseStateModel<Provider> {
@ObservationIgnored @Injected() var determinationStorage: DeterminationStorage!
@ObservationIgnored @Injected() private var nightscout: NightscoutManager!
@ObservationIgnored @Injected() private var tidepoolManager: TidepoolManager!
@ObservationIgnored @Injected() private var broadcaster: Broadcaster!

var items: [Item] = []
var initialItems: [Item] = []
Expand Down Expand Up @@ -118,6 +120,12 @@ extension ISFEditor {
provider.saveProfile(profile)
initialItems = items.map { Item(rateIndex: $0.rateIndex, timeIndex: $0.timeIndex) }

DispatchQueue.main.async {
self.broadcaster.notify(InsulinSensitivitiesObserver.self, on: .main) {
$0.insulinSensitivitiesDidChange(profile)
}
}

Task.detached(priority: .low) {
do {
debug(.nightscout, "Attempting to upload ISF to Nightscout")
Expand All @@ -129,6 +137,10 @@ extension ISFEditor {
)
}
}

Task.detached(priority: .low) {
await self.tidepoolManager.uploadSettings()
}
}

func validate() {
Expand Down
1 change: 0 additions & 1 deletion Trio/Sources/Modules/Settings/SettingsStateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ extension Settings {

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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct TidepoolStartView: BaseView {
shouldDisplayHint: $shouldDisplayHint,
hintLabel: "Connect to Tidepool",
hintText: Text(
"When connected, uploading of carbs, bolus, basal and glucose from Trio to your Tidepool account is enabled.\n\nUse your Tidepool credentials to login. If you dont already have a Tidepool account, you can sign up for one on the login page."
"Use your Tidepool credentials to log in. If you don't have a Tidepool account, you can sign up on the login page.\n\nWhen connected, Trio uploads your glucose, carb entries, insulin (bolus and basal), pump settings, and therapy settings to Tidepool.\n\nTherapy settings include basal schedules, carb ratios, insulin sensitivities, and glucose targets."
),
sheetTitle: String(localized: "Help", comment: "Help sheet title")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SwiftUI
extension TargetsEditor {
final class StateModel: BaseStateModel<Provider> {
@Injected() private var nightscout: NightscoutManager!
@Injected() private var tidepoolManager: TidepoolManager!
@Injected() private var broadcaster: Broadcaster!

@Published var items: [Item] = []
Expand Down Expand Up @@ -113,6 +114,10 @@ extension TargetsEditor {
)
}
}

Task.detached(priority: .low) {
await self.tidepoolManager.uploadSettings()
}
}

func validate() {
Expand Down
Loading