SupportUI.swift 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // SupportUI.swift
  3. // LoopKitUI
  4. //
  5. // Created by Darin Krauss on 12/10/20.
  6. // Copyright © 2020 LoopKit Authors. All rights reserved.
  7. //
  8. import SwiftUI
  9. import HealthKit
  10. import LoopKit
  11. public protocol SupportInfoProvider {
  12. var pumpStatus: PumpManagerStatus? { get }
  13. var cgmStatus: CGMManagerStatus? { get }
  14. var localizedAppNameAndVersion: String { get }
  15. func generateIssueReport(completion: @escaping (String) -> Void)
  16. }
  17. public protocol SupportUIDelegate: AlertIssuer { }
  18. public protocol SupportUI: AnyObject {
  19. typealias RawStateValue = [String: Any]
  20. /// The unique identifier of this type of support.
  21. static var supportIdentifier: String { get }
  22. /// Provides support menu item.
  23. ///
  24. /// - Parameters:
  25. /// - supportInfoProvider: A provider of additional support information.
  26. /// - urlHandler: A handler to open any URLs.
  27. /// - Returns: A view that will be used in a support menu for providing user support.
  28. func supportMenuItem(supportInfoProvider: SupportInfoProvider, urlHandler: @escaping (URL) -> Void) -> AnyView?
  29. /// Provides configuration menu items.
  30. ///
  31. /// - Parameters:
  32. /// - supportInfoProvider: A provider of additional support information.
  33. /// - urlHandler: A handler to open any URLs.
  34. /// - Returns: An array of views that will be added to the configuration section of settings.
  35. func configurationMenuItems() -> [AnyView]
  36. ///
  37. /// Check whether the given app version for the given `bundleIdentifier` needs an update. Services should return their last result, if known.
  38. ///
  39. /// - Parameters:
  40. /// - bundleIdentifier: The host app's `bundleIdentifier` (a.k.a. `CFBundleIdentifier`) string.
  41. /// - currentVersion: The host app's current version (i.e. `CFBundleVersion`).
  42. /// - completion: The completion function to call with any success result (or `nil` if not known) or failure.
  43. func checkVersion(bundleIdentifier: String, currentVersion: String, completion: @escaping (Result<VersionUpdate?, Error>) -> Void)
  44. /// Provides screen for software update UI.
  45. ///
  46. /// - Parameters:
  47. /// - bundleIdentifier: The host app's bundle identifier (e.g. `Bundle.main.bundleIdentifier`).
  48. /// - currentVersion: The host app's current version (i.e. `CFBundleVersion`).
  49. /// - guidanceColors: Colors to use for warnings, etc.
  50. /// - openAppStore: Function to open up the App Store for the host app.
  51. /// - Returns: A view that will be opened when a software update is available from this service.
  52. func softwareUpdateView(bundleIdentifier: String,
  53. currentVersion: String,
  54. guidanceColors: GuidanceColors,
  55. openAppStore: (() -> Void)?
  56. ) -> AnyView?
  57. /// Initializes the support with the previously-serialized state.
  58. ///
  59. /// - Parameters:
  60. /// - rawState: The previously-serialized state of the support.
  61. init?(rawState: RawStateValue)
  62. /// The current, serializable state of the support.
  63. var rawState: RawStateValue { get }
  64. /// A delegate for SupportUI to use (see `SupportUIDelegate`).
  65. var delegate: SupportUIDelegate? { get set }
  66. }
  67. extension SupportUI {
  68. public var identifier: String {
  69. return Self.supportIdentifier
  70. }
  71. }