SupportUI.swift 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. ///
  30. /// Check whether the given app version for the given `bundleIdentifier` needs an update. Services should return their last result, if known.
  31. ///
  32. /// - Parameters:
  33. /// - bundleIdentifier: The host app's `bundleIdentifier` (a.k.a. `CFBundleIdentifier`) string.
  34. /// - currentVersion: The host app's current version (i.e. `CFBundleVersion`).
  35. /// - completion: The completion function to call with any success result (or `nil` if not known) or failure.
  36. func checkVersion(bundleIdentifier: String, currentVersion: String, completion: @escaping (Result<VersionUpdate?, Error>) -> Void)
  37. /// Provides screen for software update UI.
  38. ///
  39. /// - Parameters:
  40. /// - bundleIdentifier: The host app's bundle identifier (e.g. `Bundle.main.bundleIdentifier`).
  41. /// - currentVersion: The host app's current version (i.e. `CFBundleVersion`).
  42. /// - guidanceColors: Colors to use for warnings, etc.
  43. /// - openAppStore: Function to open up the App Store for the host app.
  44. /// - Returns: A view that will be opened when a software update is available from this service.
  45. func softwareUpdateView(bundleIdentifier: String,
  46. currentVersion: String,
  47. guidanceColors: GuidanceColors,
  48. openAppStore: (() -> Void)?
  49. ) -> AnyView?
  50. /// Initializes the support with the previously-serialized state.
  51. ///
  52. /// - Parameters:
  53. /// - rawState: The previously-serialized state of the support.
  54. init?(rawState: RawStateValue)
  55. /// The current, serializable state of the support.
  56. var rawState: RawStateValue { get }
  57. /// A delegate for SupportUI to use (see `SupportUIDelegate`).
  58. var delegate: SupportUIDelegate? { get set }
  59. }
  60. extension SupportUI {
  61. public var identifier: String {
  62. return Self.supportIdentifier
  63. }
  64. }