Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OpenGlück #479

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
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
47 changes: 45 additions & 2 deletions xdrip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@
47DB06E32A7137B000267BE3 /* LibreLinkUpFollowManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DB06E22A7137B000267BE3 /* LibreLinkUpFollowManager.swift */; };
47DB06E72A715EC500267BE3 /* ConstantsLibreLinkUp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DB06E62A715EC500267BE3 /* ConstantsLibreLinkUp.swift */; };
47DB06E92A715FD900267BE3 /* LibreLinkUpModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DB06E82A715FD900267BE3 /* LibreLinkUpModels.swift */; };
47DE41AA2B860DF00041DA19 /* WatchConnectivity.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 47DE41A92B860DF00041DA19 /* WatchConnectivity.framework */; };
47DE41AD2B863D370041DA19 /* WatchState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DE41AC2B863D370041DA19 /* WatchState.swift */; };
47DE41AE2B863D370041DA19 /* WatchState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DE41AC2B863D370041DA19 /* WatchState.swift */; };
47DE41AF2B864EE50041DA19 /* xDrip Watch App.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 47A6ABDF2B790CC60047A4BA /* xDrip Watch App.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
Expand All @@ -211,6 +210,12 @@
47F7B1C62C68BBE100609DA7 /* ConstantsCalibrationAlgorithms.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A1585422EDB706007F5B5D /* ConstantsCalibrationAlgorithms.swift */; };
47F7B1CD2C68CC3000609DA7 /* ConstantsCalibrationAlgorithms.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A1585422EDB706007F5B5D /* ConstantsCalibrationAlgorithms.swift */; };
47FB28082636B04200042FFB /* StatisticsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FB28072636B04200042FFB /* StatisticsManager.swift */; };
9D06FF5B2A76EB1600ECEA9B /* (null) in Frameworks */ = {isa = PBXBuildFile; };
9D06FF622A76EC0000ECEA9B /* OG in Frameworks */ = {isa = PBXBuildFile; productRef = 9D06FF612A76EC0000ECEA9B /* OG */; };
9D67DF752A6DBEDC009A15DD /* SettingsViewOpenGlückSettingsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D67DF742A6DBEDC009A15DD /* SettingsViewOpenGlückSettingsViewModel.swift */; };
9D67DF7A2A6DC365009A15DD /* OpenGlückManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D67DF792A6DC365009A15DD /* OpenGlückManager.swift */; };
9D67DF7D2A6DC603009A15DD /* (null) in Frameworks */ = {isa = PBXBuildFile; };
9DBB1A4A2BA5A02D004B255A /* OGUI in Frameworks */ = {isa = PBXBuildFile; productRef = 9DBB1A492BA5A02D004B255A /* OGUI */; };
CE1B2FE025D0264B00F642F5 /* LaunchScreen.strings in Resources */ = {isa = PBXBuildFile; fileRef = CE1B2FD125D0264900F642F5 /* LaunchScreen.strings */; };
CE1B2FE125D0264B00F642F5 /* Main.strings in Resources */ = {isa = PBXBuildFile; fileRef = CE1B2FD425D0264900F642F5 /* Main.strings */; };
D400F8032778BD8000B57648 /* TextsTreatmentsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D400F8022778BD8000B57648 /* TextsTreatmentsView.swift */; };
Expand Down Expand Up @@ -1037,6 +1042,8 @@
47FB28072636B04200042FFB /* StatisticsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatisticsManager.swift; sourceTree = "<group>"; };
666E283826F7E54C00ACE4DF /* xDrip.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = xDrip.xcconfig; path = xdrip/xDrip.xcconfig; sourceTree = "<group>"; };
666E283926F7E54C00ACE4DF /* Version.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Version.xcconfig; path = xdrip/Version.xcconfig; sourceTree = "<group>"; };
9D67DF742A6DBEDC009A15DD /* SettingsViewOpenGlückSettingsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SettingsViewOpenGlückSettingsViewModel.swift"; sourceTree = "<group>"; };
9D67DF792A6DC365009A15DD /* OpenGlückManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "OpenGlückManager.swift"; sourceTree = "<group>"; };
CE1B2FC825D0261500F642F5 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Alerts.strings; sourceTree = "<group>"; };
CE1B2FCD25D0264900F642F5 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/AlertTypesSettingsView.strings; sourceTree = "<group>"; };
CE1B2FCE25D0264900F642F5 /* fr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/WatlaaView.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1913,11 +1920,14 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9D06FF622A76EC0000ECEA9B /* OG in Frameworks */,
F81F3C4225D1D91300520946 /* CoreNFC.framework in Frameworks */,
470824D2297484B500C52317 /* SwiftCharts in Frameworks */,
9D67DF7D2A6DC603009A15DD /* (null) in Frameworks */,
4779BCEE2974306300515714 /* ActionClosurable in Frameworks */,
F821CF9722AE589E005C1E43 /* HealthKit.framework in Frameworks */,
47DE41AA2B860DF00041DA19 /* WatchConnectivity.framework in Frameworks */,
9DBB1A4A2BA5A02D004B255A /* OGUI in Frameworks */,
9D06FF5B2A76EB1600ECEA9B /* (null) in Frameworks */,
4779BCF42974308F00515714 /* PieCharts in Frameworks */,
4779BCF12974307700515714 /* CryptoSwift in Frameworks */,
);
Expand Down Expand Up @@ -2203,6 +2213,14 @@
name = Frameworks;
sourceTree = "<group>";
};
9D67DF782A6DC339009A15DD /* OpenGlückManager */ = {
isa = PBXGroup;
children = (
9D67DF792A6DC365009A15DD /* OpenGlückManager.swift */,
);
path = "OpenGlückManager";
sourceTree = "<group>";
};
D4028CBE2774A4B900341476 /* Treatments */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2646,6 +2664,7 @@
4716A5122B41CA9C00419052 /* LiveActivity */,
F8E51D5B2448D8A3001C9E5A /* Loop */,
F821CF4F229BF43A005C1E43 /* Nightscout */,
9D67DF782A6DC339009A15DD /* OpenGlückManager */,
F64039AE281C3F8D0051EFFE /* QuickActions */,
F821CF9922AEF2DF005C1E43 /* Speak */,
47FB28052636AFE700042FFB /* Statistics */,
Expand Down Expand Up @@ -3104,6 +3123,7 @@
4752B4052635878E0081D551 /* SettingsViewStatisticsSettingsViewModel.swift */,
F8E51D6824549E2C001C9E5A /* SettingsViewTraceSettingsViewModel.swift */,
47150A3F27F6211C00DB2994 /* SettingsViewTreatmentsSettingsViewModel.swift */,
9D67DF742A6DBEDC009A15DD /* SettingsViewOpenGlückSettingsViewModel.swift */,
);
path = SettingsViewModels;
sourceTree = "<group>";
Expand Down Expand Up @@ -3906,6 +3926,8 @@
4779BCF02974307700515714 /* CryptoSwift */,
4779BCF32974308F00515714 /* PieCharts */,
470824D1297484B500C52317 /* SwiftCharts */,
9D06FF612A76EC0000ECEA9B /* OG */,
9DBB1A492BA5A02D004B255A /* OGUI */,
);
productName = xdrip;
productReference = F8AC425A21ADEBD60078C348 /* xdrip.app */;
Expand Down Expand Up @@ -3980,6 +4002,7 @@
4779BCEC2974306300515714 /* XCRemoteSwiftPackageReference "ActionClosurable" */,
4779BCEF2974307700515714 /* XCRemoteSwiftPackageReference "CryptoSwift" */,
4779BCF22974308F00515714 /* XCRemoteSwiftPackageReference "PieCharts" */,
9D06FF5E2A76EC0000ECEA9B /* XCRemoteSwiftPackageReference "OG" */,
);
productRefGroup = F8AC425B21ADEBD60078C348 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -4427,6 +4450,7 @@
F85DC2ED21CFE2F500B9F74A /* BgReading+CoreDataProperties.swift in Sources */,
F85544912B83E6C3002569F8 /* DexcomG7GlucoseDataRxMessage.swift in Sources */,
F8A2BC0D25DB0B12001D1E78 /* Atom+BluetoothPeripheral.swift in Sources */,
9D67DF752A6DBEDC009A15DD /* SettingsViewOpenGlückSettingsViewModel.swift in Sources */,
F8F9723123A5915900C3F17D /* M5StackAuthenticateTXMessage.swift in Sources */,
F8EE3EAE2B6834FD00B27B96 /* DexcomG7HeartBeat+CoreDataClass.swift in Sources */,
F8F9721223A5915900C3F17D /* FirmwareVersionTxMessage.swift in Sources */,
Expand Down Expand Up @@ -4572,6 +4596,7 @@
F8CB59C22738206D00BA199E /* DexcomGlucoseDataTxMessage.swift in Sources */,
F8C97854242AA70D00A09483 /* MiaoMiao+CoreDataProperties.swift in Sources */,
F8F9720A23A5915900C3F17D /* DexcomTransmitterOpCode.swift in Sources */,
9D67DF7A2A6DC365009A15DD /* OpenGlückManager.swift in Sources */,
F8AC425E21ADEBD60078C348 /* AppDelegate.swift in Sources */,
F8A2BC0825DB09BE001D1E78 /* Atom+CoreDataProperties.swift in Sources */,
F8F1671927288FC6001AA3D8 /* DexcomSessionStartRxMessage.swift in Sources */,
Expand Down Expand Up @@ -5998,6 +6023,14 @@
kind = branch;
};
};
9D06FF5E2A76EC0000ECEA9B /* XCRemoteSwiftPackageReference "OG" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/open-gluck/OG";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.0.65;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -6021,6 +6054,16 @@
package = 4779BCF22974308F00515714 /* XCRemoteSwiftPackageReference "PieCharts" */;
productName = PieCharts;
};
9D06FF612A76EC0000ECEA9B /* OG */ = {
isa = XCSwiftPackageProductDependency;
package = 9D06FF5E2A76EC0000ECEA9B /* XCRemoteSwiftPackageReference "OG" */;
productName = OG;
};
9DBB1A492BA5A02D004B255A /* OGUI */ = {
isa = XCSwiftPackageProductDependency;
package = 9D06FF5E2A76EC0000ECEA9B /* XCRemoteSwiftPackageReference "OG" */;
productName = OGUI;
};
/* End XCSwiftPackageProductDependency section */

