SettingsRootView.swift 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. @Environment(\.colorScheme) var colorScheme
  13. private var color: LinearGradient {
  14. colorScheme == .dark ? LinearGradient(
  15. gradient: Gradient(colors: [
  16. Color.bgDarkBlue,
  17. Color.bgDarkerDarkBlue
  18. ]),
  19. startPoint: .top,
  20. endPoint: .bottom
  21. )
  22. :
  23. LinearGradient(
  24. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  25. startPoint: .top,
  26. endPoint: .bottom
  27. )
  28. }
  29. var body: some View {
  30. Form {
  31. Section {
  32. Toggle("Closed loop", isOn: $state.closedLoop)
  33. }
  34. header: {
  35. Text(viewModel.headerText).textCase(nil)
  36. }.listRowBackground(Color.chart)
  37. Section {
  38. SettingsRowView(imageName: "chart.xyaxis.line", title: "Statistics", tint: Color.green, spacing: 10)
  39. .navigationLink(to: .statistics, from: self)
  40. } header: { Text("Statistics") }.listRowBackground(Color.chart)
  41. Section {
  42. Text("Pump").navigationLink(to: .pumpConfig, from: self)
  43. Text("CGM").navigationLink(to: .cgm, from: self)
  44. Text("Watch").navigationLink(to: .watch, from: self)
  45. } header: { Text("Devices") }.listRowBackground(Color.chart)
  46. Section {
  47. Text("Nightscout").navigationLink(to: .nighscoutConfig, from: self)
  48. NavigationLink(destination: TidepoolStartView(state: state)) {
  49. Text("Tidepool")
  50. }
  51. if HKHealthStore.isHealthDataAvailable() {
  52. Text("Apple Health").navigationLink(to: .healthkit, from: self)
  53. }
  54. Text("Notifications").navigationLink(to: .notificationsConfig, from: self)
  55. Text("Bolus Calculator").navigationLink(to: .bolusCalculatorConfig, from: self)
  56. Text("App Icons").navigationLink(to: .iconConfig, from: self)
  57. Text("Statistics and Home View").navigationLink(to: .statisticsConfig, from: self)
  58. } header: { Text("Services") }.listRowBackground(Color.chart)
  59. Section {
  60. Text("Preferences").navigationLink(to: .preferencesEditor, from: self)
  61. Text("Dynamic ISF").navigationLink(to: .dynamicISF, from: self)
  62. Text("Pump Settings").navigationLink(to: .pumpSettingsEditor, from: self)
  63. Text("Meal Settings").navigationLink(to: .fpuConfig, from: self)
  64. Text("Basal Profile").navigationLink(to: .basalProfileEditor, from: self)
  65. Text("Insulin Sensitivities").navigationLink(to: .isfEditor, from: self)
  66. Text("Carb Ratios").navigationLink(to: .crEditor, from: self)
  67. Text("Target Glucose").navigationLink(to: .targetsEditor, from: self)
  68. Text("Autotune").navigationLink(to: .autotuneConfig, from: self)
  69. } header: { Text("Configuration") }.listRowBackground(Color.chart)
  70. Section {
  71. Toggle("Debug options", isOn: $state.debugOptions)
  72. if state.debugOptions {
  73. Group {
  74. HStack {
  75. Text("NS Upload Profile and Settings")
  76. Button("Upload") { state.uploadProfileAndSettings(true) }
  77. .frame(maxWidth: .infinity, alignment: .trailing)
  78. .buttonStyle(.borderedProminent)
  79. }
  80. // Commenting this out for now, as not needed and possibly dangerous for users to be able to nuke their pump pairing informations via the debug menu
  81. // Leaving it in here, as it may be a handy functionality for further testing or developers.
  82. // See https://github.com/nightscout/Trio/pull/277 for more information
  83. //
  84. // HStack {
  85. // Text("Delete Stored Pump State Binary Files")
  86. // Button("Delete") { state.resetLoopDocuments() }
  87. // .frame(maxWidth: .infinity, alignment: .trailing)
  88. // .buttonStyle(.borderedProminent)
  89. // }
  90. }
  91. Group {
  92. Text("Preferences")
  93. .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
  94. Text("Pump Settings")
  95. .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
  96. Text("Autosense")
  97. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
  98. Text("Pump History")
  99. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
  100. Text("Basal profile")
  101. .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
  102. Text("Targets ranges")
  103. .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
  104. Text("Temp targets")
  105. .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
  106. }
  107. Group {
  108. Text("Pump profile")
  109. .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
  110. Text("Profile")
  111. .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
  112. Text("Carbs")
  113. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
  114. Text("Announcements")
  115. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
  116. Text("Enacted announcements")
  117. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
  118. Text("Autotune")
  119. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autotune), from: self)
  120. }
  121. Group {
  122. Text("Target presets")
  123. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.tempTargetsPresets), from: self)
  124. Text("Calibrations")
  125. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.calibrations), from: self)
  126. Text("Middleware")
  127. .navigationLink(to: .configEditor(file: OpenAPS.Middleware.determineBasal), from: self)
  128. Text("Statistics")
  129. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.statistics), from: self)
  130. Text("Edit settings json")
  131. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
  132. }
  133. }
  134. } header: { Text("Developer") }.listRowBackground(Color.chart)
  135. Section {
  136. HStack {
  137. Text("Share logs")
  138. .onTapGesture {
  139. showShareSheet.toggle()
  140. }
  141. Spacer()
  142. Image(systemName: "square.and.arrow.up")
  143. }
  144. }.listRowBackground(Color.chart)
  145. }.scrollContentBackground(.hidden).background(color)
  146. .sheet(isPresented: $showShareSheet) {
  147. ShareSheet(activityItems: state.logItems())
  148. }
  149. .onAppear(perform: configureView)
  150. .navigationTitle("Settings")
  151. .navigationBarTitleDisplayMode(.large)
  152. .onDisappear(perform: { state.uploadProfileAndSettings(false) })
  153. .screenNavigation(self)
  154. }
  155. }
  156. }