@capgo/capacitor-updater 7.51.21 → 7.53.0

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 (29) hide show
  1. package/CapgoCapacitorUpdater.podspec +0 -3
  2. package/Package.swift +3 -11
  3. package/README.md +202 -67
  4. package/android/build.gradle +2 -3
  5. package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +610 -177
  6. package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +909 -196
  7. package/android/src/main/java/ee/forgr/capacitor_updater/CryptoCipher.java +53 -19
  8. package/android/src/main/java/ee/forgr/capacitor_updater/DelayUpdateUtils.java +226 -106
  9. package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +210 -58
  10. package/android/src/main/java/ee/forgr/capacitor_updater/HeadlessUpdateWorker.java +325 -0
  11. package/android/src/main/java/ee/forgr/capacitor_updater/Logger.java +63 -4
  12. package/android/src/main/java/ee/forgr/capacitor_updater/NativeUpdatePrompt.java +303 -0
  13. package/android/src/main/java/ee/forgr/capacitor_updater/Version.java +306 -0
  14. package/dist/docs.json +394 -27
  15. package/dist/esm/definitions.d.ts +220 -7
  16. package/dist/esm/definitions.js.map +1 -1
  17. package/ios/Sources/CapacitorUpdaterPlugin/AES.swift +104 -52
  18. package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +562 -187
  19. package/ios/Sources/CapacitorUpdaterPlugin/CapgoSemanticVersion.swift +162 -0
  20. package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +564 -109
  21. package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +11 -2
  22. package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +204 -93
  23. package/ios/Sources/CapacitorUpdaterPlugin/Logger.swift +75 -5
  24. package/ios/Sources/CapacitorUpdaterPlugin/NativeUpdatePrompt.swift +183 -0
  25. package/ios/Sources/CapacitorUpdaterPlugin/RedirectPolicyDelegate.swift +53 -0
  26. package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +9 -3
  27. package/ios/Sources/CapacitorUpdaterPlugin/ZipArchiveReader.swift +247 -0
  28. package/ios/Sources/CapacitorUpdaterPlugin/ZipCentralDirectory.swift +280 -0
  29. package/package.json +7 -3
