RemoteContentView.swift 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // LoopFollow
  2. // RemoteContentView.swift
  3. import SwiftUI
  4. struct RemoteContentView: View {
  5. @ObservedObject private var device = Storage.shared.device
  6. @ObservedObject private var remoteType = Storage.shared.remoteType
  7. var body: some View {
  8. Group {
  9. switch remoteType.value {
  10. case .nightscout:
  11. if device.value == "Trio" {
  12. TrioNightscoutRemoteView()
  13. } else {
  14. NoRemoteView()
  15. }
  16. case .trc:
  17. if device.value == "Trio" {
  18. TrioRemoteControlView(viewModel: TrioRemoteControlViewModel())
  19. } else {
  20. Text("Trio Remote Control is only supported for 'Trio'")
  21. }
  22. case .loopAPNS:
  23. LoopAPNSRemoteView()
  24. case .none:
  25. Text("Please select a Remote Type in Settings.")
  26. }
  27. }
  28. .onAppear {
  29. verifyNightscoutAuth()
  30. }
  31. }
  32. private func verifyNightscoutAuth() {
  33. guard remoteType.value == .nightscout, !Storage.shared.nsWriteAuth.value else { return }
  34. NightscoutUtils.verifyURLAndToken { _, _, nsWriteAuth, nsAdminAuth in
  35. DispatchQueue.main.async {
  36. Storage.shared.nsWriteAuth.value = nsWriteAuth
  37. Storage.shared.nsAdminAuth.value = nsAdminAuth
  38. }
  39. }
  40. }
  41. }