SettingsRootView.swift 8.1 KB

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