SettingsRootView.swift 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. import HealthKit
  2. import SwiftUI
  3. import Swinject
  4. extension Settings {
  5. struct RootView: BaseView {
  6. let resolver: Resolver
  7. @StateObject var state = StateModel()
  8. @State private var showShareSheet = false
  9. @Environment(\.colorScheme) var colorScheme
  10. private var color: LinearGradient {
  11. colorScheme == .dark ? LinearGradient(
  12. gradient: Gradient(colors: [
  13. Color.bgDarkBlue,
  14. Color.bgDarkerDarkBlue
  15. ]),
  16. startPoint: .top,
  17. endPoint: .bottom
  18. )
  19. :
  20. LinearGradient(
  21. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  22. startPoint: .top,
  23. endPoint: .bottom
  24. )
  25. }
  26. var body: some View {
  27. Form {
  28. Section {
  29. Toggle("Closed loop", isOn: $state.closedLoop)
  30. } header: {
  31. Text(
  32. "iAPS v\(state.versionNumber) (\(state.buildNumber))\nBranch: \(state.branch) \(state.copyrightNotice) "
  33. ).textCase(nil)
  34. }.listRowBackground(Color.chart)
  35. Section {
  36. Text("Pump").navigationLink(to: .pumpConfig, from: self)
  37. Text("CGM").navigationLink(to: .cgm, from: self)
  38. Text("Watch").navigationLink(to: .watch, from: self)
  39. } header: { Text("Devices") }.listRowBackground(Color.chart)
  40. Section {
  41. Text("Nightscout").navigationLink(to: .nighscoutConfig, from: self)
  42. if HKHealthStore.isHealthDataAvailable() {
  43. Text("Apple Health").navigationLink(to: .healthkit, from: self)
  44. }
  45. Text("Notifications").navigationLink(to: .notificationsConfig, from: self)
  46. } header: { Text("Services") }.listRowBackground(Color.chart)
  47. Section {
  48. Text("Pump Settings").navigationLink(to: .pumpSettingsEditor, from: self)
  49. Text("Basal Profile").navigationLink(to: .basalProfileEditor, from: self)
  50. Text("Insulin Sensitivities").navigationLink(to: .isfEditor, from: self)
  51. Text("Carb Ratios").navigationLink(to: .crEditor, from: self)
  52. Text("Target Glucose").navigationLink(to: .targetsEditor, from: self)
  53. } header: { Text("Configuration") }.listRowBackground(Color.chart)
  54. Section {
  55. Text("OpenAPS").navigationLink(to: .preferencesEditor, from: self)
  56. Text("Autotune").navigationLink(to: .autotuneConfig, from: self)
  57. } header: { Text("OpenAPS") }.listRowBackground(Color.chart)
  58. Section {
  59. Text("UI/UX").navigationLink(to: .statisticsConfig, from: self)
  60. Text("App Icons").navigationLink(to: .iconConfig, from: self)
  61. Text("Bolus Calculator").navigationLink(to: .bolusCalculatorConfig, from: self)
  62. Text("Fat And Protein Conversion").navigationLink(to: .fpuConfig, from: self)
  63. Text("Dynamic ISF").navigationLink(to: .dynamicISF, from: self)
  64. } header: { Text("Extra Features") }.listRowBackground(Color.chart)
  65. Section {
  66. Toggle("Debug options", isOn: $state.debugOptions)
  67. if state.debugOptions {
  68. Group {
  69. HStack {
  70. Text("NS Upload Profile and Settings")
  71. Button("Upload") { state.uploadProfileAndSettings(true) }
  72. .frame(maxWidth: .infinity, alignment: .trailing)
  73. .buttonStyle(.borderedProminent)
  74. }
  75. }
  76. Group {
  77. Text("Preferences")
  78. .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
  79. Text("Pump Settings")
  80. .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
  81. Text("Autosense")
  82. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
  83. Text("Pump History")
  84. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
  85. Text("Basal profile")
  86. .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
  87. Text("Targets ranges")
  88. .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
  89. Text("Temp targets")
  90. .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
  91. Text("Meal")
  92. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.meal), from: self)
  93. }
  94. Group {
  95. Text("Pump profile")
  96. .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
  97. Text("Profile")
  98. .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
  99. Text("Carbs")
  100. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
  101. Text("Enacted")
  102. .navigationLink(to: .configEditor(file: OpenAPS.Enact.enacted), from: self)
  103. Text("Announcements")
  104. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
  105. Text("Enacted announcements")
  106. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
  107. Text("Autotune")
  108. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autotune), from: self)
  109. Text("Glucose")
  110. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.glucose), from: self)
  111. }
  112. Group {
  113. Text("Target presets")
  114. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.tempTargetsPresets), from: self)
  115. Text("Calibrations")
  116. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.calibrations), from: self)
  117. Text("Middleware")
  118. .navigationLink(to: .configEditor(file: OpenAPS.Middleware.determineBasal), from: self)
  119. Text("Statistics")
  120. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.statistics), from: self)
  121. Text("Edit settings json")
  122. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
  123. }
  124. }
  125. } header: { Text("Developer") }.listRowBackground(Color.chart)
  126. Section {
  127. Toggle("Animated Background", isOn: $state.animatedBackground)
  128. }.listRowBackground(Color.chart)
  129. Section {
  130. Text("Share logs")
  131. .onTapGesture {
  132. showShareSheet = true
  133. }
  134. }.listRowBackground(Color.chart)
  135. }.scrollContentBackground(.hidden).background(color)
  136. .sheet(isPresented: $showShareSheet) {
  137. ShareSheet(activityItems: state.logItems())
  138. }
  139. .onAppear(perform: configureView)
  140. .navigationTitle("Settings")
  141. .navigationBarTitleDisplayMode(.large)
  142. .onDisappear(perform: { state.uploadProfileAndSettings(false) })
  143. }
  144. }
  145. }