TrioSettings.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import Foundation
  2. enum BolusShortcutLimit: String, JSON, CaseIterable, Identifiable {
  3. var id: String { rawValue }
  4. case notAllowed
  5. case limitBolusMax
  6. var displayName: String {
  7. switch self {
  8. case .notAllowed:
  9. return String(localized: "Not allowed")
  10. case .limitBolusMax:
  11. return String(localized: "Max bolus")
  12. }
  13. }
  14. }
  15. struct TrioSettings: JSON, Equatable {
  16. var units: GlucoseUnits = .mgdL
  17. var closedLoop: Bool = false
  18. var isUploadEnabled: Bool = false
  19. var isDownloadEnabled: Bool = false
  20. var useLocalGlucoseSource: Bool = false
  21. var localGlucosePort: Int = 8080
  22. var debugOptions: Bool = false
  23. var cgm: CGMType = .none
  24. var cgmPluginIdentifier: String = ""
  25. var uploadGlucose: Bool = true
  26. var useCalendar: Bool = false
  27. var displayCalendarIOBandCOB: Bool = false
  28. var displayCalendarEmojis: Bool = false
  29. var glucoseBadge: Bool = false
  30. var notificationsPump: Bool = true
  31. var notificationsCgm: Bool = true
  32. var notificationsCarb: Bool = true
  33. var notificationsAlgorithm: Bool = true
  34. var glucoseNotificationsOption: GlucoseNotificationsOption = .onlyAlarmLimits
  35. var addSourceInfoToGlucoseNotifications: Bool = false
  36. var lowGlucose: Decimal = 72
  37. var highGlucose: Decimal = 270
  38. var carbsRequiredThreshold: Decimal = 10
  39. var showCarbsRequiredBadge: Bool = true
  40. var useFPUconversion: Bool = true
  41. var individualAdjustmentFactor: Decimal = 0.5
  42. var timeCap: Int = 8
  43. var minuteInterval: Int = 30
  44. var delay: Int = 60
  45. var useAppleHealth: Bool = false
  46. var smoothGlucose: Bool = false
  47. var eA1cDisplayUnit: EstimatedA1cDisplayUnit = .percent
  48. var high: Decimal = 180
  49. var low: Decimal = 70
  50. var hours: Int = 6
  51. var glucoseColorScheme: GlucoseColorScheme = .staticColor
  52. var xGridLines: Bool = true
  53. var yGridLines: Bool = true
  54. var rulerMarks: Bool = true
  55. var forecastDisplayType: ForecastDisplayType = .cone
  56. var maxCarbs: Decimal = 250
  57. var maxFat: Decimal = 250
  58. var maxProtein: Decimal = 250
  59. var confirmBolusFaster: Bool = false
  60. var overrideFactor: Decimal = 0.8
  61. var fattyMeals: Bool = false
  62. var fattyMealFactor: Decimal = 0.7
  63. var sweetMeals: Bool = false
  64. var sweetMealFactor: Decimal = 1
  65. var displayPresets: Bool = true
  66. var useLiveActivity: Bool = false
  67. var lockScreenView: LockScreenView = .simple
  68. var bolusShortcut: BolusShortcutLimit = .notAllowed
  69. }
  70. extension TrioSettings: Decodable {
  71. // Needed to decode incomplete JSON
  72. init(from decoder: Decoder) throws {
  73. let container = try decoder.container(keyedBy: CodingKeys.self)
  74. var settings = TrioSettings()
  75. if let units = try? container.decode(GlucoseUnits.self, forKey: .units) {
  76. settings.units = units
  77. }
  78. if let closedLoop = try? container.decode(Bool.self, forKey: .closedLoop) {
  79. settings.closedLoop = closedLoop
  80. }
  81. if let isUploadEnabled = try? container.decode(Bool.self, forKey: .isUploadEnabled) {
  82. settings.isUploadEnabled = isUploadEnabled
  83. }
  84. if let isDownloadEnabled = try? container.decode(Bool.self, forKey: .isDownloadEnabled) {
  85. settings.isDownloadEnabled = isDownloadEnabled
  86. }
  87. if let useLocalGlucoseSource = try? container.decode(Bool.self, forKey: .useLocalGlucoseSource) {
  88. settings.useLocalGlucoseSource = useLocalGlucoseSource
  89. }
  90. if let localGlucosePort = try? container.decode(Int.self, forKey: .localGlucosePort) {
  91. settings.localGlucosePort = localGlucosePort
  92. }
  93. if let debugOptions = try? container.decode(Bool.self, forKey: .debugOptions) {
  94. settings.debugOptions = debugOptions
  95. }
  96. if let cgm = try? container.decode(CGMType.self, forKey: .cgm) {
  97. settings.cgm = cgm
  98. }
  99. if let cgmPluginIdentifier = try? container.decode(String.self, forKey: .cgmPluginIdentifier) {
  100. settings.cgmPluginIdentifier = cgmPluginIdentifier
  101. }
  102. if let uploadGlucose = try? container.decode(Bool.self, forKey: .uploadGlucose) {
  103. settings.uploadGlucose = uploadGlucose
  104. }
  105. if let useCalendar = try? container.decode(Bool.self, forKey: .useCalendar) {
  106. settings.useCalendar = useCalendar
  107. }
  108. if let displayCalendarIOBandCOB = try? container.decode(Bool.self, forKey: .displayCalendarIOBandCOB) {
  109. settings.displayCalendarIOBandCOB = displayCalendarIOBandCOB
  110. }
  111. if let displayCalendarEmojis = try? container.decode(Bool.self, forKey: .displayCalendarEmojis) {
  112. settings.displayCalendarEmojis = displayCalendarEmojis
  113. }
  114. if let useAppleHealth = try? container.decode(Bool.self, forKey: .useAppleHealth) {
  115. settings.useAppleHealth = useAppleHealth
  116. }
  117. if let glucoseBadge = try? container.decode(Bool.self, forKey: .glucoseBadge) {
  118. settings.glucoseBadge = glucoseBadge
  119. }
  120. if let useFPUconversion = try? container.decode(Bool.self, forKey: .useFPUconversion) {
  121. settings.useFPUconversion = useFPUconversion
  122. }
  123. if let individualAdjustmentFactor = try? container.decode(Decimal.self, forKey: .individualAdjustmentFactor) {
  124. settings.individualAdjustmentFactor = individualAdjustmentFactor
  125. }
  126. if let fattyMeals = try? container.decode(Bool.self, forKey: .fattyMeals) {
  127. settings.fattyMeals = fattyMeals
  128. }
  129. if let fattyMealFactor = try? container.decode(Decimal.self, forKey: .fattyMealFactor) {
  130. settings.fattyMealFactor = fattyMealFactor
  131. }
  132. if let sweetMeals = try? container.decode(Bool.self, forKey: .sweetMeals) {
  133. settings.sweetMeals = sweetMeals
  134. }
  135. if let sweetMealFactor = try? container.decode(Decimal.self, forKey: .sweetMealFactor) {
  136. settings.sweetMealFactor = sweetMealFactor
  137. }
  138. if let overrideFactor = try? container.decode(Decimal.self, forKey: .overrideFactor) {
  139. settings.overrideFactor = overrideFactor
  140. }
  141. if let timeCap = try? container.decode(Int.self, forKey: .timeCap) {
  142. settings.timeCap = timeCap
  143. }
  144. if let minuteInterval = try? container.decode(Int.self, forKey: .minuteInterval) {
  145. settings.minuteInterval = minuteInterval
  146. }
  147. if let delay = try? container.decode(Int.self, forKey: .delay) {
  148. settings.delay = delay
  149. }
  150. if let notificationsPump = try? container.decode(Bool.self, forKey: .notificationsPump) {
  151. settings.notificationsPump = notificationsPump
  152. }
  153. if let notificationsCgm = try? container.decode(Bool.self, forKey: .notificationsCgm) {
  154. settings.notificationsCgm = notificationsCgm
  155. }
  156. if let notificationsCarb = try? container.decode(Bool.self, forKey: .notificationsCarb) {
  157. settings.notificationsCarb = notificationsCarb
  158. }
  159. if let notificationsAlgorithm = try? container.decode(Bool.self, forKey: .notificationsAlgorithm) {
  160. settings.notificationsAlgorithm = notificationsAlgorithm
  161. }
  162. if let glucoseNotificationsOption = try? container.decode(
  163. GlucoseNotificationsOption.self,
  164. forKey: .glucoseNotificationsOption
  165. ) {
  166. settings.glucoseNotificationsOption = glucoseNotificationsOption
  167. }
  168. if let addSourceInfoToGlucoseNotifications = try? container.decode(
  169. Bool.self,
  170. forKey: .addSourceInfoToGlucoseNotifications
  171. ) {
  172. settings.addSourceInfoToGlucoseNotifications = addSourceInfoToGlucoseNotifications
  173. }
  174. if let lowGlucose = try? container.decode(Decimal.self, forKey: .lowGlucose) {
  175. settings.lowGlucose = lowGlucose
  176. }
  177. if let highGlucose = try? container.decode(Decimal.self, forKey: .highGlucose) {
  178. settings.highGlucose = highGlucose
  179. }
  180. if let carbsRequiredThreshold = try? container.decode(Decimal.self, forKey: .carbsRequiredThreshold) {
  181. settings.carbsRequiredThreshold = carbsRequiredThreshold
  182. }
  183. if let showCarbsRequiredBadge = try? container.decode(Bool.self, forKey: .showCarbsRequiredBadge) {
  184. settings.showCarbsRequiredBadge = showCarbsRequiredBadge
  185. }
  186. if let smoothGlucose = try? container.decode(Bool.self, forKey: .smoothGlucose) {
  187. settings.smoothGlucose = smoothGlucose
  188. }
  189. if let low = try? container.decode(Decimal.self, forKey: .low) {
  190. settings.low = low
  191. }
  192. if let high = try? container.decode(Decimal.self, forKey: .high) {
  193. settings.high = high
  194. }
  195. if let hours = try? container.decode(Int.self, forKey: .hours) {
  196. settings.hours = hours
  197. }
  198. if let glucoseColorScheme = try? container.decode(GlucoseColorScheme.self, forKey: .glucoseColorScheme) {
  199. settings.glucoseColorScheme = glucoseColorScheme
  200. }
  201. if let xGridLines = try? container.decode(Bool.self, forKey: .xGridLines) {
  202. settings.xGridLines = xGridLines
  203. }
  204. if let yGridLines = try? container.decode(Bool.self, forKey: .yGridLines) {
  205. settings.yGridLines = yGridLines
  206. }
  207. if let rulerMarks = try? container.decode(Bool.self, forKey: .rulerMarks) {
  208. settings.rulerMarks = rulerMarks
  209. }
  210. if let forecastDisplayType = try? container.decode(ForecastDisplayType.self, forKey: .forecastDisplayType) {
  211. settings.forecastDisplayType = forecastDisplayType
  212. }
  213. if let eA1cDisplayUnit = try? container.decode(EstimatedA1cDisplayUnit.self, forKey: .eA1cDisplayUnit) {
  214. settings.eA1cDisplayUnit = eA1cDisplayUnit
  215. }
  216. if let maxCarbs = try? container.decode(Decimal.self, forKey: .maxCarbs) {
  217. settings.maxCarbs = maxCarbs
  218. }
  219. if let maxFat = try? container.decode(Decimal.self, forKey: .maxFat) {
  220. settings.maxFat = maxFat
  221. }
  222. if let maxProtein = try? container.decode(Decimal.self, forKey: .maxProtein) {
  223. settings.maxProtein = maxProtein
  224. }
  225. if let confirmBolusFaster = try? container.decode(Bool.self, forKey: .confirmBolusFaster) {
  226. settings.confirmBolusFaster = confirmBolusFaster
  227. }
  228. if let displayPresets = try? container.decode(Bool.self, forKey: .displayPresets) {
  229. settings.displayPresets = displayPresets
  230. }
  231. if let useLiveActivity = try? container.decode(Bool.self, forKey: .useLiveActivity) {
  232. settings.useLiveActivity = useLiveActivity
  233. }
  234. if let lockScreenView = try? container.decode(LockScreenView.self, forKey: .lockScreenView) {
  235. settings.lockScreenView = lockScreenView
  236. }
  237. if let bolusShortcut = try? container.decode(BolusShortcutLimit.self, forKey: .bolusShortcut) {
  238. settings.bolusShortcut = bolusShortcut
  239. }
  240. self = settings
  241. }
  242. }