@capgo/capacitor-updater 4.0.0-alpha.39 → 4.0.0-alpha.42

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.
@@ -47,7 +47,7 @@ public class CapacitorUpdater {
47
47
  private static final String bundleDirectory = "versions";
48
48
 
49
49
  public static final String TAG = "Capacitor-updater";
50
- public static final String pluginVersion = "4.0.0-alpha.39";
50
+ public static final String pluginVersion = "4.0.0-alpha.42";
51
51
 
52
52
  public SharedPreferences.Editor editor;
53
53
  public SharedPreferences prefs;
@@ -367,6 +367,7 @@ public class CapacitorUpdater {
367
367
  json.put("version_name", version);
368
368
  json.put("plugin_version", pluginVersion);
369
369
 
370
+ Log.e(CapacitorUpdater.TAG, "Auto-update parameters: " + json.toString());
370
371
  // Building a request
371
372
  JsonObjectRequest request = new JsonObjectRequest(
372
373
  Request.Method.POST,
@@ -430,25 +431,28 @@ public class CapacitorUpdater {
430
431
  }
431
432
  }
432
433
 
433
- public BundleInfo getBundleInfo(String id) {
434
- if(id == null) {
435
- id = BundleInfo.VERSION_UNKNOWN;
434
+ public BundleInfo getBundleInfo(final String id) {
435
+ String trueId = BundleInfo.VERSION_UNKNOWN;
436
+ if(id != null) {
437
+ trueId = id;
436
438
  }
437
- Log.d(TAG, "Getting info for bundle [" + id + "]");
439
+ Log.d(TAG, "Getting info for bundle [" + trueId + "]");
438
440
  BundleInfo result;
439
- if(BundleInfo.ID_BUILTIN.equals(id)) {
440
- result = new BundleInfo(id, (String) null, BundleStatus.SUCCESS, "", "");
441
+ if(BundleInfo.ID_BUILTIN.equals(trueId)) {
442
+ result = new BundleInfo(trueId, (String) null, BundleStatus.SUCCESS, "", "");
443
+ } else if(BundleInfo.VERSION_UNKNOWN.equals(trueId)) {
444
+ result = new BundleInfo(trueId, (String) null, BundleStatus.ERROR, "", "");
441
445
  } else {
442
446
  try {
443
- String stored = this.prefs.getString(id + INFO_SUFFIX, "");
447
+ String stored = this.prefs.getString(trueId + INFO_SUFFIX, "");
444
448
  result = BundleInfo.fromJSON(stored);
445
449
  } catch (JSONException e) {
446
- Log.e(TAG, "Failed to parse info for bundle [" + id + "] ", e);
447
- result = new BundleInfo(id, (String) null, BundleStatus.PENDING, "", "");
450
+ Log.e(TAG, "Failed to parse info for bundle [" + trueId + "] ", e);
451
+ result = new BundleInfo(trueId, (String) null, BundleStatus.PENDING, "", "");
448
452
  }
449
453
  }
450
454
 
451
- Log.d(TAG, "Returning info [" + id + "] " + result);
455
+ Log.d(TAG, "Returning info [" + trueId + "] " + result);
452
456
  return result;
453
457
  }
454
458
 
@@ -539,7 +543,7 @@ public class CapacitorUpdater {
539
543
  }
540
544
 
541
545
  public BundleInfo getNextBundle() {
542
- final String id = this.prefs.getString(NEXT_VERSION, BundleInfo.ID_BUILTIN);
546
+ final String id = this.prefs.getString(NEXT_VERSION, null);
543
547
  return this.getBundleInfo(id);
544
548
  }
545
549
 
@@ -608,7 +608,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
608
608
  final BundleInfo current = this.implementation.getCurrentBundle();
609
609
  final BundleInfo next = this.implementation.getNextBundle();
610
610
 
611
- if (next != null && !next.isErrorStatus() && (next.getId() != current.getId())) {
611
+ if (next != null && !next.isErrorStatus() && next.getId() != current.getId()) {
612
612
  // There is a next bundle waiting for activation
613
613
  Log.d(CapacitorUpdater.TAG, "Next bundle is: " + next.getVersionName());
614
614
  if (this.implementation.set(next) && this._reload()) {
@@ -4,7 +4,7 @@ import Foundation
4
4
 
5
5
  @objc public class BundleInfo: NSObject, Decodable, Encodable {
6
6
  public static let ID_BUILTIN: String = "builtin"
7
- public static let ID_UNKNOWN: String = "unknown"
7
+ public static let VERSION_UNKNOWN: String = "unknown"
8
8
  public static let DOWNLOADED_BUILTIN: String = "1970-01-01T00:00:00.000Z"
9
9
 
10
10
  private let downloaded: String
@@ -34,7 +34,7 @@ import Foundation
34
34
  }
35
35
 
36
36
  public func isUnknown() -> Bool {
37
- return BundleInfo.ID_UNKNOWN == self.id
37
+ return BundleInfo.VERSION_UNKNOWN == self.id
38
38
  }
39
39
 
40
40
  public func isErrorStatus() -> Bool {
@@ -149,7 +149,7 @@ extension CustomError: LocalizedError {
149
149
 
150
150
  public let TAG = "✨ Capacitor-updater:";
151
151
  public let CAP_SERVER_PATH = "serverBasePath"
152
- public let pluginVersion = "4.0.0-alpha.39"
152
+ public let pluginVersion = "4.0.0-alpha.42"
153
153
  public var statsUrl = ""
154
154
  public var appId = ""
155
155
  public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
@@ -242,6 +242,7 @@ extension CustomError: LocalizedError {
242
242
  "plugin_version": self.pluginVersion,
243
243
  "version_name": self.getCurrentBundle().getVersionName()
244
244
  ]
245
+ print("\(self.TAG) Auto-update parameters: \(parameters)")
245
246
  let request = AF.request(url, method: .post,parameters: parameters, encoder: JSONParameterEncoder.default)
246
247
 
247
248
  request.validate().responseDecodable(of: AppVersionDec.self) { response in
@@ -420,7 +421,7 @@ extension CustomError: LocalizedError {
420
421
  }
421
422
 
422
423
  public func reset(isInternal: Bool) {
423
- print("\(self.TAG) reset: \(internal)")
424
+ print("\(self.TAG) reset: \(isInternal)")
424
425
  self.setCurrentBundle(bundle: "")
425
426
  self.setFallbackBundle(fallback: Optional<BundleInfo>.none)
426
427
  let _ = self.setNextBundle(next: Optional<String>.none)
@@ -469,19 +470,27 @@ extension CustomError: LocalizedError {
469
470
  }
470
471
  }
471
472
 
472
- public func getBundleInfo(id: String = BundleInfo.ID_BUILTIN) -> BundleInfo {
473
- print("\(self.TAG) Getting info for bundle [\(id)]")
474
- if(BundleInfo.ID_BUILTIN == id) {
475
- return BundleInfo(id: id, version: "", status: BundleStatus.SUCCESS, checksum: "")
473
+ public func getBundleInfo(id: String?) -> BundleInfo {
474
+ var trueId = BundleInfo.VERSION_UNKNOWN
475
+ if(id != nil) {
476
+ trueId = id!
476
477
  }
477
- do {
478
- let result: BundleInfo = try UserDefaults.standard.getObj(forKey: "\(id)\(self.INFO_SUFFIX)", castTo: BundleInfo.self)
479
- // print("\(self.TAG) Returning info bundle [\(id)]", result.toString())
480
- return result
481
- } catch {
482
- print("\(self.TAG) Failed to parse info for bundle [\(id)]", error.localizedDescription)
483
- return BundleInfo(id: id, version: "", status: BundleStatus.PENDING, checksum: "")
478
+ print("\(self.TAG) Getting info for bundle [\(trueId)]")
479
+ let result: BundleInfo;
480
+ if(BundleInfo.ID_BUILTIN == trueId) {
481
+ result = BundleInfo(id: trueId, version: "", status: BundleStatus.SUCCESS, checksum: "")
482
+ } else if (BundleInfo.VERSION_UNKNOWN == trueId) {
483
+ result = BundleInfo(id: trueId, version: "", status: BundleStatus.ERROR, checksum: "")
484
+ } else {
485
+ do {
486
+ result = try UserDefaults.standard.getObj(forKey: "\(trueId)\(self.INFO_SUFFIX)", castTo: BundleInfo.self)
487
+ } catch {
488
+ print("\(self.TAG) Failed to parse info for bundle [\(trueId)]", error.localizedDescription)
489
+ result = BundleInfo(id: trueId, version: "", status: BundleStatus.PENDING, checksum: "")
490
+ }
484
491
  }
492
+ print("\(self.TAG) Returning info bundle [\(result.toString())]")
493
+ return result;
485
494
  }
486
495
 
487
496
  public func getBundleInfoByVersionName(version: String) -> BundleInfo? {
@@ -559,7 +568,7 @@ extension CustomError: LocalizedError {
559
568
  }
560
569
 
561
570
  public func getNextBundle() -> BundleInfo? {
562
- let id: String = UserDefaults.standard.string(forKey: self.NEXT_VERSION) ?? BundleInfo.ID_BUILTIN
571
+ let id: String? = UserDefaults.standard.string(forKey: self.NEXT_VERSION)
563
572
  return self.getBundleInfo(id: id)
564
573
  }
565
574
 
@@ -423,7 +423,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
423
423
  let current: BundleInfo = self.implementation.getCurrentBundle()
424
424
  let next: BundleInfo? = self.implementation.getNextBundle()
425
425
 
426
- if (next != nil && !next!.isErrorStatus() && (next!.getVersionName() != current.getVersionName())) {
426
+ if (next != nil && !next!.isErrorStatus() && next!.getVersionName() != current.getVersionName()) {
427
427
  print("\(self.implementation.TAG) Next bundle is: \(next!.toString())")
428
428
  if (self.implementation.set(bundle: next!) && self._reload()) {
429
429
  print("\(self.implementation.TAG) Updated to bundle: \(next!.toString())")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.0.0-alpha.39",
3
+ "version": "4.0.0-alpha.42",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",