@capgo/capacitor-updater 7.34.2 → 7.35.0-alpha.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.
@@ -72,7 +72,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
72
72
  private static final String[] BREAKING_EVENT_NAMES = { "breakingAvailable", "majorAvailable" };
73
73
  private static final String LAST_FAILED_BUNDLE_PREF_KEY = "CapacitorUpdater.lastFailedBundle";
74
74
 
75
- private final String pluginVersion = "7.34.2";
75
+ private final String pluginVersion = "7.35.0-alpha.0";
76
76
  private static final String DELAY_CONDITION_PREFERENCES = "";
77
77
 
78
78
  private SharedPreferences.Editor editor;
@@ -302,11 +302,13 @@ public class DownloadService extends Worker {
302
302
  }
303
303
 
304
304
  final String finalFileHash = fileHash;
305
- // Remove .br extension for decompressed files
305
+
306
+ // Check if file is a Brotli file and remove .br extension from target
306
307
  boolean isBrotli = fileName.endsWith(".br");
307
- String finalFileName = isBrotli ? fileName.substring(0, fileName.length() - 3) : fileName;
308
- File targetFile = new File(destFolder, fileName);
309
- File cacheFile = new File(cacheFolder, finalFileHash + "_" + new File(finalFileName).getName());
308
+ String targetFileName = isBrotli ? fileName.substring(0, fileName.length() - 3) : fileName;
309
+
310
+ File targetFile = new File(destFolder, targetFileName);
311
+ File cacheFile = new File(cacheFolder, finalFileHash + "_" + new File(fileName).getName());
310
312
  File builtinFile = new File(builtinFolder, fileName);
311
313
 
312
314
  // Ensure parent directories of the target file exist
@@ -316,6 +318,7 @@ public class DownloadService extends Worker {
316
318
  continue;
317
319
  }
318
320
 
