SettingsRootView.swift 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. header: Text(
  13. "FreeAPS X v\(state.versionNumber) - \(state.buildNumber) \nBranch: \(state.branch) \(state.copyrightNotice) "
  14. )
  15. ) {
  16. Toggle("Closed loop", isOn: $state.closedLoop)
  17. }
  18. Section(header: Text("Devices")) {
  19. Text("Pump").navigationLink(to: .pumpConfig, from: self)
  20. Text("CGM").navigationLink(to: .cgm, from: self)
  21. }
  22. Section(header: Text("Services")) {
  23. Text("Nightscout").navigationLink(to: .nighscoutConfig, from: self)
  24. if HKHealthStore.isHealthDataAvailable() {
  25. Text("Apple Health").navigationLink(to: .healthkit, from: self)
  26. }
  27. Text("Notifications").navigationLink(to: .notificationsConfig, from: self)
  28. Text("Fat And Protein Conversion").navigationLink(to: .fpuConfig, from: self)
  29. }
  30. Section(header: Text("Configuration")) {
  31. Text("Preferences").navigationLink(to: .preferencesEditor, from: self)
  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 Ranges").navigationLink(to: .targetsEditor, from: self)
  37. Text("Autotune").navigationLink(to: .autotuneConfig, from: self)
  38. }
  39. Section(header: Text("Developer")) {
  40. Toggle("Debug options", isOn: $state.debugOptions)
  41. if state.debugOptions {
  42. Group {
  43. Text("NS Upload Profile").onTapGesture {
  44. state.uploadProfile()
  45. }
  46. Text("NS Uploaded Profile")
  47. .navigationLink(to: .configEditor(file: OpenAPS.Nightscout.uploadedProfile), from: self)
  48. }
  49. Group {
  50. Text("Preferences")
  51. .navigationLink(to: .configEditor(file: OpenAPS.Settings.preferences), from: self)
  52. Text("Pump Settings")
  53. .navigationLink(to: .configEditor(file: OpenAPS.Settings.settings), from: self)
  54. Text("Autosense")
  55. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autosense), from: self)
  56. Text("Pump History")
  57. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.pumpHistory), from: self)
  58. Text("Basal profile")
  59. .navigationLink(to: .configEditor(file: OpenAPS.Settings.basalProfile), from: self)
  60. Text("Targets ranges")
  61. .navigationLink(to: .configEditor(file: OpenAPS.Settings.bgTargets), from: self)
  62. Text("Temp targets")
  63. .navigationLink(to: .configEditor(file: OpenAPS.Settings.tempTargets), from: self)
  64. Text("Meal")
  65. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.meal), from: self)
  66. }
  67. Group {
  68. Text("Pump profile")
  69. .navigationLink(to: .configEditor(file: OpenAPS.Settings.pumpProfile), from: self)
  70. Text("Profile")
  71. .navigationLink(to: .configEditor(file: OpenAPS.Settings.profile), from: self)
  72. Text("Carbs")
  73. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.carbHistory), from: self)
  74. Text("Enacted")
  75. .navigationLink(to: .configEditor(file: OpenAPS.Enact.enacted), from: self)
  76. Text("Announcements")
  77. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcements), from: self)
  78. Text("Enacted announcements")
  79. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.announcementsEnacted), from: self)
  80. Text("Autotune")
  81. .navigationLink(to: .configEditor(file: OpenAPS.Settings.autotune), from: self)
  82. Text("Glucose")
  83. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.glucose), from: self)
  84. }
  85. Group {
  86. Text("Target presets")
  87. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.tempTargetsPresets), from: self)
  88. Text("Calibrations")
  89. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.calibrations), from: self)
  90. Text("Middleware")
  91. .navigationLink(to: .configEditor(file: OpenAPS.Middleware.determineBasal), from: self)
  92. Text("Statistics")
  93. .navigationLink(to: .configEditor(file: OpenAPS.Monitor.statistics), from: self)
  94. Text("Edit settings json")
  95. .navigationLink(to: .configEditor(file: OpenAPS.FreeAPS.settings), from: self)
  96. }
  97. }
  98. }
  99. Section {
  100. Toggle("Animated Background", isOn: $state.animatedBackground)
  101. }
  102. Section {
  103. Text("Share logs")
  104. .onTapGesture {
  105. showShareSheet = true
  106. }
  107. }
  108. }
  109. .sheet(isPresented: $showShareSheet) {
  110. ShareSheet(activityItems: state.logItems())
  111. }
  112. .onAppear(perform: configureView)
  113. .navigationTitle("Settings")
  114. .navigationBarItems(leading: Button("Close", action: state.hideSettingsModal))
  115. .navigationBarTitleDisplayMode(.automatic)
  116. }
  117. }
  118. }