@@ -0,0 +1,162 @@
1
+ /*
2
+ * This Source Code Form is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
+ */
6
+
7
+ import Foundation
8
+
9
+ /// Minimal version value used for native version comparisons.
10
+ ///
11
+ /// Parsing and ordering intentionally mirror the lenient parser of the `Version` package
12
+ /// (mrackwitz/Version 0.8.0) that this type replaces, so existing comparisons keep the same results:
13
+ /// - `MAJOR[.MINOR[.PATCH]][-PRERELEASE][+BUILD]`, numeric components are ASCII digits (leading zeros allowed).
14
+ /// - Missing minor/patch compare as `0`.
15
+ /// - A version with a prerelease is lower than the same version without one.
16
+ /// - Prerelease identifiers are compared dot by dot: numerically when both are digits, lexically otherwise.
17
+ /// - Build metadata is ignored for equality and ordering.
18
+ public struct CapgoSemanticVersion: Comparable, Hashable, CustomStringConvertible {
19
+ public enum ParseError: Error {
20
+ case invalidComponents
21
+ case invalidMajorComponent
22
+ case invalidMinorComponent
23
+ case invalidPatchComponent
24
+ }
25
+
26
+ public let major: Int
27
+ public let minor: Int?
28
+ public let patch: Int?
29
+ public let prerelease: String?
30
+ public let build: String?
31
+
32
+ public var canonicalMinor: Int { minor ?? 0 }
33
+ public var canonicalPatch: Int { patch ?? 0 }
34
+
35
+ // Same pattern as the lenient `Version` parser (including its build group quirk: no dots in build metadata).
36
+ private static let versionPattern =
37
+ "\\A([0-9]+)(?:\\.([0-9]+))?(?:\\.([0-9]+))?(?:-([0-9A-Za-z-.]+))?(?:\\+([0-9A-Za-z-]+))??\\z"
38
+ private static let versionRegex = try? NSRegularExpression(pattern: versionPattern)
39
+
40
+ public init(major: Int, minor: Int? = nil, patch: Int? = nil, prerelease: String? = nil, build: String? = nil) {
41
+ self.major = max(0, major)
42
+ self.minor = minor.map { max(0, $0) }
43
+ self.patch = patch.map { max(0, $0) }
44
+ self.prerelease = prerelease
45
+ self.build = build
46
+ }
47
+
48
+ public init(_ string: String) throws {
49
+ guard let regex = Self.versionRegex else {
50
+ throw ParseError.invalidComponents
51
+ }
52
+ let nsString = string as NSString
53
+ guard let match = regex.firstMatch(in: string, options: [], range: NSRange(location: 0, length: nsString.length)),
54
+ match.numberOfRanges == 6 else {
55
+ throw ParseError.invalidComponents
56
+ }
57
+
58
+ func group(_ index: Int) -> String? {
59
+ let range = match.range(at: index)
60
+ return range.location == NSNotFound ? nil : nsString.substring(with: range)
61
+ }
62
+
63
+ guard let major = group(1).flatMap({ Int($0) }) else {
64
+ throw ParseError.invalidMajorComponent
65
+ }
66
+ let minorComponent = group(2)
67
+ let minor = minorComponent.flatMap { Int($0) }
68
+ if minorComponent != nil && minor == nil {
69
+ throw ParseError.invalidMinorComponent
70
+ }
71
+ let patchComponent = group(3)
72
+ let patch = patchComponent.flatMap { Int($0) }
73
+ if patchComponent != nil && patch == nil {
74
+ throw ParseError.invalidPatchComponent
75
+ }
76
+
77
+ self.major = major
78
+ self.minor = minor
79
+ self.patch = patch
80
+ self.prerelease = group(4)
81
+ self.build = group(5)
82
+ }
83
+
84
+ public var description: String {
85
+ var result = "\(major)"
86
+ if let minor {
87
+ result += ".\(minor)"
88
+ }
89
+ if let patch {
90
+ result += ".\(patch)"
91
+ }
92
+ if let prerelease {
93
+ result += "-\(prerelease)"
94
+ }
95
+ if let build {
96
+ result += "+\(build)"
97
+ }
98
+ return result
99
+ }
100
+
101
+ public static func == (lhs: CapgoSemanticVersion, rhs: CapgoSemanticVersion) -> Bool {
102
+ return lhs.major == rhs.major
103
+ && lhs.canonicalMinor == rhs.canonicalMinor
104
+ && lhs.canonicalPatch == rhs.canonicalPatch
105
+ && lhs.prerelease == rhs.prerelease
106
+ }
107
+
108
+ public func hash(into hasher: inout Hasher) {
109
+ hasher.combine(major)
110
+ hasher.combine(canonicalMinor)
111
+ hasher.combine(canonicalPatch)
112
+ hasher.combine(prerelease)
113
+ }
114
+
115
+ public static func < (lhs: CapgoSemanticVersion, rhs: CapgoSemanticVersion) -> Bool {
116
+ if lhs.major != rhs.major {
117
+ return lhs.major < rhs.major
118
+ }
119
+ if lhs.canonicalMinor != rhs.canonicalMinor {
120
+ return lhs.canonicalMinor < rhs.canonicalMinor
121
+ }
122
+ if lhs.canonicalPatch != rhs.canonicalPatch {
123
+ return lhs.canonicalPatch < rhs.canonicalPatch
124
+ }
125
+
126
+ switch (lhs.prerelease, rhs.prerelease) {
127
+ case (.some, .none):
128
+ return true
129
+ case (.none, .some), (.none, .none):
130
+ return false
131
+ case let (.some(lpre), .some(rpre)):
132
+ return comparePrerelease(lpre, rpre) == .orderedAscending
133
+ }
134
+ }
135
+
136
+ private static func isNumericIdentifier(_ value: String) -> Bool {
137
+ return !value.isEmpty && value.utf8.allSatisfy { $0 >= 0x30 && $0 <= 0x39 }
138
+ }
139
+
140
+ private static func comparePrerelease(_ lhs: String, _ rhs: String) -> ComparisonResult {
141
+ let lhsComponents = lhs.components(separatedBy: ".")
142
+ let rhsComponents = rhs.components(separatedBy: ".")
143
+ if let (left, right) = zip(lhsComponents, rhsComponents).first(where: { $0.0 != $0.1 }) {
144
+ if isNumericIdentifier(left) && isNumericIdentifier(right) {
145
+ let leftValue = Int(left) ?? 0
146
+ let rightValue = Int(right) ?? 0
147
+ if leftValue == rightValue {
148
+ return .orderedSame
149
+ }
150
+ return leftValue < rightValue ? .orderedAscending : .orderedDescending
151
+ }
152
+ if left == right {
153
+ return .orderedSame
154
+ }
155
+ return left < right ? .orderedAscending : .orderedDescending
156
+ }
157
+ if lhsComponents.count != rhsComponents.count {
158
+ return lhsComponents.count < rhsComponents.count ? .orderedAscending : .orderedDescending
159
+ }
160
+ return .orderedSame
161
+ }
162
+ }