| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import Combine
- import SwiftUI
- import Swinject
- import UIKit
- extension RemoteControlConfig {
- struct RootView: BaseView {
- let resolver: Resolver
- @StateObject var state = StateModel()
- @State private var shouldDisplayHint: Bool = false
- @State var hintDetent = PresentationDetent.large
- @State var selectedVerboseHint: String?
- @State var hintLabel: String?
- @State private var decimalPlaceholder: Decimal = 0.0
- @State private var isCopied: Bool = false
- @Environment(\.colorScheme) var colorScheme
- @Environment(AppState.self) var appState
- var body: some View {
- Form {
- SettingInputSection(
- decimalValue: $decimalPlaceholder,
- booleanValue: $state.isTrioRemoteControlEnabled,
- shouldDisplayHint: $shouldDisplayHint,
- selectedVerboseHint: Binding(
- get: { selectedVerboseHint },
- set: {
- selectedVerboseHint = $0
- hintLabel = "Enable Remote Command"
- }
- ),
- units: state.units,
- type: .boolean,
- label: "Enable Remote Control",
- miniHint: "Remote Control allow Trio to receive instructions, such as boluses and temp targets, from LoopFollow.",
- 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.",
- headerText: "Trio Remote Control"
- )
- Section(
- header: Text("Shared Secret"),
- content: {
- TextField("Enter Shared Secret", text: $state.sharedSecret)
- .disableAutocorrection(true)
- .autocapitalization(.none)
- .padding(8)
- .background(Color(UIColor.systemGray6))
- .cornerRadius(8)
- Button(action: {
- UIPasteboard.general.string = state.sharedSecret
- isCopied = true
- }) {
- Label("Copy Secret", systemImage: "doc.on.doc")
- .frame(maxWidth: .infinity)
- }
- .buttonStyle(.bordered)
- .frame(maxWidth: .infinity)
- .alert(isPresented: $isCopied) {
- Alert(
- title: Text("Copied"),
- message: Text("Shared Secret copied to clipboard"),
- dismissButton: .default(Text("OK"))
- )
- }
- Button(action: {
- state.generateNewSharedSecret()
- }) {
- Label("Generate Secret", systemImage: "arrow.clockwise")
- .frame(maxWidth: .infinity)
- }
- .buttonStyle(.borderedProminent)
- .foregroundColor(.white)
- .frame(maxWidth: .infinity)
- }
- ).listRowBackground(Color.chart)
- }
- .sheet(isPresented: $shouldDisplayHint) {
- SettingInputHintView(
- hintDetent: $hintDetent,
- shouldDisplayHint: $shouldDisplayHint,
- hintLabel: hintLabel ?? "",
- hintText: selectedVerboseHint ?? "",
- sheetTitle: "Help"
- )
- }
- .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
- .onAppear(perform: configureView)
- .navigationTitle("Remote Control")
- .navigationBarTitleDisplayMode(.automatic)
- }
- }
- }
|