@capgo/capacitor-updater 7.34.3 → 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.
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +1 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +12 -13
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +2 -2
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +11 -7
- package/package.json +1 -1
|
@@ -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.
|
|
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
|
-
|
|
305
|
+
|
|
306
|
+
// Check if file is a Brotli file and remove .br extension from target
|
|
306
307
|
boolean isBrotli = fileName.endsWith(".br");
|
|
307
|
-
String
|
|
308
|
-
|
|
309
|
-
File
|
|
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
|
-
//
|
|
585
|
-
|
|
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.
|
|
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"
|
|
@@ -358,7 +358,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
private func cleanupObsoleteVersions() {
|
|
361
|
-
let previous = UserDefaults.standard.string(forKey: "LatestNativeBuildVersion") ??
|
|
361
|
+
let previous = UserDefaults.standard.string(forKey: "LatestNativeBuildVersion") ?? "0"
|
|
362
362
|
if previous != "0" && self.currentBuildVersion != previous {
|
|
363
363
|
_ = self._reset(toLastSuccessful: false)
|
|
364
364
|
let res = implementation.list()
|
|
@@ -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 =
|
|
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
|
|
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
|
-
|
|
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):\(
|
|
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):\(
|
|
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
|
}
|