RemoteControlConfig.swift 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. @Environment(AppState.self) var appState
  17. var body: some View {
  18. Form {
  19. SettingInputSection(
  20. decimalValue: $decimalPlaceholder,
  21. booleanValue: $state.isTrioRemoteControlEnabled,
  22. shouldDisplayHint: $shouldDisplayHint,
  23. selectedVerboseHint: Binding(
  24. get: { selectedVerboseHint },
  25. set: {
  26. selectedVerboseHint = $0
  27. hintLabel = "Enable Remote Command"
  28. }
  29. ),
  30. units: state.units,
  31. type: .boolean,
  32. label: "Enable Remote Control",
  33. miniHint: "Remote Control allow Trio to receive instructions, such as boluses and temp targets, from LoopFollow.",
  34. verboseHint: "When Remote Control is enabled, you can send boluses, overrides, 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.",
  35. headerText: "Trio Remote Control"
  36. )
  37. Section(
  38. header: Text("Shared Secret"),
  39. content: {
  40. TextField("Enter Shared Secret", text: $state.sharedSecret)
  41. .disableAutocorrection(true)
  42. .autocapitalization(.none)
  43. .padding(8)
  44. .background(Color(UIColor.systemGray6))
  45. .cornerRadius(8)
  46. Button(action: {
  47. UIPasteboard.general.string = state.sharedSecret
  48. isCopied = true
  49. }) {
  50. Label("Copy Secret", systemImage: "doc.on.doc")
  51. .frame(maxWidth: .infinity)
  52. }
  53. .buttonStyle(.bordered)
  54. .frame(maxWidth: .infinity)
  55. .alert(isPresented: $isCopied) {
  56. Alert(
  57. title: Text("Copied"),
  58. message: Text("Shared Secret copied to clipboard"),
  59. dismissButton: .default(Text("OK"))
  60. )
  61. }
  62. Button(action: {
  63. state.generateNewSharedSecret()
  64. }) {
  65. Label("Generate Secret", systemImage: "arrow.clockwise")
  66. .frame(maxWidth: .infinity)
  67. }
  68. .buttonStyle(.borderedProminent)
  69. .foregroundColor(.white)
  70. .frame(maxWidth: .infinity)
  71. }
  72. ).listRowBackground(Color.chart)
  73. }
  74. .sheet(isPresented: $shouldDisplayHint) {
  75. SettingInputHintView(
  76. hintDetent: $hintDetent,
  77. shouldDisplayHint: $shouldDisplayHint,
  78. hintLabel: hintLabel ?? "",
  79. hintText: selectedVerboseHint ?? "",
  80. sheetTitle: "Help"
  81. )
  82. }
  83. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  84. .onAppear(perform: configureView)
  85. .navigationTitle("Remote Control")
  86. .navigationBarTitleDisplayMode(.automatic)
  87. }
  88. }
  89. }