@capgo/capacitor-updater 9.0.1 → 9.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/README.md +106 -81
  2. package/android/build.gradle +1 -3
  3. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +513 -21
  4. package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +675 -34
  5. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +82 -10
  6. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadWorkerManager.java +23 -0
  7. package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +188 -4
  8. package/android/src/main/java/ee/forgr/capacitor_updater/Http3.java +81 -1
  9. package/android/src/main/java/ee/forgr/capacitor_updater/HttpEngineTransport.java +72 -21
  10. package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +5 -1
  11. package/dist/docs.json +13 -13
  12. package/dist/esm/definitions.d.ts +57 -23
  13. package/dist/esm/definitions.js.map +1 -1
  14. package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +1278 -107
  15. package/ios/Sources/CapacitorUpdaterPlugin/CapgoSemanticVersion.swift +38 -0
  16. package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +583 -56
  17. package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +8 -1
  18. package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +6 -1
  19. package/ios/Tests/CapacitorUpdaterPluginTests/CapacitorUpdaterPluginTests.swift +2705 -77
  20. package/ios/Tests/CapacitorUpdaterPluginTests/ChecksumRequiredTests.swift +9 -4
  21. package/ios/Tests/CapacitorUpdaterPluginTests/CliCryptoFixtureTests.swift +67 -2
  22. package/ios/Tests/CapacitorUpdaterPluginTests/HttpsOnlyBuiltinMinimumTests.swift +130 -5
  23. package/ios/Tests/CapacitorUpdaterPluginTests/NetworkTransportTests.swift +22 -8
  24. package/ios/Tests/CapacitorUpdaterPluginTests/SessionKeyRequiredTests.swift +4 -0
  25. package/ios/Tests/CapacitorUpdaterPluginTests/UpdateLifecycleTests.swift +19 -3
  26. package/package.json +2 -2
@@ -81,6 +81,44 @@ public struct CapgoSemanticVersion: Comparable, Hashable, CustomStringConvertibl
81
81
  self.build = group(5)
82
82
  }
83
83
 
84
+ /// Compares only `MAJOR.MINOR.PATCH` of two version strings, with numeric components of any length
85
+ /// (no `Int` limit). Prerelease and build parts are ignored, missing minor/patch count as `0`, and extra
86
+ /// components (a `2.0.0.4` native version) are ignored, like Android's floor parser.
87
+ /// Returns nil when either string does not start with a digit.
88
+ static func compareNumericCore(_ lhs: String, _ rhs: String) -> ComparisonResult? {
89
+ guard let left = numericCore(lhs), let right = numericCore(rhs) else {
90
+ return nil
91
+ }
92
+ for (leftComponent, rightComponent) in zip(left, right) where leftComponent != rightComponent {
93
+ if leftComponent.count != rightComponent.count {
94
+ return leftComponent.count < rightComponent.count ? .orderedAscending : .orderedDescending
95
+ }
96
+ return leftComponent < rightComponent ? .orderedAscending : .orderedDescending
97
+ }
98
+ return .orderedSame
99
+ }
100
+
101
+ /// Major, minor and patch digit strings without leading zeros (missing components are "0"). Mirrors Android's
102
+ /// `parseCoreVersionComponents`: drop build metadata and whitespace, cut the prerelease at the first `-`, then
103
+ /// read the leading digits of the first three dot-separated tokens. This is deliberately looser than the public
104
+ /// version grammar, so native overrides such as `2.0.0.4` still get a floor instead of skipping it.
105
+ private static func numericCore(_ string: String) -> [String]? {
106
+ let withoutBuild = string.split(separator: "+", maxSplits: 1, omittingEmptySubsequences: false).first ?? ""
107
+ let compact = withoutBuild.filter { !$0.isWhitespace }
108
+ guard let first = compact.first, first.isASCII, first.isNumber else {
109
+ return nil
110
+ }
111
+ let core = compact.split(separator: "-", maxSplits: 1, omittingEmptySubsequences: false).first ?? ""
112
+ let tokens = core.split(separator: ".", omittingEmptySubsequences: false)
113
+ return (0..<3).map { index in
114
+ guard index < tokens.count else {
115
+ return "0"
116
+ }
117
+ let digits = tokens[index].prefix { $0.isASCII && $0.isNumber }.drop { $0 == "0" }
118
+ return digits.isEmpty ? "0" : String(digits)
119
+ }
120
+ }
121
+
84
122
  public var description: String {
85
123
  var result = "\(major)"
86
124
  if let minor {