RemoteControlConfig.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import Combine
  2. import SwiftUI
  3. import Swinject
  4. import UIKit
  5. extension RemoteControlConfig {
  6. struct RootView: BaseView {
  7. let resolver: Resolver
  8. @StateObject var state = StateModel()
  9. @State private var shouldDisplayHint: Bool = false
  10. @State var hintDetent = PresentationDetent.large
  11. @State var selectedVerboseHint: String?
  12. @State var hintLabel: String?
  13. @State private var decimalPlaceholder: Decimal = 0.0
  14. @State private var isCopied: Bool = false
  15. @Environment(\.colorScheme) var colorScheme
  16. private var color: LinearGradient {
  17. colorScheme == .dark ? LinearGradient(
  18. gradient: Gradient(colors: [
  19. Color.bgDarkBlue,
  20. Color.bgDarkerDarkBlue
  21. ]),
  22. startPoint: .top,
  23. endPoint: .bottom
  24. )
  25. :
  26. LinearGradient(
  27. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  28. startPoint: .top,
  29. endPoint: .bottom
  30. )
  31. }
  32. var body: some View {
  33. Form {
  34. SettingInputSection(
  35. decimalValue: $decimalPlaceholder,
  36. booleanValue: $state.isTRCEnabled,
  37. shouldDisplayHint: $shouldDisplayHint,
  38. selectedVerboseHint: Binding(
  39. get: { selectedVerboseHint },
  40. set: {
  41. selectedVerboseHint = $0
  42. hintLabel = "Enable Remote Command"
  43. }
  44. ),
  45. units: state.units,
  46. type: .boolean,
  47. label: "Enable Remote Command",
  48. miniHint: "Remote commands allow Trio to receive instructions, such as boluses and temp targets, from LoopFollow.",
  49. verboseHint: "When Remote Commands are enabled, you can send boluses, temporary targets, carbs, and other commands to Trio via push notifications. To ensure security, these commands are protected by a shared secret, which must be entered in LoopFollow."
  50. )
  51. Section(
  52. header: Text("Shared Secret"),
  53. content: {
  54. TextField("Enter Shared Secret", text: $state.sharedSecret)
  55. .disableAutocorrection(true)
  56. .autocapitalization(.none)
  57. .padding(8)
  58. .background(Color(UIColor.systemGray6))
  59. .cornerRadius(8)
  60. Button(action: {
  61. UIPasteboard.general.string = state.sharedSecret
  62. isCopied = true
  63. }) {
  64. Label("Copy Secret", systemImage: "doc.on.doc")
  65. .frame(maxWidth: .infinity)
  66. }
  67. .buttonStyle(.bordered)
  68. .frame(maxWidth: .infinity)
  69. .alert(isPresented: $isCopied) {
  70. Alert(
  71. title: Text("Copied"),
  72. message: Text("Shared Secret copied to clipboard"),
  73. dismissButton: .default(Text("OK"))
  74. )
  75. }
  76. Button(action: {
  77. state.generateNewSharedSecret()
  78. }) {
  79. Label("Generate Secret", systemImage: "arrow.clockwise")
  80. .frame(maxWidth: .infinity)
  81. }
  82. .buttonStyle(.borderedProminent)
  83. .foregroundColor(.white)
  84. .frame(maxWidth: .infinity)
  85. }
  86. ).listRowBackground(Color.chart)
  87. }
  88. .sheet(isPresented: $shouldDisplayHint) {
  89. SettingInputHintView(
  90. hintDetent: $hintDetent,
  91. shouldDisplayHint: $shouldDisplayHint,
  92. hintLabel: hintLabel ?? "",
  93. hintText: selectedVerboseHint ?? "",
  94. sheetTitle: "Help"
  95. )
  96. }
  97. .scrollContentBackground(.hidden).background(color)
  98. .onAppear(perform: configureView)
  99. .navigationTitle("Remote Control")
  100. .navigationBarTitleDisplayMode(.automatic)
  101. }
  102. }
  103. }