SettingsRootView.swift 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import HealthKit
  2. import LoopKit
  3. import LoopKitUI
  4. import SwiftUI
  5. import Swinject
  6. extension Settings {
  7. struct RootView: BaseView {
  8. let resolver: Resolver
  9. @StateObject var state = StateModel()
  10. @State private var showShareSheet = false
  11. @StateObject private var viewModel = SettingsRootViewModel()
  12. var body: some View {
  13. Form {
  14. Section {
  15. Toggle("Closed loop", isOn: $state.closedLoop)
  16. }
  17. header: {
  18. Text(viewModel.headerText).textCase(nil)
  19. }
  20. Section {
  21. Text("Pump").navigationLink(to: .pumpConfig, from: self)
  22. Text("CGM").navigationLink(to: .cgm, from: self)
  23. Text("Watch").navigationLink(to: .watch, from: self)
  24. } header: { Text("Devices") }
  25. Section {
  26. Text("Nightscout").navigationLink(to: .nighscoutConfig, from: self)
  27. Text("TidePool")
  28. .onTapGesture {
  29. state.setupTidePool = true
  30. }
  31. if HKHealthStore.isHealthDataAvailable() {
  32. Text("Apple Health").navigationLink(to: .healthkit, from: self)
  33. }
  34. Text("Notifications").navigationLink(to: .notificationsConfig, from: self)
  35. Text("Meal Settings").navigationLink(to: .fpuConfig, from: self)
  36. Text("App Icons").navigationLink(to: .iconConfig, from: self)
  37. Text("Statistics and Home View").navigationLink(to: .statisticsConfig, from: self)
  38. } header: { Text("Services") }
  39. Section {
  40. Text("Preferences").navigationLink(to: .preferencesEditor, from: self)
  41. Text("Pump Settings").navigationLink(to: .pumpSettingsEditor, from: self)
  42. Text("Basal Profile").navigationLink(to: .basalProfileEditor, from: self)
  43. Text("Insulin Sensitivities").navigationLink(to: .isfEditor, from: self)
  44. Text("Carb Ratios").navigationLink(to: .crEditor, from: self)
  45. Text("Target Glucose").navigationLink(to: .targetsEditor, from: self)
  46. Text("Autotune").navigationLink(to: .autotuneConfig, from: self)
  47. } header: { Text("Configuration") }
  48. Section {
  49. Toggle("Debug options", isOn: $state.debugOptions)
  50. if state.debugOptions {
  51. Group {
  52. HStack {
  53. Text("NS Upload Profile and Settings")
  54. Button("Upload") { state.uploadProfileAndSettings(true) }
  55. .frame(maxWidth: .infinity, alignment: .trailing)
  56. .buttonStyle(.borderedProminent)
  57. }
  58. }
  59. Group {
  60. Text("Preferences")
  61. .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
  62. Text("Pump Settings")
  63. .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
  64. Text("Autosense")
  65. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
  66. Text("Pump History")
  67. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
  68. Text("Basal profile")
  69. .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
  70. Text("Targets ranges")
  71. .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
  72. Text("Temp targets")
  73. .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
  74. Text("Meal")
  75. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.meal), from: self)
  76. }
  77. Group {
  78. Text("Pump profile")
  79. .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
  80. Text("Profile")
  81. .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
  82. Text("Carbs")
  83. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
  84. Text("Enacted")
  85. .navigationLink(to: .configEditor(file: OpenAPS.Enact.enacted), from: self)
  86. Text("Announcements")
  87. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
  88. Text("Enacted announcements")
  89. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
  90. Text("Autotune")
  91. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autotune), from: self)
  92. Text("Glucose")
  93. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.glucose), from: self)
  94. }
  95. Group {
  96. Text("Target presets")
  97. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.tempTargetsPresets), from: self)
  98. Text("Calibrations")
  99. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.calibrations), from: self)
  100. Text("Middleware")
  101. .navigationLink(to: .configEditor(file: OpenAPS.Middleware.determineBasal), from: self)
  102. Text("Statistics")
  103. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.statistics), from: self)
  104. Text("Edit settings json")
  105. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
  106. }
  107. }
  108. } header: { Text("Developer") }
  109. Section {
  110. Toggle("Animated Background", isOn: $state.animatedBackground)
  111. }
  112. Section {
  113. Text("Share logs")
  114. .onTapGesture {
  115. showShareSheet = true
  116. }
  117. }
  118. }
  119. .sheet(isPresented: $showShareSheet) {
  120. ShareSheet(activityItems: state.logItems())
  121. }
  122. .sheet(isPresented: $state.setupTidePool) {
  123. if let serviceUIType = state.serviceUIType,
  124. let pluginHost = state.provider.tidePoolManager.getTidePoolPluginHost()
  125. {
  126. if let serviceUI = state.provider.tidePoolManager.getTidePoolServiceUI() {
  127. TidePoolSettingsView(
  128. serviceUI: serviceUI,
  129. serviceOnBoardDelegate: self.state,
  130. serviceDelegate: self.state
  131. )
  132. } else {
  133. TidePoolSetupView(
  134. serviceUIType: serviceUIType,
  135. pluginHost: pluginHost,
  136. serviceOnBoardDelegate: self.state,
  137. serviceDelegate: self.state
  138. )
  139. }
  140. }
  141. }
  142. .onAppear(perform: configureView)
  143. .navigationTitle("Settings")
  144. .navigationBarItems(leading: Button("Close", action: state.hideSettingsModal))
  145. .navigationBarTitleDisplayMode(.automatic)
  146. .onDisappear(perform: { state.uploadProfileAndSettings(false) })
  147. }
  148. }
  149. }