@capgo/capacitor-updater 8.51.17 → 8.51.19
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.
- package/README.md +50 -41
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +1 -1
- package/dist/docs.json +4 -4
- package/dist/esm/definitions.d.ts +12 -9
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +4 -3
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +13 -3
- package/ios/Sources/CapacitorUpdaterPlugin/CryptoCipher.swift +30 -37
- package/ios/Sources/CapacitorUpdaterPlugin/DelayUpdateUtils.swift +16 -41
- package/ios/Sources/CapacitorUpdaterPlugin/ShakeMenu.swift +2 -2
- package/package.json +1 -1
|
@@ -161,49 +161,43 @@ public struct CryptoCipher {
|
|
|
161
161
|
let bufferSize = checksumBufferBytes()
|
|
162
162
|
var sha256 = SHA256()
|
|
163
163
|
|
|
164
|
+
let fileHandle: FileHandle
|
|
164
165
|
do {
|
|
165
|
-
|
|
166
|
+
fileHandle = try FileHandle(forReadingFrom: filePath)
|
|
167
|
+
} catch {
|
|
168
|
+
logger.error("Cannot open file for checksum calculation")
|
|
169
|
+
logger.debug("Path: \(filePath.path), Error: \(error)")
|
|
170
|
+
return ""
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
defer {
|
|
166
174
|
do {
|
|
167
|
-
|
|
175
|
+
try fileHandle.close()
|
|
168
176
|
} catch {
|
|
169
|
-
logger.error("
|
|
170
|
-
logger.debug("
|
|
171
|
-
return ""
|
|
177
|
+
logger.error("Error closing file during checksum")
|
|
178
|
+
logger.debug("Error: \(error)")
|
|
172
179
|
}
|
|
180
|
+
}
|
|
173
181
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
182
|
+
while autoreleasepool(invoking: {
|
|
183
|
+
let fileData: Data
|
|
184
|
+
do {
|
|
185
|
+
fileData = try fileHandle.read(upToCount: bufferSize) ?? Data()
|
|
186
|
+
} catch {
|
|
187
|
+
logger.error("Error reading file during checksum")
|
|
188
|
+
logger.debug("Error: \(error)")
|
|
189
|
+
return false
|
|
181
190
|
}
|
|
182
191
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
return false
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if fileData.count > 0 {
|
|
194
|
-
sha256.update(data: fileData)
|
|
195
|
-
return true // Continue
|
|
196
|
-
} else {
|
|
197
|
-
return false // End of file
|
|
198
|
-
}
|
|
199
|
-
}) {}
|
|
192
|
+
if fileData.count > 0 {
|
|
193
|
+
sha256.update(data: fileData)
|
|
194
|
+
return true // Continue
|
|
195
|
+
} else {
|
|
196
|
+
return false // End of file
|
|
197
|
+
}
|
|
198
|
+
}) {}
|
|
200
199
|
|
|
201
|
-
|
|
202
|
-
} catch {
|
|
203
|
-
logger.error("Cannot calculate checksum")
|
|
204
|
-
logger.debug("Path: \(filePath.path), Error: \(error)")
|
|
205
|
-
return ""
|
|
206
|
-
}
|
|
200
|
+
return hexString(from: sha256)
|
|
207
201
|
}
|
|
208
202
|
|
|
209
203
|
final class RunningChecksum {
|
|
@@ -222,8 +216,7 @@ public struct CryptoCipher {
|
|
|
222
216
|
}
|
|
223
217
|
|
|
224
218
|
static func hexString(from sha256: SHA256) -> String {
|
|
225
|
-
|
|
226
|
-
return copy.finalize().compactMap { String(format: "%02x", $0) }.joined()
|
|
219
|
+
return sha256.finalize().compactMap { String(format: "%02x", $0) }.joined()
|
|
227
220
|
}
|
|
228
221
|
|
|
229
222
|
static func shortPathKey(_ fileName: String) -> String {
|
|
@@ -151,59 +151,34 @@ public class DelayUpdateUtils {
|
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
public func setMultiDelay(delayConditions: String) -> Bool {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return true
|
|
159
|
-
} catch {
|
|
160
|
-
logger.error("Failed to delay update, [Error calling 'setMultiDelay()']: \(error)")
|
|
161
|
-
return false
|
|
162
|
-
}
|
|
154
|
+
UserDefaults.standard.set(delayConditions, forKey: DelayUpdateUtils.DELAY_CONDITION_PREFERENCES)
|
|
155
|
+
UserDefaults.standard.synchronize()
|
|
156
|
+
logger.info("Delay update saved")
|
|
157
|
+
return true
|
|
163
158
|
}
|
|
164
159
|
|
|
165
160
|
public func setBackgroundTimestamp(_ backgroundTimestamp: Int64) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
logger.info("Background timestamp saved")
|
|
170
|
-
} catch {
|
|
171
|
-
logger.error("Failed to save background timestamp, [Error calling 'setBackgroundTimestamp()']: \(error)")
|
|
172
|
-
}
|
|
161
|
+
UserDefaults.standard.set(backgroundTimestamp, forKey: DelayUpdateUtils.BACKGROUND_TIMESTAMP_KEY)
|
|
162
|
+
UserDefaults.standard.synchronize()
|
|
163
|
+
logger.info("Background timestamp saved")
|
|
173
164
|
}
|
|
174
165
|
|
|
175
166
|
public func unsetBackgroundTimestamp() {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
logger.info("Background timestamp removed")
|
|
180
|
-
} catch {
|
|
181
|
-
// swiftlint:disable:next line_length
|
|
182
|
-
logger.error("Failed to remove background timestamp, [Error calling 'unsetBackgroundTimestamp()']: \(error)")
|
|
183
|
-
}
|
|
167
|
+
UserDefaults.standard.removeObject(forKey: DelayUpdateUtils.BACKGROUND_TIMESTAMP_KEY)
|
|
168
|
+
UserDefaults.standard.synchronize()
|
|
169
|
+
logger.info("Background timestamp removed")
|
|
184
170
|
}
|
|
185
171
|
|
|
186
172
|
private func getBackgroundTimestamp() -> Int64 {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
let timestamp = UserDefaults.standard.object(forKey: key) as? Int64 ?? 0
|
|
190
|
-
return timestamp
|
|
191
|
-
} catch {
|
|
192
|
-
logger.error("Failed to get background timestamp, [Error calling 'getBackgroundTimestamp()']: \(error)")
|
|
193
|
-
return 0
|
|
194
|
-
}
|
|
173
|
+
let key = DelayUpdateUtils.BACKGROUND_TIMESTAMP_KEY
|
|
174
|
+
return UserDefaults.standard.object(forKey: key) as? Int64 ?? 0
|
|
195
175
|
}
|
|
196
176
|
|
|
197
177
|
public func cancelDelay(source: String) -> Bool {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return true
|
|
203
|
-
} catch {
|
|
204
|
-
logger.error("Failed to cancel update delay: \(error)")
|
|
205
|
-
return false
|
|
206
|
-
}
|
|
178
|
+
UserDefaults.standard.removeObject(forKey: DelayUpdateUtils.DELAY_CONDITION_PREFERENCES)
|
|
179
|
+
UserDefaults.standard.synchronize()
|
|
180
|
+
logger.info("All delays canceled from \(source)")
|
|
181
|
+
return true
|
|
207
182
|
}
|
|
208
183
|
|
|
209
184
|
// MARK: - Helper methods
|
|
@@ -792,9 +792,9 @@ extension UIWindow {
|
|
|
792
792
|
message: "Update downloaded! Reload to apply version \(latest.version)?",
|
|
793
793
|
plugin: plugin,
|
|
794
794
|
bridge: bridge,
|
|
795
|
-
onReload: {
|
|
795
|
+
onReload: {
|
|
796
796
|
_ = updater.set(bundle: bundle)
|
|
797
|
-
_ = plugin
|
|
797
|
+
_ = plugin._reload()
|
|
798
798
|
}
|
|
799
799
|
)
|
|
800
800
|
}
|