SettingsRootView.swift 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. HStack(spacing: 15) {
  30. Image(systemName: "circle")
  31. .imageScale(.small)
  32. .font(.system(size: 32))
  33. .foregroundColor(Color.green)
  34. Toggle("Closed loop", isOn: $state.closedLoop)
  35. .font(.subheadline)
  36. .foregroundStyle(.primary)
  37. }
  38. } header: {
  39. Text(
  40. "iAPS v\(state.versionNumber) (\(state.buildNumber))\nBranch: \(state.branch) \(state.copyrightNotice)\nBuild Expires: \(Bundle.main.profileExpiration)"
  41. )
  42. .textCase(nil)
  43. }.listRowBackground(Color.chart)
  44. Section {
  45. SettingsRowView(imageName: "chart.xyaxis.line", title: "Statistics", tint: Color.green, spacing: 10)
  46. .navigationLink(to: .statistics, from: self)
  47. } header: { Text("Statistics") }.listRowBackground(Color.chart)
  48. Section {
  49. SettingsRowViewCustomImage(imageName: "pod", title: "Pump")
  50. .navigationLink(to: .pumpConfig, from: self)
  51. SettingsRowViewCustomImage(imageName: "g6", title: "CGM")
  52. .navigationLink(to: .cgm, from: self)
  53. SettingsRowView(imageName: "applewatch.watchface", title: "Watch", tint: Color.primary, spacing: 18)
  54. .navigationLink(to: .watch, from: self)
  55. } header: { Text("Select Devices") }.listRowBackground(Color.chart)
  56. Section {
  57. SettingsRowViewCustomImage(imageName: "owl", title: "Nightscout", frame: 32)
  58. .navigationLink(to: .nighscoutConfig, from: self)
  59. if HKHealthStore.isHealthDataAvailable() {
  60. SettingsRowView(imageName: "heart.circle.fill", title: "Apple Health", tint: Color.red)
  61. .navigationLink(to: .healthkit, from: self)
  62. }
  63. SettingsRowView(imageName: "message.circle.fill", title: "Notifications", tint: Color.blue)
  64. .navigationLink(to: .notificationsConfig, from: self)
  65. } header: { Text("Services") }.listRowBackground(Color.chart)
  66. Section {
  67. SettingsRowViewCustomImage(imageName: "pod", title: "Pump Settings")
  68. .navigationLink(to: .pumpSettingsEditor, from: self)
  69. SettingsRowView(imageName: "chart.bar.xaxis", title: "Basal Profile", tint: Color.insulin, spacing: 10)
  70. .navigationLink(to: .basalProfileEditor, from: self)
  71. SettingsRowView(imageName: "drop.fill", title: "Insulin Sensitivities", tint: Color.insulin, spacing: 22)
  72. .navigationLink(to: .isfEditor, from: self)
  73. SettingsRowView(imageName: "fork.knife.circle", title: "Carb Ratios", tint: Color.orange, spacing: 14)
  74. .navigationLink(to: .crEditor, from: self)
  75. SettingsRowView(imageName: "target", title: "Target Glucose", tint: Color.green, spacing: 14)
  76. .navigationLink(to: .targetsEditor, from: self)
  77. } header: { Text("Configuration") }.listRowBackground(Color.chart)
  78. Section {
  79. Text("OpenAPS").navigationLink(to: .preferencesEditor, from: self)
  80. Text("Autotune").navigationLink(to: .autotuneConfig, from: self)
  81. } header: { Text("OpenAPS") }.listRowBackground(Color.chart)
  82. Section {
  83. Text("UI/UX").navigationLink(to: .statisticsConfig, from: self)
  84. Text("App Icons").navigationLink(to: .iconConfig, from: self)
  85. Text("Bolus Calculator").navigationLink(to: .bolusCalculatorConfig, from: self)
  86. Text("Fat And Protein Conversion").navigationLink(to: .fpuConfig, from: self)
  87. Text("Dynamic ISF").navigationLink(to: .dynamicISF, from: self)
  88. } header: { Text("Extra Features") }.listRowBackground(Color.chart)
  89. Section {
  90. Toggle("Debug options", isOn: $state.debugOptions)
  91. if state.debugOptions {
  92. Group {
  93. HStack {
  94. Text("NS Upload Profile and Settings")
  95. Button("Upload") { state.uploadProfileAndSettings(true) }
  96. .frame(maxWidth: .infinity, alignment: .trailing)
  97. .buttonStyle(.borderedProminent)
  98. }
  99. }
  100. Group {
  101. Text("Preferences")
  102. .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
  103. Text("Pump Settings")
  104. .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
  105. Text("Autosense")
  106. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
  107. Text("Pump History")
  108. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
  109. Text("Basal profile")
  110. .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
  111. Text("Targets ranges")
  112. .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
  113. Text("Temp targets")
  114. .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
  115. Text("Meal")
  116. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.meal), from: self)
  117. }
  118. Group {
  119. Text("Pump profile")
  120. .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
  121. Text("Profile")
  122. .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
  123. Text("Carbs")
  124. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
  125. Text("Announcements")
  126. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
  127. Text("Enacted announcements")
  128. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
  129. Text("Autotune")
  130. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autotune), from: self)
  131. }
  132. Group {
  133. Text("Target presets")
  134. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.tempTargetsPresets), from: self)
  135. Text("Calibrations")
  136. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.calibrations), from: self)
  137. Text("Middleware")
  138. .navigationLink(to: .configEditor(file: OpenAPS.Middleware.determineBasal), from: self)
  139. Text("Statistics")
  140. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.statistics), from: self)
  141. Text("Edit settings json")
  142. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
  143. }
  144. }
  145. } header: { Text("Developer") }.listRowBackground(Color.chart)
  146. Section {
  147. Toggle("Animated Background", isOn: $state.animatedBackground)
  148. }.listRowBackground(Color.chart)
  149. Section {
  150. Text("Share logs")
  151. .onTapGesture {
  152. showShareSheet = true
  153. }
  154. }.listRowBackground(Color.chart)
  155. }.scrollContentBackground(.hidden).background(color)
  156. .sheet(isPresented: $showShareSheet) {
  157. ShareSheet(activityItems: state.logItems())
  158. }
  159. .onAppear(perform: configureView)
  160. .navigationTitle("Menu")
  161. .navigationBarTitleDisplayMode(.large)
  162. .onDisappear(perform: { state.uploadProfileAndSettings(false) })
  163. }
  164. }
  165. }