SettingsRootView.swift 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. HStack {
  58. Text("Delete Pump State nlist")
  59. Button("Delete") { state.resetLoopDocuments() }
  60. .frame(maxWidth: .infinity, alignment: .trailing)
  61. .buttonStyle(.borderedProminent)
  62. }
  63. }
  64. Group {
  65. Text("Preferences")
  66. .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
  67. Text("Pump Settings")
  68. .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
  69. Text("Autosense")
  70. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
  71. Text("Pump History")
  72. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
  73. Text("Basal profile")
  74. .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
  75. Text("Targets ranges")
  76. .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
  77. Text("Temp targets")
  78. .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
  79. Text("Meal")
  80. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.meal), from: self)
  81. }
  82. Group {
  83. Text("Pump profile")
  84. .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
  85. Text("Profile")
  86. .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
  87. Text("Carbs")
  88. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
  89. Text("Enacted")
  90. .navigationLink(to: .configEditor(file: OpenAPS.Enact.enacted), from: self)
  91. Text("Announcements")
  92. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
  93. Text("Enacted announcements")
  94. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
  95. Text("Autotune")
  96. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autotune), from: self)
  97. Text("Glucose")
  98. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.glucose), from: self)
  99. }
  100. Group {
  101. Text("Target presets")
  102. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.tempTargetsPresets), from: self)
  103. Text("Calibrations")
  104. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.calibrations), from: self)
  105. Text("Middleware")
  106. .navigationLink(to: .configEditor(file: OpenAPS.Middleware.determineBasal), from: self)
  107. Text("Statistics")
  108. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.statistics), from: self)
  109. Text("Edit settings json")
  110. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
  111. }
  112. }
  113. } header: { Text("Developer") }
  114. Section {
  115. Toggle("Animated Background", isOn: $state.animatedBackground)
  116. }
  117. Section {
  118. Text("Share logs")
  119. .onTapGesture {
  120. showShareSheet = true
  121. }
  122. }
  123. }
  124. .sheet(isPresented: $showShareSheet) {
  125. ShareSheet(activityItems: state.logItems())
  126. }
  127. .onAppear(perform: configureView)
  128. .navigationTitle("Settings")
  129. .navigationBarItems(leading: Button("Close", action: state.hideSettingsModal))
  130. .navigationBarTitleDisplayMode(.automatic)
  131. .onDisappear(perform: { state.uploadProfileAndSettings(false) })
  132. }
  133. }
  134. }