VersionUpdate.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // VersionUpdate.swift
  3. // LoopKit
  4. //
  5. // Created by Rick Pasetto on 9/8/21.
  6. // Copyright © 2021 LoopKit Authors. All rights reserved.
  7. //
  8. // Note: order is important for VersionUpdate. Later version updates are more critical than earlier ones. Do not reorder!
  9. public enum VersionUpdate: Comparable, CaseIterable {
  10. /// No version update needed.
  11. case none
  12. /// A update is available, but it is just informational (supported update).
  13. case available
  14. /// The version is unsupported; the app needs to be updated to the latest "supported" version. Not a critical update.
  15. case recommended
  16. /// The app must be updated immediately.
  17. case required
  18. }
  19. extension VersionUpdate: RawRepresentable {
  20. public typealias RawValue = String
  21. public init?(rawValue: RawValue) {
  22. switch rawValue {
  23. case "none": self = .none
  24. case "available": self = .available
  25. case "recommended": self = .recommended
  26. case "required": self = .required
  27. default: return nil
  28. }
  29. }
  30. public var rawValue: RawValue {
  31. switch self {
  32. case .none: return "none"
  33. case .available: return "available"
  34. case .recommended: return "recommended"
  35. case .required: return "required"
  36. }
  37. }
  38. }
  39. extension VersionUpdate {
  40. public static let `default` = VersionUpdate.none
  41. public var softwareUpdateAvailable: Bool { self > .none }
  42. }
  43. extension VersionUpdate {
  44. public var localizedDescription: String {
  45. switch self {
  46. case .none:
  47. return NSLocalizedString("No Update", comment: "Description of no software update needed")
  48. case .available:
  49. return NSLocalizedString("Update Available", comment: "Description of informational software update needed")
  50. case .recommended:
  51. return NSLocalizedString("Recommended Update", comment: "Description of supported software update needed")
  52. case .required:
  53. return NSLocalizedString("Critical Update", comment: "Description of critical software update needed")
  54. }
  55. }
  56. }
  57. public extension Notification.Name {
  58. static let SoftwareUpdateAvailable = Notification.Name(rawValue: "com.loopkit.Loop.SoftwareUpdateAvailable")
  59. }