321
+ final boolean finalIsBrotli = isBrotli;
319
322
  Future<?> future = executor.submit(() -> {
320
323
  try {
321
324
  if (builtinFile.exists() && verifyChecksum(builtinFile, finalFileHash)) {
@@ -325,7 +328,7 @@ public class DownloadService extends Worker {
325
328
  copyFile(cacheFile, targetFile);
326
329
  logger.debug("already cached " + fileName);
327
330
  } else {
328
- downloadAndVerify(downloadUrl, targetFile, cacheFile, finalFileHash, sessionKey, publicKey);
331
+ downloadAndVerify(downloadUrl, targetFile, cacheFile, finalFileHash, sessionKey, publicKey, finalIsBrotli);
329
332
  }
330
333
 
331
334
  long completed = completedFiles.incrementAndGet();
@@ -575,19 +578,15 @@ public class DownloadService extends Worker {
575
578
  File cacheFile,
576
579
  String expectedHash,
577
580
  String sessionKey,
578
- String publicKey
581
+ String publicKey,
582
+ boolean isBrotli
579
583
  ) throws Exception {
580
584
  logger.debug("downloadAndVerify " + downloadUrl);
581
585
 
582
586
  Request request = new Request.Builder().url(downloadUrl).build();
583
587
 
584
- // Check if file is a Brotli file
585
- boolean isBrotli = targetFile.getName().endsWith(".br");
586
-
587
- // Create final target file with .br extension removed if it's a Brotli file
588
- File finalTargetFile = isBrotli
589
- ? new File(targetFile.getParentFile(), targetFile.getName().substring(0, targetFile.getName().length() - 3))
590
- : targetFile;
588
+ // targetFile is already the final destination without .br extension
589
+ File finalTargetFile = targetFile;
591
590
 
592
591
  // Create a temporary file for the compressed data
593
592
  File compressedFile = new File(getApplicationContext().getCacheDir(), "temp_" + targetFile.getName() + ".tmp");
@@ -54,7 +54,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
54
54
  CAPPluginMethod(name: "isShakeMenuEnabled", returnType: CAPPluginReturnPromise)
55
55
  ]
56
56
  public var implementation = CapgoUpdater()
57
- private let pluginVersion: String = "7.34.2"
57
+ private let pluginVersion: String = "7.35.0-alpha.0"
58
58
  static let updateUrlDefault = "https://plugin.capgo.app/updates"
59
59
  static let statsUrlDefault = "https://plugin.capgo.app/stats"
60
60
  static let channelUrlDefault = "https://plugin.capgo.app/channel_self"
@@ -400,7 +400,7 @@ import UIKit
400
400
  private var tempData = Data()
401
401
 
402
402
  private func verifyChecksum(file: URL, expectedHash: String) -> Bool {
403
- let actualHash = CryptoCipher.calcChecksum(filePath: file)
403
+ let actualHash = CryptoCipher.calcChecksum(filePath: file)
404
404
  return actualHash == expectedHash
405
405
  }
406
406
 
@@ -446,12 +446,15 @@ import UIKit
446
446
  }
447
447
 
448
448
  // Check if file has .br extension for Brotli decompression
449
- let isBrotli = fileName.hasSuffix(".br")
450
- let finalFileName = isBrotli ? String(fileName.dropLast(3)) : fileName
451
- let fileNameWithoutPath = (finalFileName as NSString).lastPathComponent
449
+ let fileNameWithoutPath = (fileName as NSString).lastPathComponent
452
450
  let cacheFileName = "\(fileHash)_\(fileNameWithoutPath)"
453
451
  let cacheFilePath = cacheFolder.appendingPathComponent(cacheFileName)
454
- let destFilePath = destFolder.appendingPathComponent(finalFileName)
452
+
453
+ // Check if file is Brotli compressed and remove .br extension from destination
454
+ let isBrotli = fileName.hasSuffix(".br")
455
+ let destFileName = isBrotli ? String(fileName.dropLast(3)) : fileName
456
+
457
+ let destFilePath = destFolder.appendingPathComponent(destFileName)
455
458
  let builtinFilePath = builtinFolder.appendingPathComponent(fileName)
456
459
 
457
460
  // Create necessary subdirectories in the destination folder
@@ -505,10 +508,11 @@ import UIKit
505
508
  try FileManager.default.removeItem(at: tempFile)
506
509
  }
507
510
 
511
+ // Use the isBrotli and destFilePath already computed above
508
512
  if isBrotli {
509
513
  // Decompress the Brotli data
510
514
  guard let decompressedData = self.decompressBrotli(data: finalData, fileName: fileName) else {
511
- self.sendStats(action: "download_manifest_brotli_fail", versionName: "\(version):\(finalFileName)")
515
+ self.sendStats(action: "download_manifest_brotli_fail", versionName: "\(version):\(destFileName)")
512
516
  throw NSError(domain: "BrotliDecompressionError", code: 1, userInfo: [NSLocalizedDescriptionKey: "Failed to decompress Brotli data for file \(fileName) at url \(downloadUrl)"])
513
517
  }
514
518
  finalData = decompressedData
@@ -523,7 +527,7 @@ import UIKit
523
527
  if calculatedChecksum != fileHash {
524
528
  // Delete the corrupt file before throwing error
525
529
  try? FileManager.default.removeItem(at: destFilePath)
526
- self.sendStats(action: "download_manifest_checksum_fail", versionName: "\(version):\(finalFileName)")
530
+ self.sendStats(action: "download_manifest_checksum_fail", versionName: "\(version):\(destFileName)")
527
531
  throw NSError(domain: "ChecksumError", code: 1, userInfo: [NSLocalizedDescriptionKey: "Computed checksum is not equal to required checksum (\(calculatedChecksum) != \(fileHash)) for file \(fileName) at url \(downloadUrl)"])
528
532
  }
529
533
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "7.34.2",
3
+ "version": "7.35.0-alpha.0",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Live update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",