SettingsRootView.swift 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. NavigationLink(destination: TidepoolStartView(state: state)) {
  28. Text("Tidepool")
  29. }
  30. if HKHealthStore.isHealthDataAvailable() {
  31. Text("Apple Health").navigationLink(to: .healthkit, from: self)
  32. }
  33. Text("Notifications").navigationLink(to: .notificationsConfig, from: self)
  34. Text("App Icons").navigationLink(to: .iconConfig, from: self)
  35. Text("Statistics and Home View").navigationLink(to: .statisticsConfig, from: self)
  36. } header: { Text("Services") }
  37. Section {
  38. Text("Preferences").navigationLink(to: .preferencesEditor, from: self)
  39. Text("Pump Settings").navigationLink(to: .pumpSettingsEditor, from: self)
  40. Text("Meal Settings").navigationLink(to: .fpuConfig, from: self)
  41. Text("Basal Profile").navigationLink(to: .basalProfileEditor, from: self)
  42. Text("Insulin Sensitivities").navigationLink(to: .isfEditor, from: self)
  43. Text("Carb Ratios").navigationLink(to: .crEditor, from: self)
  44. Text("Target Glucose").navigationLink(to: .targetsEditor, from: self)
  45. Text("Autotune").navigationLink(to: .autotuneConfig, from: self)
  46. } header: { Text("Configuration") }
  47. Section {
  48. Toggle("Debug options", isOn: $state.debugOptions)
  49. if state.debugOptions {
  50. Group {
  51. HStack {
  52. Text("NS Upload Profile and Settings")
  53. Button("Upload") { state.uploadProfileAndSettings(true) }
  54. .frame(maxWidth: .infinity, alignment: .trailing)
  55. .buttonStyle(.borderedProminent)
  56. }
  57. // 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
  58. // Leaving it in here, as it may be a handy functionality for further testing or developers.
  59. // See https://github.com/nightscout/Trio/pull/277 for more information
  60. //
  61. // HStack {
  62. // Text("Delete Stored Pump State Binary Files")
  63. // Button("Delete") { state.resetLoopDocuments() }
  64. // .frame(maxWidth: .infinity, alignment: .trailing)
  65. // .buttonStyle(.borderedProminent)
  66. // }
  67. }
  68. Group {
  69. Text("Preferences")
  70. .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
  71. Text("Pump Settings")
  72. .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
  73. Text("Autosense")
  74. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
  75. Text("Pump History")
  76. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
  77. Text("Basal profile")
  78. .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
  79. Text("Targets ranges")
  80. .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
  81. Text("Temp targets")
  82. .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
  83. Text("Meal")
  84. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.meal), from: self)
  85. }
  86. Group {
  87. Text("Pump profile")
  88. .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
  89. Text("Profile")
  90. .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
  91. Text("Carbs")
  92. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
  93. Text("Enacted")
  94. .navigationLink(to: .configEditor(file: OpenAPS.Enact.enacted), from: self)
  95. Text("Announcements")
  96. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
  97. Text("Enacted announcements")
  98. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
  99. Text("Autotune")
  100. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autotune), from: self)
  101. Text("Glucose")
  102. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.glucose), from: self)
  103. }
  104. Group {
  105. Text("Target presets")
  106. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.tempTargetsPresets), from: self)
  107. Text("Calibrations")
  108. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.calibrations), from: self)
  109. Text("Middleware")
  110. .navigationLink(to: .configEditor(file: OpenAPS.Middleware.determineBasal), from: self)
  111. Text("Statistics")
  112. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.statistics), from: self)
  113. Text("Edit settings json")
  114. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
  115. }
  116. }
  117. } header: { Text("Developer") }
  118. Section {
  119. Toggle("Animated Background", isOn: $state.animatedBackground)
  120. }
  121. Section {
  122. Text("Share logs")
  123. .onTapGesture {
  124. showShareSheet = true
  125. }
  126. }
  127. }
  128. .sheet(isPresented: $showShareSheet) {
  129. ShareSheet(activityItems: state.logItems())
  130. }
  131. .onAppear(perform: configureView)
  132. .navigationTitle("Settings")
  133. .navigationBarItems(leading: Button("Close", action: state.hideSettingsModal))
  134. .navigationBarTitleDisplayMode(.automatic)
  135. .onDisappear(perform: { state.uploadProfileAndSettings(false) })
  136. }
  137. }
  138. }