Skip to content

Commit

Permalink
Add OpenGlück
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Allène committed Mar 16, 2024
1 parent 3a6f4af commit 064b323
Show file tree
Hide file tree
Showing 10 changed files with 581 additions and 12 deletions.
49 changes: 47 additions & 2 deletions xdrip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
47DB06E92A715FD900267BE3 /* LibreLinkUpModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47DB06E82A715FD900267BE3 /* LibreLinkUpModels.swift */; };
47F8E95A2710255D00B8B02B /* ConstantsWatchApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47F8E9592710255C00B8B02B /* ConstantsWatchApp.swift */; };
47FB28082636B04200042FFB /* StatisticsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FB28072636B04200042FFB /* StatisticsManager.swift */; };
9D06FF5B2A76EB1600ECEA9B /* (null) in Frameworks */ = {isa = PBXBuildFile; };
9D06FF602A76EC0000ECEA9B /* DiablyLib in Frameworks */ = {isa = PBXBuildFile; productRef = 9D06FF5F2A76EC0000ECEA9B /* DiablyLib */; };
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; };
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 @@ -757,6 +763,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 @@ -1614,10 +1622,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 */,
9D06FF602A76EC0000ECEA9B /* DiablyLib in Frameworks */,
9D06FF5B2A76EB1600ECEA9B /* (null) in Frameworks */,
4779BCF42974308F00515714 /* PieCharts in Frameworks */,
4779BCF12974307700515714 /* CryptoSwift in Frameworks */,
);
Expand Down Expand Up @@ -1687,6 +1699,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 @@ -2103,6 +2123,7 @@
47DB06DB2A7136E900267BE3 /* LibreLinkUp */,
F8E51D5B2448D8A3001C9E5A /* Loop */,
F821CF4F229BF43A005C1E43 /* NightScout */,
9D67DF782A6DC339009A15DD /* OpenGlückManager */,
F64039AE281C3F8D0051EFFE /* QuickActions */,
F821CF9922AEF2DF005C1E43 /* Speak */,
47FB28052636AFE700042FFB /* Statistics */,
Expand Down Expand Up @@ -2584,6 +2605,7 @@
4752B4052635878E0081D551 /* SettingsViewStatisticsSettingsViewModel.swift */,
F8E51D6824549E2C001C9E5A /* SettingsViewTraceSettingsViewModel.swift */,
47150A3F27F6211C00DB2994 /* SettingsViewTreatmentsSettingsViewModel.swift */,
9D67DF742A6DBEDC009A15DD /* SettingsViewOpenGlückSettingsViewModel.swift */,
);
path = SettingsViewModels;
sourceTree = "<group>";
Expand Down Expand Up @@ -3268,6 +3290,8 @@
4779BCF02974307700515714 /* CryptoSwift */,
4779BCF32974308F00515714 /* PieCharts */,
470824D1297484B500C52317 /* SwiftCharts */,
9D06FF5F2A76EC0000ECEA9B /* DiablyLib */,
9D06FF612A76EC0000ECEA9B /* OG */,
);
productName = xdrip;
productReference = F8AC425A21ADEBD60078C348 /* xdrip.app */;
Expand Down Expand Up @@ -3336,6 +3360,7 @@
4779BCEC2974306300515714 /* XCRemoteSwiftPackageReference "ActionClosurable" */,
4779BCEF2974307700515714 /* XCRemoteSwiftPackageReference "CryptoSwift" */,
4779BCF22974308F00515714 /* XCRemoteSwiftPackageReference "PieCharts" */,
9D06FF5E2A76EC0000ECEA9B /* XCRemoteSwiftPackageReference "OG" */,
);
productRefGroup = F8AC425B21ADEBD60078C348 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -3624,6 +3649,7 @@
F821CF56229BF43A005C1E43 /* AlertKind.swift in Sources */,
F85DC2ED21CFE2F500B9F74A /* BgReading+CoreDataProperties.swift in Sources */,
F8A2BC0D25DB0B12001D1E78 /* Atom+BluetoothPeripheral.swift in Sources */,
9D67DF752A6DBEDC009A15DD /* SettingsViewOpenGlückSettingsViewModel.swift in Sources */,
F8F9723123A5915900C3F17D /* M5StackAuthenticateTXMessage.swift in Sources */,
F8F9721223A5915900C3F17D /* FirmwareVersionTxMessage.swift in Sources */,
F80D916824F7086D006840B5 /* Libre2BluetoothPeripheralViewModel.swift in Sources */,
Expand Down Expand Up @@ -3747,6 +3773,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 @@ -4843,7 +4870,7 @@
CURRENT_PROJECT_VERSION = "$(CURRENT_PROJECT_VERSION)";
DEVELOPMENT_TEAM = "$(XDRIP_DEVELOPMENT_TEAM)";
INFOPLIST_FILE = "$(SRCROOT)/xdrip/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -4871,7 +4898,7 @@
CURRENT_PROJECT_VERSION = "$(CURRENT_PROJECT_VERSION)";
DEVELOPMENT_TEAM = "$(XDRIP_DEVELOPMENT_TEAM)";
INFOPLIST_FILE = "$(SRCROOT)/xdrip/Supporting Files/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -4960,6 +4987,14 @@
kind = branch;
};
};
9D06FF5E2A76EC0000ECEA9B /* XCRemoteSwiftPackageReference "OG" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/callms/OG";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.0.65;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand All @@ -4983,6 +5018,16 @@
package = 4779BCF22974308F00515714 /* XCRemoteSwiftPackageReference "PieCharts" */;
productName = PieCharts;
};
9D06FF5F2A76EC0000ECEA9B /* DiablyLib */ = {
isa = XCSwiftPackageProductDependency;
package = 9D06FF5E2A76EC0000ECEA9B /* XCRemoteSwiftPackageReference "OG" */;
productName = DiablyLib;
};
9D06FF612A76EC0000ECEA9B /* OG */ = {
isa = XCSwiftPackageProductDependency;
package = 9D06FF5E2A76EC0000ECEA9B /* XCRemoteSwiftPackageReference "OG" */;
productName = OG;
};
/* End XCSwiftPackageProductDependency section */

/* Begin XCVersionGroup section */
Expand Down
9 changes: 9 additions & 0 deletions xdrip.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
"version" : "1.8.0"
}
},
{
"identity" : "og",
"kind" : "remoteSourceControl",
"location" : "https://github.com/callms/OG",
"state" : {
"revision" : "7324a2d1ce066f15e101a157bcc7cd2903004fec",
"version" : "1.0.74"
}
},
{
"identity" : "piecharts",
"kind" : "remoteSourceControl",
Expand Down
3 changes: 3 additions & 0 deletions xdrip/Constants/ConstantsLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ enum ConstantsLog {
/// healthkit manager
static let categoryHealthKitManager = "HealthKitManager "

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

/// SettingsViewHealthKitSettingsViewModel
static let categorySettingsViewHealthKitSettingsViewModel = "SettingsViewHealthKitSettingsViewModel"

Expand Down
59 changes: 59 additions & 0 deletions xdrip/Extensions/UserDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,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 @@ -1485,6 +1492,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 @@ -670,18 +674,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

0 comments on commit 064b323

Please sign in to comment.