SettingsRootView.swift 8.2 KB

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