TrioSettings.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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", table: "ShortcutsDetail")
  10. case .limitBolusMax:
  11. return String(localized: "Max bolus", table: "ShortcutsDetail")
  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 useAlarmSound: Bool = false
  36. var addSourceInfoToGlucoseNotifications: Bool = false
  37. var lowGlucose: Decimal = 72
  38. var highGlucose: Decimal = 270
  39. var carbsRequiredThreshold: Decimal = 10
  40. var showCarbsRequiredBadge: Bool = true
  41. var useFPUconversion: Bool = true
  42. var totalInsulinDisplayType: TotalInsulinDisplayType = .totalDailyDose
  43. var individualAdjustmentFactor: Decimal = 0.5
  44. var timeCap: Int = 8
  45. var minuteInterval: Int = 30
  46. var delay: Int = 60
  47. var useAppleHealth: Bool = false
  48. var smoothGlucose: Bool = false
  49. var hbA1cDisplayUnit: HbA1cDisplayUnit = .percent
  50. var high: Decimal = 180
  51. var low: Decimal = 70
  52. var hours: Int = 6
  53. var glucoseColorScheme: GlucoseColorScheme = .staticColor
  54. var xGridLines: Bool = true
  55. var yGridLines: Bool = true
  56. var timeInRangeChartStyle: TimeInRangeChartStyle = .vertical
  57. var rulerMarks: Bool = true
  58. var forecastDisplayType: ForecastDisplayType = .cone
  59. var maxCarbs: Decimal = 250
  60. var maxFat: Decimal = 250
  61. var maxProtein: Decimal = 250
  62. var confirmBolusFaster: Bool = false
  63. var overrideFactor: Decimal = 0.8
  64. var fattyMeals: Bool = false
  65. var fattyMealFactor: Decimal = 0.7
  66. var sweetMeals: Bool = false
  67. var sweetMealFactor: Decimal = 1
  68. var displayPresets: Bool = true
  69. var confirmBolus: ConfirmBolus = .veryLowGlucose
  70. var useLiveActivity: Bool = false
  71. var lockScreenView: LockScreenView = .simple
  72. var bolusShortcut: BolusShortcutLimit = .notAllowed
  73. }
  74. extension TrioSettings: Decodable {
  75. // Needed to decode incomplete JSON
  76. init(from decoder: Decoder) throws {
  77. let container = try decoder.container(keyedBy: CodingKeys.self)
  78. var settings = TrioSettings()
  79. if let units = try? container.decode(GlucoseUnits.self, forKey: .units) {
  80. settings.units = units
  81. }
  82. if let closedLoop = try? container.decode(Bool.self, forKey: .closedLoop) {
  83. settings.closedLoop = closedLoop
  84. }
  85. if let isUploadEnabled = try? container.decode(Bool.self, forKey: .isUploadEnabled) {
  86. settings.isUploadEnabled = isUploadEnabled
  87. }
  88. if let isDownloadEnabled = try? container.decode(Bool.self, forKey: .isDownloadEnabled) {
  89. settings.isDownloadEnabled = isDownloadEnabled
  90. }
  91. if let useLocalGlucoseSource = try? container.decode(Bool.self, forKey: .useLocalGlucoseSource) {
  92. settings.useLocalGlucoseSource = useLocalGlucoseSource
  93. }
  94. if let localGlucosePort = try? container.decode(Int.self, forKey: .localGlucosePort) {
  95. settings.localGlucosePort = localGlucosePort
  96. }
  97. if let debugOptions = try? container.decode(Bool.self, forKey: .debugOptions) {
  98. settings.debugOptions = debugOptions
  99. }
  100. if let cgm = try? container.decode(CGMType.self, forKey: .cgm) {
  101. settings.cgm = cgm
  102. }
  103. if let cgmPluginIdentifier = try? container.decode(String.self, forKey: .cgmPluginIdentifier) {
  104. settings.cgmPluginIdentifier = cgmPluginIdentifier
  105. }
  106. if let uploadGlucose = try? container.decode(Bool.self, forKey: .uploadGlucose) {
  107. settings.uploadGlucose = uploadGlucose
  108. }
  109. if let useCalendar = try? container.decode(Bool.self, forKey: .useCalendar) {
  110. settings.useCalendar = useCalendar
  111. }
  112. if let displayCalendarIOBandCOB = try? container.decode(Bool.self, forKey: .displayCalendarIOBandCOB) {
  113. settings.displayCalendarIOBandCOB = displayCalendarIOBandCOB
  114. }
  115. if let displayCalendarEmojis = try? container.decode(Bool.self, forKey: .displayCalendarEmojis) {
  116. settings.displayCalendarEmojis = displayCalendarEmojis
  117. }
  118. if let useAppleHealth = try? container.decode(Bool.self, forKey: .useAppleHealth) {
  119. settings.useAppleHealth = useAppleHealth
  120. }
  121. if let glucoseBadge = try? container.decode(Bool.self, forKey: .glucoseBadge) {
  122. settings.glucoseBadge = glucoseBadge
  123. }
  124. if let useFPUconversion = try? container.decode(Bool.self, forKey: .useFPUconversion) {
  125. settings.useFPUconversion = useFPUconversion
  126. }
  127. if let totalInsulinDisplayType = try? container.decode(TotalInsulinDisplayType.self, forKey: .totalInsulinDisplayType) {
  128. settings.totalInsulinDisplayType = totalInsulinDisplayType
  129. }
  130. if let individualAdjustmentFactor = try? container.decode(Decimal.self, forKey: .individualAdjustmentFactor) {
  131. settings.individualAdjustmentFactor = individualAdjustmentFactor
  132. }
  133. if let fattyMeals = try? container.decode(Bool.self, forKey: .fattyMeals) {
  134. settings.fattyMeals = fattyMeals
  135. }
  136. if let fattyMealFactor = try? container.decode(Decimal.self, forKey: .fattyMealFactor) {
  137. settings.fattyMealFactor = fattyMealFactor
  138. }
  139. if let sweetMeals = try? container.decode(Bool.self, forKey: .sweetMeals) {
  140. settings.sweetMeals = sweetMeals
  141. }
  142. if let sweetMealFactor = try? container.decode(Decimal.self, forKey: .sweetMealFactor) {
  143. settings.sweetMealFactor = sweetMealFactor
  144. }
  145. if let overrideFactor = try? container.decode(Decimal.self, forKey: .overrideFactor) {
  146. settings.overrideFactor = overrideFactor
  147. }
  148. if let timeCap = try? container.decode(Int.self, forKey: .timeCap) {
  149. settings.timeCap = timeCap
  150. }
  151. if let minuteInterval = try? container.decode(Int.self, forKey: .minuteInterval) {
  152. settings.minuteInterval = minuteInterval
  153. }
  154. if let delay = try? container.decode(Int.self, forKey: .delay) {
  155. settings.delay = delay
  156. }
  157. if let notificationsPump = try? container.decode(Bool.self, forKey: .notificationsPump) {
  158. settings.notificationsPump = notificationsPump
  159. }
  160. if let notificationsCgm = try? container.decode(Bool.self, forKey: .notificationsCgm) {
  161. settings.notificationsCgm = notificationsCgm
  162. }
  163. if let notificationsCarb = try? container.decode(Bool.self, forKey: .notificationsCarb) {
  164. settings.notificationsCarb = notificationsCarb
  165. }
  166. if let notificationsAlgorithm = try? container.decode(Bool.self, forKey: .notificationsAlgorithm) {
  167. settings.notificationsAlgorithm = notificationsAlgorithm
  168. }
  169. if let glucoseNotificationsOption = try? container.decode(
  170. GlucoseNotificationsOption.self,
  171. forKey: .glucoseNotificationsOption
  172. ) {
  173. settings.glucoseNotificationsOption = glucoseNotificationsOption
  174. }
  175. if let useAlarmSound = try? container.decode(Bool.self, forKey: .useAlarmSound) {
  176. settings.useAlarmSound = useAlarmSound
  177. }
  178. if let addSourceInfoToGlucoseNotifications = try? container.decode(
  179. Bool.self,
  180. forKey: .addSourceInfoToGlucoseNotifications
  181. ) {
  182. settings.addSourceInfoToGlucoseNotifications = addSourceInfoToGlucoseNotifications
  183. }
  184. if let lowGlucose = try? container.decode(Decimal.self, forKey: .lowGlucose) {
  185. settings.lowGlucose = lowGlucose
  186. }
  187. if let highGlucose = try? container.decode(Decimal.self, forKey: .highGlucose) {
  188. settings.highGlucose = highGlucose
  189. }
  190. if let carbsRequiredThreshold = try? container.decode(Decimal.self, forKey: .carbsRequiredThreshold) {
  191. settings.carbsRequiredThreshold = carbsRequiredThreshold
  192. }
  193. if let showCarbsRequiredBadge = try? container.decode(Bool.self, forKey: .showCarbsRequiredBadge) {
  194. settings.showCarbsRequiredBadge = showCarbsRequiredBadge
  195. }
  196. if let smoothGlucose = try? container.decode(Bool.self, forKey: .smoothGlucose) {
  197. settings.smoothGlucose = smoothGlucose
  198. }
  199. if let low = try? container.decode(Decimal.self, forKey: .low) {
  200. settings.low = low
  201. }
  202. if let high = try? container.decode(Decimal.self, forKey: .high) {
  203. settings.high = high
  204. }
  205. if let hours = try? container.decode(Int.self, forKey: .hours) {
  206. settings.hours = hours
  207. }
  208. if let glucoseColorScheme = try? container.decode(GlucoseColorScheme.self, forKey: .glucoseColorScheme) {
  209. settings.glucoseColorScheme = glucoseColorScheme
  210. }
  211. if let xGridLines = try? container.decode(Bool.self, forKey: .xGridLines) {
  212. settings.xGridLines = xGridLines
  213. }
  214. if let yGridLines = try? container.decode(Bool.self, forKey: .yGridLines) {
  215. settings.yGridLines = yGridLines
  216. }
  217. if let timeInRangeChartStyle = try? container.decode(TimeInRangeChartStyle.self, forKey: .timeInRangeChartStyle) {
  218. settings.timeInRangeChartStyle = timeInRangeChartStyle
  219. }
  220. if let rulerMarks = try? container.decode(Bool.self, forKey: .rulerMarks) {
  221. settings.rulerMarks = rulerMarks
  222. }
  223. if let forecastDisplayType = try? container.decode(ForecastDisplayType.self, forKey: .forecastDisplayType) {
  224. settings.forecastDisplayType = forecastDisplayType
  225. }
  226. if let hbA1cDisplayUnit = try? container.decode(HbA1cDisplayUnit.self, forKey: .hbA1cDisplayUnit) {
  227. settings.hbA1cDisplayUnit = hbA1cDisplayUnit
  228. }
  229. if let maxCarbs = try? container.decode(Decimal.self, forKey: .maxCarbs) {
  230. settings.maxCarbs = maxCarbs
  231. }
  232. if let maxFat = try? container.decode(Decimal.self, forKey: .maxFat) {
  233. settings.maxFat = maxFat
  234. }
  235. if let maxProtein = try? container.decode(Decimal.self, forKey: .maxProtein) {
  236. settings.maxProtein = maxProtein
  237. }
  238. if let confirmBolusFaster = try? container.decode(Bool.self, forKey: .confirmBolusFaster) {
  239. settings.confirmBolusFaster = confirmBolusFaster
  240. }
  241. if let displayPresets = try? container.decode(Bool.self, forKey: .displayPresets) {
  242. settings.displayPresets = displayPresets
  243. }
  244. if let confirmBolus = try? container.decode(ConfirmBolus.self, forKey: .confirmBolus) {
  245. settings.confirmBolus = confirmBolus
  246. }
  247. if let useLiveActivity = try? container.decode(Bool.self, forKey: .useLiveActivity) {
  248. settings.useLiveActivity = useLiveActivity
  249. }
  250. if let lockScreenView = try? container.decode(LockScreenView.self, forKey: .lockScreenView) {
  251. settings.lockScreenView = lockScreenView
  252. }
  253. if let bolusShortcut = try? container.decode(BolusShortcutLimit.self, forKey: .bolusShortcut) {
  254. settings.bolusShortcut = bolusShortcut
  255. }
  256. self = settings
  257. }
  258. }