SettingsRootView.swift 10.0 KB

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