SettingsRootView.swift 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import HealthKit
  2. import SwiftUI
  3. import Swinject
  4. extension Settings {
  5. struct RootView: BaseView {
  6. let resolver: Resolver
  7. @StateObject var state = StateModel()
  8. @State private var showShareSheet = false
  9. var body: some View {
  10. Form {
  11. Section(header: Text("FreeAPS X v\(state.buildNumber)")) {
  12. Toggle("Closed loop", isOn: $state.closedLoop)
  13. }
  14. Section(header: Text("Devices")) {
  15. Text("Pump").navigationLink(to: .pumpConfig, from: self)
  16. }
  17. Section(header: Text("Services")) {
  18. Text("Nightscout").navigationLink(to: .nighscoutConfig, from: self)
  19. Text("CGM").navigationLink(to: .cgm, from: self)
  20. if HKHealthStore.isHealthDataAvailable() {
  21. Text("Apple Health").navigationLink(to: .healthkit, from: self)
  22. }
  23. Text("Notifications").navigationLink(to: .notificationsConfig, from: self)
  24. }
  25. Section(header: Text("Configuration")) {
  26. Text("Preferences").navigationLink(to: .preferencesEditor, from: self)
  27. Text("Pump Settings").navigationLink(to: .pumpSettingsEditor, from: self)
  28. Text("Basal Profile").navigationLink(to: .basalProfileEditor, from: self)
  29. Text("Insulin Sensitivities").navigationLink(to: .isfEditor, from: self)
  30. Text("Carb Ratios").navigationLink(to: .crEditor, from: self)
  31. Text("Target Ranges").navigationLink(to: .targetsEditor, from: self)
  32. Text("Autotune").navigationLink(to: .autotuneConfig, from: self)
  33. }
  34. Section(header: Text("Developer")) {
  35. Toggle("Debug options", isOn: $state.debugOptions)
  36. if state.debugOptions {
  37. Group {
  38. Text("NS Upload Profile").onTapGesture {
  39. state.uploadProfile()
  40. }
  41. Text("NS Uploaded Profile")
  42. .navigationLink(to: .configEditor(file: OpenAPS.Nightscout.uploadedProfile), from: self)
  43. }
  44. Group {
  45. Text("Preferences")
  46. .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
  47. Text("Pump Settings")
  48. .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
  49. Text("Autosense")
  50. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
  51. Text("Pump History")
  52. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
  53. Text("Basal profile")
  54. .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
  55. Text("Targets ranges")
  56. .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
  57. Text("Carb ratios")
  58. .navigationLink(to: .configEditor(file: OpenAPS.Settings.carbRatios), from: self)
  59. Text("Insulin sensitivities")
  60. .navigationLink(to: .configEditor(file: OpenAPS.Settings.insulinSensitivities), from: self)
  61. Text("Temp targets")
  62. .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
  63. Text("Meal")
  64. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.meal), from: self)
  65. }
  66. Group {
  67. Text("IOB")
  68. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.iob), from: self)
  69. Text("Pump profile")
  70. .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
  71. Text("Profile")
  72. .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
  73. Text("Glucose")
  74. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.glucose), from: self)
  75. Text("Carbs")
  76. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
  77. Text("Suggested")
  78. .navigationLink(to: .configEditor(file: OpenAPS.Enact.suggested), from: self)
  79. Text("Enacted")
  80. .navigationLink(to: .configEditor(file: OpenAPS.Enact.enacted), from: self)
  81. Text("Announcements")
  82. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
  83. Text("Enacted announcements")
  84. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
  85. Text("Autotune")
  86. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autotune), from: self)
  87. }
  88. Group {
  89. Text("CGM Events")
  90. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.cgmState), from: self)
  91. Text("Uploaded CGM Events")
  92. .navigationLink(to: .configEditor(file: OpenAPS.Nightscout.uploadedCGMState), from: self)
  93. }
  94. Group {
  95. Text("Alerts")
  96. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.alertHistory), from: self)
  97. Text("Target presets")
  98. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.tempTargetsPresets), from: self)
  99. Text("Calibrations")
  100. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.calibrations), from: self)
  101. Text("Current Temp")
  102. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.tempBasal), from: self)
  103. Text("Middleware")
  104. .navigationLink(to: .configEditor(file: OpenAPS.Middleware.determineBasal), from: self)
  105. Text("TDD")
  106. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.tdd), from: self)
  107. Text("Statistics")
  108. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.dailyStats), from: self)
  109. Text("Loop Cycles")
  110. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.loopStats), from: self)
  111. Text("Edit settings json")
  112. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
  113. }
  114. }
  115. }
  116. Section {
  117. Toggle("Animated Background", isOn: $state.animatedBackground)
  118. }
  119. Section {
  120. Text("Share logs")
  121. .onTapGesture {
  122. showShareSheet = true
  123. }
  124. }
  125. }
  126. .sheet(isPresented: $showShareSheet) {
  127. ShareSheet(activityItems: state.logItems())
  128. }
  129. .onAppear(perform: configureView)
  130. .navigationTitle("Settings")
  131. .navigationBarItems(leading: Button("Close", action: state.hideSettingsModal))
  132. .navigationBarTitleDisplayMode(.automatic)
  133. }
  134. }
  135. }