@capgo/capacitor-updater 5.7.1 → 5.7.3
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.
|
@@ -55,7 +55,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
55
55
|
private static final String channelUrlDefault =
|
|
56
56
|
"https://api.capgo.app/channel_self";
|
|
57
57
|
|
|
58
|
-
private final String PLUGIN_VERSION = "5.7.
|
|
58
|
+
private final String PLUGIN_VERSION = "5.7.3";
|
|
59
59
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
60
60
|
|
|
61
61
|
private SharedPreferences.Editor editor;
|
|
@@ -822,6 +822,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
822
822
|
if (this.periodCheckDelay == 0 || !this._isAutoUpdateEnabled()) {
|
|
823
823
|
return;
|
|
824
824
|
}
|
|
825
|
+
// The delay should be equal to this.periodCheckDelay.
|
|
826
|
+
// In appMovedToForeground we schedule a backgroundDownload and it happens BEFORE this scheduleAtFixedRate
|
|
827
|
+
// As such we get a race condition
|
|
825
828
|
final Timer timer = new Timer();
|
|
826
829
|
timer.scheduleAtFixedRate(
|
|
827
830
|
new TimerTask() {
|
|
@@ -854,7 +857,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
854
857
|
}
|
|
855
858
|
}
|
|
856
859
|
},
|
|
857
|
-
|
|
860
|
+
this.periodCheckDelay,
|
|
858
861
|
this.periodCheckDelay
|
|
859
862
|
);
|
|
860
863
|
}
|
|
@@ -227,6 +227,7 @@ extension CustomError: LocalizedError {
|
|
|
227
227
|
private let INFO_SUFFIX: String = "_info"
|
|
228
228
|
private let FALLBACK_VERSION: String = "pastVersion"
|
|
229
229
|
private let NEXT_VERSION: String = "nextVersion"
|
|
230
|
+
private var unzipPercent = 0
|
|
230
231
|
|
|
231
232
|
public let TAG: String = "✨ Capacitor-updater:"
|
|
232
233
|
public let CAP_SERVER_PATH: String = "serverBasePath"
|
|
@@ -385,7 +386,7 @@ extension CustomError: LocalizedError {
|
|
|
385
386
|
throw NSError(domain: "Invalid session key data", code: 1, userInfo: nil)
|
|
386
387
|
}
|
|
387
388
|
|
|
388
|
-
guard let sessionKeyDataDecrypted =
|
|
389
|
+
guard let sessionKeyDataDecrypted = rsaPrivateKey.decrypt(data: sessionKeyDataEncrypted) else {
|
|
389
390
|
throw NSError(domain: "Failed to decrypt session key data", code: 2, userInfo: nil)
|
|
390
391
|
}
|
|
391
392
|
|
|
@@ -395,7 +396,7 @@ extension CustomError: LocalizedError {
|
|
|
395
396
|
throw NSError(domain: "Failed to read encrypted data", code: 3, userInfo: nil)
|
|
396
397
|
}
|
|
397
398
|
|
|
398
|
-
guard let decryptedData =
|
|
399
|
+
guard let decryptedData = aesPrivateKey.decrypt(data: encryptedData) else {
|
|
399
400
|
throw NSError(domain: "Failed to decrypt data", code: 4, userInfo: nil)
|
|
400
401
|
}
|
|
401
402
|
|
|
@@ -407,19 +408,73 @@ extension CustomError: LocalizedError {
|
|
|
407
408
|
}
|
|
408
409
|
}
|
|
409
410
|
|
|
411
|
+
private func unzipProgressHandler(entry: String, zipInfo: unz_file_info, entryNumber: Int, total: Int, destUnZip: URL, id: String, unzipError: inout NSError?) {
|
|
412
|
+
if entry.contains("\\") {
|
|
413
|
+
print("\(self.TAG) unzip: Windows path is not supported, please use unix path as required by zip RFC: \(entry)")
|
|
414
|
+
self.sendStats(action: "windows_path_fail")
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
let fileURL = destUnZip.appendingPathComponent(entry)
|
|
418
|
+
let canonicalPath = fileURL.path
|
|
419
|
+
let canonicalDir = destUnZip.path
|
|
420
|
+
|
|
421
|
+
if !canonicalPath.hasPrefix(canonicalDir) {
|
|
422
|
+
self.sendStats(action: "canonical_path_fail")
|
|
423
|
+
unzipError = NSError(domain: "CanonicalPathError", code: 0, userInfo: nil)
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
let isDirectory = entry.hasSuffix("/")
|
|
427
|
+
if !isDirectory {
|
|
428
|
+
let folderURL = fileURL.deletingLastPathComponent()
|
|
429
|
+
if !FileManager.default.fileExists(atPath: folderURL.path) {
|
|
430
|
+
do {
|
|
431
|
+
try FileManager.default.createDirectory(at: folderURL, withIntermediateDirectories: true, attributes: nil)
|
|
432
|
+
} catch {
|
|
433
|
+
self.sendStats(action: "directory_path_fail")
|
|
434
|
+
unzipError = error as NSError
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
let newPercent = Int(Double(entryNumber) / Double(total) * 100)
|
|
440
|
+
if newPercent != self.unzipPercent {
|
|
441
|
+
self.unzipPercent = newPercent
|
|
442
|
+
self.notifyDownload(id, self.calcTotalPercent(percent: self.unzipPercent, min: 75, max: 90))
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
410
446
|
private func saveDownloaded(sourceZip: URL, id: String, base: URL) throws {
|
|
411
447
|
try prepareFolder(source: base)
|
|
412
448
|
let destHot: URL = base.appendingPathComponent(id)
|
|
413
449
|
let destUnZip: URL = documentsDir.appendingPathComponent(randomString(length: 10))
|
|
414
|
-
|
|
450
|
+
|
|
451
|
+
self.unzipPercent = 0
|
|
452
|
+
self.notifyDownload(id, 75)
|
|
453
|
+
|
|
454
|
+
var unzipError: NSError?
|
|
455
|
+
let success = SSZipArchive.unzipFile(atPath: sourceZip.path,
|
|
456
|
+
toDestination: destUnZip.path,
|
|
457
|
+
preserveAttributes: true,
|
|
458
|
+
overwrite: true,
|
|
459
|
+
nestedZipLevel: 1,
|
|
460
|
+
password: nil,
|
|
461
|
+
error: &unzipError,
|
|
462
|
+
delegate: nil,
|
|
463
|
+
progressHandler: { [weak self] (entry, zipInfo, entryNumber, total) in
|
|
464
|
+
guard let self = self else { return }
|
|
465
|
+
self.unzipProgressHandler(entry: entry, zipInfo: zipInfo, entryNumber: entryNumber, total: total, destUnZip: destUnZip, id: id, unzipError: &unzipError)
|
|
466
|
+
},
|
|
467
|
+
completionHandler: nil)
|
|
468
|
+
|
|
469
|
+
if !success || unzipError != nil {
|
|
415
470
|
self.sendStats(action: "unzip_fail")
|
|
416
|
-
throw CustomError.cannotUnzip
|
|
471
|
+
throw unzipError ?? CustomError.cannotUnzip
|
|
417
472
|
}
|
|
473
|
+
|
|
418
474
|
if try unflatFolder(source: destUnZip, dest: destHot) {
|
|
419
475
|
try deleteFolder(source: destUnZip)
|
|
420
476
|
}
|
|
421
477
|
}
|
|
422
|
-
|
|
423
478
|
private func createInfoObject() -> InfoObject {
|
|
424
479
|
return InfoObject(
|
|
425
480
|
platform: "ios",
|
|
@@ -703,7 +758,7 @@ extension CustomError: LocalizedError {
|
|
|
703
758
|
return setChannel
|
|
704
759
|
}
|
|
705
760
|
let semaphore: DispatchSemaphore = DispatchSemaphore(value: 0)
|
|
706
|
-
|
|
761
|
+
let parameters: InfoObject = self.createInfoObject()
|
|
707
762
|
|
|
708
763
|
let request = AF.request(self.channelUrl, method: .delete, parameters: parameters, encoder: JSONParameterEncoder.default, requestModifier: { $0.timeoutInterval = self.timeout })
|
|
709
764
|
|
|
@@ -15,7 +15,7 @@ import Version
|
|
|
15
15
|
@objc(CapacitorUpdaterPlugin)
|
|
16
16
|
public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
17
17
|
public var implementation = CapacitorUpdater()
|
|
18
|
-
private let PLUGIN_VERSION: String = "5.7.
|
|
18
|
+
private let PLUGIN_VERSION: String = "5.7.3"
|
|
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"
|