SettingsRootView.swift 7.3 KB

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