@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.
@@ -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
- let fileHandle: FileHandle
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
- fileHandle = try FileHandle(forReadingFrom: filePath)
175
+ try fileHandle.close()
168
176
  } catch {
169
- logger.error("Cannot open file for checksum calculation")
170
- logger.debug("Path: \(filePath.path), Error: \(error)")
171
- return ""
177
+ logger.error("Error closing file during checksum")
178
+ logger.debug("Error: \(error)")
172
179
  }
180
+ }
173
181
 
174
- defer {
175
- do {
176
- try fileHandle.close()
177
- } catch {
178
- logger.error("Error closing file during checksum")
179
- logger.debug("Error: \(error)")
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
- while autoreleasepool(invoking: {
184
- let fileData: Data
185
- do {
186
- fileData = try fileHandle.read(upToCount: bufferSize) ?? Data()
187
- } catch {
188
- logger.error("Error reading file during checksum")
189
- logger.debug("Error: \(error)")
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
- return hexString(from: sha256)
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
- var copy = sha256
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
- do {
155
- UserDefaults.standard.set(delayConditions, forKey: DelayUpdateUtils.DELAY_CONDITION_PREFERENCES)
156
- UserDefaults.standard.synchronize()
157
- logger.info("Delay update saved")
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
- do {
167
- UserDefaults.standard.set(backgroundTimestamp, forKey: DelayUpdateUtils.BACKGROUND_TIMESTAMP_KEY)
168
- UserDefaults.standard.synchronize()
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
- do {
177
- UserDefaults.standard.removeObject(forKey: DelayUpdateUtils.BACKGROUND_TIMESTAMP_KEY)
178
- UserDefaults.standard.synchronize()
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
- do {
188
- let key = DelayUpdateUtils.BACKGROUND_TIMESTAMP_KEY
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
- do {
199
- UserDefaults.standard.removeObject(forKey: DelayUpdateUtils.DELAY_CONDITION_PREFERENCES)
200
- UserDefaults.standard.synchronize()
201
- logger.info("All delays canceled from \(source)")
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: { [weak plugin] in
795
+ onReload: {
796
796
  _ = updater.set(bundle: bundle)
797
- _ = plugin?._reload()
797
+ _ = plugin._reload()
798
798
  }
799
799
  )
800
800
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "8.51.17",
3
+ "version": "8.51.19",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",