/* Begin XCVersionGroup section */
Expand Down
3 changes: 3 additions & 0 deletions xdrip/Constants/ConstantsLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ enum ConstantsLog {
/// healthkit manager
static let categoryHealthKitManager = "HealthKitManager "

/// openglück
static let categoryOpenGlückManager = "OpenGlückManager "

/// SettingsViewHealthKitSettingsViewModel
static let categorySettingsViewHealthKitSettingsViewModel = "SettingsViewHealthKitSettingsViewModel"

Expand Down
1 change: 1 addition & 0 deletions xdrip/Constants/ConstantsSettingsIcons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum ConstantsSettingsIcons {
static let dataSourceSettingsIcon: String = "➡️ "
static let developerSettingsIcon: String = "👨🏻‍💻 "
static let dexcomSettingsIcon: String = "⬆️ "
static let openGlückSettingsIcon: String = "⬆️ "
static let healthKitSettingsIcon: String = "❤️ "
static let helpSettingsIcon: String = "📖 "
static let homeScreenSettingsIcon: String = "📈 "
Expand Down
59 changes: 59 additions & 0 deletions xdrip/Extensions/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ extension UserDefaults {
/// should readings be stored in healthkit, true or false
case storeReadingsInHealthkit = "storeReadingsInHealthkit"

// OpenGlück
case openGlückEnabled = "openGlückEnabled"
case openGlückUploadEnabled = "openGlückUploadEnabled"
case openGlückHostname = "openGlückHostname"
case openGlückToken = "openGlückToken"
case timeStampLatestOpenGlückBgReading = "openGlückLastUpload"

// Speak readings

/// speak readings
Expand Down Expand Up @@ -1518,6 +1525,58 @@ extension UserDefaults {
}
}

// MARK: OpenGlück Settings

/// is OpenGlück enabled?
@objc dynamic var openGlückEnabled: Bool {
get {
return bool(forKey: Key.openGlückEnabled.rawValue)
}
set {
set(newValue, forKey: Key.openGlückEnabled.rawValue)
}
}

/// is OpenGlück upload enabled?
@objc dynamic var openGlückUploadEnabled: Bool {
get {
return bool(forKey: Key.openGlückUploadEnabled.rawValue)
}
set {
set(newValue, forKey: Key.openGlückUploadEnabled.rawValue)
}
}

/// OpenGlück hostname
@objc dynamic var openGlückHostname: String? {
get {
return string(forKey: Key.openGlückHostname.rawValue)
}
set {
set(newValue, forKey: Key.openGlückHostname.rawValue)
}
}

/// OpenGlück token
@objc dynamic var openGlückToken: String? {
get {
return string(forKey: Key.openGlückToken.rawValue)
}
set {
set(newValue, forKey: Key.openGlückToken.rawValue)
}
}

/// OpenGlück last upload
@objc dynamic var timeStampLatestOpenGlückBgReading: Date? {
get {
return object(forKey: Key.timeStampLatestOpenGlückBgReading.rawValue) as? Date
}
set {
set(newValue, forKey: Key.timeStampLatestOpenGlückBgReading.rawValue)
}
}

// MARK: Speak Settings

/// should readings be spoken or not
Expand Down
38 changes: 30 additions & 8 deletions xdrip/Managers/Alerts/AlertManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class AlertManager:NSObject {
/// playSound instance
private var soundPlayer:SoundPlayer?

/// openGlück manager instance
private var openGlückManager:OpenGlückManager?

/// snooze parameters
private var snoozeParameters = [SnoozeParameters]()

Expand All @@ -63,14 +66,15 @@ public class AlertManager:NSObject {

// MARK: - initializer

init(coreDataManager:CoreDataManager, soundPlayer:SoundPlayer?) {
init(coreDataManager:CoreDataManager, soundPlayer:SoundPlayer?, openGlückManager:OpenGlückManager?) {
// initialize properties
self.bgReadingsAccessor = BgReadingsAccessor(coreDataManager: coreDataManager)
self.alertTypesAccessor = AlertTypesAccessor(coreDataManager: coreDataManager)
self.alertEntriesAccessor = AlertEntriesAccessor(coreDataManager: coreDataManager)
self.calibrationsAccessor = CalibrationsAccessor(coreDataManager: coreDataManager)
self.sensorsAccessor = SensorsAccessor(coreDataManager: coreDataManager)
self.soundPlayer = soundPlayer
self.openGlückManager = openGlückManager
self.uNUserNotificationCenter = UNUserNotificationCenter.current()
self.coreDataManager = coreDataManager

Expand Down Expand Up @@ -773,18 +777,36 @@ public class AlertManager:NSObject {
let notificationRequest = UNNotificationRequest(identifier: alertKind.notificationIdentifier(), content: content, trigger: trigger)

// Add Request to User Notification Center
uNUserNotificationCenter.add(notificationRequest) { (error) in
if let error = error {
trace("Unable to Add Notification Request %{public}@", log: self.log, category: ConstantsLog.categoryAlertManager, type: .error, error.localizedDescription)
let lastBgReadingTimestamp = lastBgReading?.timeStamp
Task {
// check if current alert can be dismissed by third-party manager
switch alertKind {
case .low:
// ask openglück
if let lastBgReadingTimestamp, let openGlückManager, await openGlückManager.shouldDismissLow(at: lastBgReadingTimestamp) {
trace("OpenGlück asked to dismiss a low notification", log: self.log, category: ConstantsLog.categoryAlertManager, type: .info)
return
}
default:
// no possible dismissal
break
}
uNUserNotificationCenter.add(notificationRequest) { (error) in
if let error = error {
trace("Unable to Add Notification Request %{public}@", log: self.log, category: ConstantsLog.categoryAlertManager, type: .error, error.localizedDescription)
}
}
}

// snooze default period, to avoid that alert goes off every minute for Libre 2, except if it's a delayed alert (for delayed alerts it looks a bit risky to me)
if delayInSecondsToUse == 0 {

trace("in checkAlert, snoozing alert %{public}@ for %{public}@ minutes", log: self.log, category: ConstantsLog.categoryAlertManager, type: .info, alertKind.descriptionForLogging(), ConstantsAlerts.defaultDelayBetweenAlertsOfSameKindInMinutes.description)

getSnoozeParameters(alertKind: alertKind).snooze(snoozePeriodInMinutes: ConstantsAlerts.defaultDelayBetweenAlertsOfSameKindInMinutes)
if alertKind == .low || alertKind == .verylow {
trace("in checkAlert, deliberately NOT snoozing alert %{public}@", log: self.log, category: ConstantsLog.categoryAlertManager, type: .info, alertKind.descriptionForLogging())
} else {
trace("in checkAlert, snoozing alert %{public}@ for %{public}@ minutes", log: self.log, category: ConstantsLog.categoryAlertManager, type: .info, alertKind.descriptionForLogging(), ConstantsAlerts.defaultDelayBetweenAlertsOfSameKindInMinutes.description)

getSnoozeParameters(alertKind: alertKind).snooze(snoozePeriodInMinutes: ConstantsAlerts.defaultDelayBetweenAlertsOfSameKindInMinutes)
}

}

Expand Down
Loading