@capgo/capacitor-updater 4.36.0 → 4.41.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.
@@ -331,7 +331,7 @@ public class CapacitorUpdater {
331
331
  ) {
332
332
  try {
333
333
  final File downloaded = new File(this.documentsDir, dest);
334
- this.decryptFile(downloaded, sessionKey);
334
+ this.decryptFile(downloaded, sessionKey, version);
335
335
  final String checksum;
336
336
  checksum = this.getChecksum(downloaded);
337
337
  this.notifyDownload(id, 71);
@@ -478,8 +478,11 @@ public class CapacitorUpdater {
478
478
  return enc.toLowerCase();
479
479
  }
480
480
 
481
- private void decryptFile(final File file, final String ivSessionKey)
482
- throws IOException {
481
+ private void decryptFile(
482
+ final File file,
483
+ final String ivSessionKey,
484
+ final String version
485
+ ) throws IOException {
483
486
  // (str != null && !str.isEmpty())
484
487
  if (
485
488
  this.privateKey == null ||
@@ -514,6 +517,7 @@ public class CapacitorUpdater {
514
517
  fos.close();
515
518
  } catch (GeneralSecurityException e) {
516
519
  Log.i(TAG, "decryptFile fail");
520
+ this.sendStats("decrypt_fail", version);
517
521
  e.printStackTrace();
518
522
  throw new IOException("GeneralSecurityException");
519
523
  }
@@ -55,7 +55,7 @@ public class CapacitorUpdaterPlugin
55
55
  private static final String channelUrlDefault =
56
56
  "https://api.capgo.app/channel_self";
57
57
 
58
- private final String PLUGIN_VERSION = "4.36.0";
58
+ private final String PLUGIN_VERSION = "4.41.0";
59
59
  private static final String DELAY_CONDITION_PREFERENCES = "";
60
60
 
61
61
  private SharedPreferences.Editor editor;
@@ -339,7 +339,7 @@ extension CustomError: LocalizedError {
339
339
  }
340
340
  }
341
341
 
342
- private func decryptFile(filePath: URL, sessionKey: String) throws {
342
+ private func decryptFile(filePath: URL, sessionKey: String, version: String) throws {
343
343
  if self.privateKey.isEmpty || sessionKey.isEmpty {
344
344
  print("\(self.TAG) Cannot found privateKey or sessionKey")
345
345
  return
@@ -347,13 +347,13 @@ extension CustomError: LocalizedError {
347
347
  do {
348
348
  guard let rsaPrivateKey: RSAPrivateKey = .load(rsaPrivateKey: self.privateKey) else {
349
349
  print("cannot decode privateKey", self.privateKey)
350
- return
350
+ throw CustomError.cannotDecode
351
351
  }
352
352
 
353
353
  let sessionKeyArray: [String] = sessionKey.components(separatedBy: ":")
354
354
  guard let ivData: Data = Data(base64Encoded: sessionKeyArray[0]) else {
355
355
  print("cannot decode sessionKey", sessionKey)
356
- return
356
+ throw CustomError.cannotDecode
357
357
  }
358
358
  let sessionKeyDataEncrypted: Data = Data(base64Encoded: sessionKeyArray[1])!
359
359
  let sessionKeyDataDecrypted: Data = rsaPrivateKey.decrypt(data: sessionKeyDataEncrypted)!
@@ -364,6 +364,7 @@ extension CustomError: LocalizedError {
364
364
  try decryptedData.write(to: filePath)
365
365
  } catch {
366
366
  print("\(self.TAG) Cannot decode: \(filePath.path)", error)
367
+ self.sendStats(action: "decrypt_fail", versionName: version)
367
368
  throw CustomError.cannotDecode
368
369
  }
369
370
  }
@@ -470,7 +471,7 @@ extension CustomError: LocalizedError {
470
471
  case .success:
471
472
  self.notifyDownload(id, 71)
472
473
  do {
473
- try self.decryptFile(filePath: fileURL, sessionKey: sessionKey)
474
+ try self.decryptFile(filePath: fileURL, sessionKey: sessionKey, version: version)
474
475
  checksum = self.getChecksum(filePath: fileURL)
475
476
  try self.saveDownloaded(sourceZip: fileURL, id: id, base: self.documentsDir.appendingPathComponent(self.bundleDirectoryHot))
476
477
  self.notifyDownload(id, 85)
@@ -482,7 +483,7 @@ extension CustomError: LocalizedError {
482
483
  mainError = error as NSError
483
484
  }
484
485
  case let .failure(error):
485
- print("\(self.TAG) download error", response.value!, error)
486
+ print("\(self.TAG) download error", response.value ?? "", error)
486
487
  mainError = error as NSError
487
488
  }
488
489
  }
@@ -657,7 +658,7 @@ extension CustomError: LocalizedError {
657
658
  setChannel.message = message
658
659
  }
659
660
  case let .failure(error):
660
- print("\(self.TAG) Error set Channel", response.value!, error)
661
+ print("\(self.TAG) Error set Channel", response.value ?? "", error)
661
662
  setChannel.message = "Error set Channel \(String(describing: response.value))"
662
663
  setChannel.error = "response_error"
663
664
  }
@@ -721,7 +722,7 @@ extension CustomError: LocalizedError {
721
722
  case .success:
722
723
  print("\(self.TAG) Stats send for \(action), version \(versionName)")
723
724
  case let .failure(error):
724
- print("\(self.TAG) Error sending stats: ", response.value!, error)
725
+ print("\(self.TAG) Error sending stats: ", response.value ?? "", error)
725
726
  }
726
727
  }
727
728
  }
@@ -766,7 +767,7 @@ extension CustomError: LocalizedError {
766
767
 
767
768
  private func saveBundleInfo(id: String, bundle: BundleInfo?) {
768
769
  if bundle != nil && (bundle!.isBuiltin() || bundle!.isUnknown()) {
769
- print("\(self.TAG) Not saving info for bundle [\(id)]", bundle!.toString())
770
+ print("\(self.TAG) Not saving info for bundle [\(id)]", bundle?.toString() ?? "")
770
771
  return
771
772
  }
772
773
  if bundle == nil {
@@ -15,7 +15,7 @@ import Version
15
15
  @objc(CapacitorUpdaterPlugin)
16
16
  public class CapacitorUpdaterPlugin: CAPPlugin {
17
17
  private var implementation = CapacitorUpdater()
18
- private let PLUGIN_VERSION: String = "4.36.0"
18
+ private let PLUGIN_VERSION: String = "4.41.0"
19
19
  static let updateUrlDefault = "https://api.capgo.app/updates"
20
20
  static let statsUrlDefault = "https://api.capgo.app/stats"
21
21
  static let channelUrlDefault = "https://api.capgo.app/channel_self"
@@ -122,7 +122,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
122
122
  let sessionKey = call.getString("sessionKey", "")
123
123
  let checksum = call.getString("checksum", "")
124
124
  let url = URL(string: urlString)
125
- print("\(self.implementation.TAG) Downloading \(url!)")
125
+ print("\(self.implementation.TAG) Downloading \(String(describing: url))")
126
126
  DispatchQueue.global(qos: .background).async {
127
127
  do {
128
128
  let next = try self.implementation.download(url: url!, version: version, sessionKey: sessionKey)
@@ -138,7 +138,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
138
138
  self.notifyListeners("updateAvailable", data: ["bundle": next.toJSON()])
139
139
  call.resolve(next.toJSON())
140
140
  } catch {
141
- print("\(self.implementation.TAG) Failed to download from: \(url!) \(error.localizedDescription)")
141
+ print("\(self.implementation.TAG) Failed to download from: \(String(describing: url)) \(error.localizedDescription)")
142
142
  self.notifyListeners("downloadFailed", data: ["version": version])
143
143
  let current: BundleInfo = self.implementation.getCurrentBundle()
144
144
  self.implementation.sendStats(action: "download_fail", versionName: current.getVersionName())
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.36.0",
4
- "packageManager": "pnpm@8.1.0",
3
+ "version": "4.41.0",
4
+ "packageManager": "pnpm@8.2.0",
5
5
  "license": "MPL-2.0",
6
6
  "description": "Live update for capacitor apps",
7
7
  "main": "dist/plugin.cjs.js",