SettingsRootView.swift 7.6 KB

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