@capgo/capacitor-updater 8.51.18 → 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.
@@ -146,7 +146,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
146
146
  static final int APPLICATION_EXIT_REASON_USER_REQUESTED = 10;
147
147
  static final int APPLICATION_EXIT_REASON_DEPENDENCY_DIED = 12;
148
148
 
149
- private final String pluginVersion = "8.51.18";
149
+ private final String pluginVersion = "8.51.19";
150
150
  private static final String DELAY_CONDITION_PREFERENCES = "";
151
151
 
152
152
  private SharedPreferences.Editor editor;
@@ -96,7 +96,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
96
96
  deinit {
97
97
  implementation.shutdown()
98
98
  }
99
- private let pluginVersion: String = "8.51.18"
99
+ private let pluginVersion: String = "8.51.19"
100
100
  private let launchStartedAtMs = Int64(Date().timeIntervalSince1970 * 1000)
101
101
  static let updateUrlDefault = "https://plugin.capgo.app/updates"
102
102
  static let statsUrlDefault = "https://plugin.capgo.app/stats"
@@ -3555,7 +3555,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
3555
3555
  }
3556
3556
 
3557
3557
  private func makeSplashscreenCall(callbackId: String, options: [String: Any], methodName: String) -> CAPPluginCall {
3558
- CAPPluginCall(callbackId: callbackId, options: options, success: { [weak self] (_, _) in
3558
+ CAPPluginCall(callbackId: callbackId, methodName: methodName, options: options, success: { [weak self] (_, _) in
3559
3559
  guard let self = self else { return }
3560
3560
  self.logger.info(self.splashscreenCompletedMessage(methodName: methodName))
3561
3561
  }, error: { [weak self] (_) in
@@ -3846,7 +3846,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
3846
3846
  return
3847
3847
  }
3848
3848
 
3849
- let scheduleTimeout = {
3849
+ let scheduleTimeout = { [weak self] in
3850
+ guard let self = self else { return }
3850
3851
  self.autoSplashscreenTimeoutWorkItem?.cancel()
3851
3852
 
3852
3853
  let workItem = DispatchWorkItem { [weak self] in
@@ -172,7 +172,15 @@ import UIKit
172
172
  return nsError.domain == NSURLErrorDomain && nsError.code == NSURLErrorTimedOut
173
173
  }
174
174
 
175
- private lazy var alamofireSession: Session = {
175
+ // lazy var is not thread-safe; concurrent manifest downloads can race first access when statsUrl is empty.
176
+ private var _alamofireSession: Session?
177
+ private let alamofireSessionLock = NSLock()
178
+ private var alamofireSession: Session {
179
+ alamofireSessionLock.lock()
180
+ defer { alamofireSessionLock.unlock() }
181
+ if let session = _alamofireSession {
182
+ return session
183
+ }
176
184
  let configuration = URLSessionConfiguration.ephemeral
177
185
  configuration.httpAdditionalHeaders = ["User-Agent": self.userAgent]
178
186
  configuration.httpCookieStorage = nil
@@ -180,8 +188,10 @@ import UIKit
180
188
  configuration.requestCachePolicy = .reloadIgnoringLocalCacheData
181
189
  configuration.urlCache = nil
182
190
  configuration.httpMaximumConnectionsPerHost = Self.manifestMaxConcurrentFiles
183
- return Session(configuration: configuration)
184
- }()
191
+ let session = Session(configuration: configuration)
192
+ _alamofireSession = session
193
+ return session
194
+ }
185
195
  private let networkResponseQueue = DispatchQueue(label: "ee.forgr.capacitor-updater.network-response", qos: .utility)
186
196
 
187
197
  public var notifyDownloadRaw: (String, Int, Bool, BundleInfo?) -> Void = { _, _, _, _ in }
@@ -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.18",
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",