@capgo/capacitor-updater 6.25.7 → 6.27.10

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.
@@ -71,7 +71,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
71
71
  private static final String[] BREAKING_EVENT_NAMES = { "breakingAvailable", "majorAvailable" };
72
72
  private static final String LAST_FAILED_BUNDLE_PREF_KEY = "CapacitorUpdater.lastFailedBundle";
73
73
 
74
- private final String pluginVersion = "6.25.7";
74
+ private final String pluginVersion = "6.27.10";
75
75
  private static final String DELAY_CONDITION_PREFERENCES = "";
76
76
 
77
77
  private SharedPreferences.Editor editor;
@@ -1572,7 +1572,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
1572
1572
  }
1573
1573
 
1574
1574
  private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
1575
- endBackGroundTaskWithNotif(msg, latestVersionName, current, error, false, "download_fail", "downloadFailed");
1575
+ endBackGroundTaskWithNotif(msg, latestVersionName, current, error, false, "download_fail", "downloadFailed", true);
1576
1576
  }
1577
1577
 
1578
1578
  private void endBackGroundTaskWithNotif(
@@ -1582,7 +1582,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
1582
1582
  Boolean error,
1583
1583
  Boolean isDirectUpdate
1584
1584
  ) {
1585
- endBackGroundTaskWithNotif(msg, latestVersionName, current, error, isDirectUpdate, "download_fail", "downloadFailed");
1585
+ endBackGroundTaskWithNotif(msg, latestVersionName, current, error, isDirectUpdate, "download_fail", "downloadFailed", true);
1586
1586
  }
1587
1587
 
1588
1588
  private void endBackGroundTaskWithNotif(
@@ -1593,6 +1593,19 @@ public class CapacitorUpdaterPlugin extends Plugin {
1593
1593
  Boolean isDirectUpdate,
1594
1594
  String failureAction,
1595
1595
  String failureEvent
1596
+ ) {
1597
+ endBackGroundTaskWithNotif(msg, latestVersionName, current, error, isDirectUpdate, failureAction, failureEvent, true);
1598
+ }
1599
+
1600
+ private void endBackGroundTaskWithNotif(
1601
+ String msg,
1602
+ String latestVersionName,
1603
+ BundleInfo current,
1604
+ Boolean error,
1605
+ Boolean isDirectUpdate,
1606
+ String failureAction,
1607
+ String failureEvent,
1608
+ boolean shouldSendStats
1596
1609
  ) {
1597
1610
  if (error) {
1598
1611
  logger.info(
@@ -1603,7 +1616,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
1603
1616
  "latestVersionName: " +
1604
1617
  latestVersionName
1605
1618
  );
1606
- this.implementation.sendStats(failureAction, current.getVersionName());
1619
+ if (shouldSendStats) {
1620
+ this.implementation.sendStats(failureAction, current.getVersionName());
1621
+ }
1607
1622
  final JSObject ret = new JSObject();
1608
1623
  ret.put("version", latestVersionName);
1609
1624
  this.notifyListeners(failureEvent, ret);
@@ -1634,14 +1649,23 @@ public class CapacitorUpdaterPlugin extends Plugin {
1634
1649
  if (jsRes.has("error")) {
1635
1650
  String error = jsRes.getString("error");
1636
1651
  String errorMessage = jsRes.has("message") ? jsRes.getString("message") : "server did not provide a message";
1637
- logger.error("getLatest failed with error: " + error + ", message: " + errorMessage);
1652
+ int statusCode = jsRes.has("statusCode") ? jsRes.optInt("statusCode", 0) : 0;
1653
+ boolean responseIsOk = statusCode >= 200 && statusCode < 300;
1654
+
1655
+ logger.error(
1656
+ "getLatest failed with error: " + error + ", message: " + errorMessage + ", statusCode: " + statusCode
1657
+ );
1638
1658
  String latestVersion = jsRes.has("version") ? jsRes.getString("version") : current.getVersionName();
1659
+
1639
1660
  CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
1640
1661
  errorMessage,
1641
1662
  latestVersion,
1642
1663
  current,
1643
1664
  true,
1644
- plannedDirectUpdate
1665
+ plannedDirectUpdate,
1666
+ "download_fail",
1667
+ "downloadFailed",
1668
+ !responseIsOk
1645
1669
  );
1646
1670
  return;
1647
1671
  }
@@ -871,11 +871,13 @@ public class CapgoUpdater {
871
871
  @Override
872
872
  public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
873
873
  try (ResponseBody responseBody = response.body()) {
874
+ final int statusCode = response.code();
874
875
  // Check for 429 rate limit
875
876
  if (checkAndHandleRateLimitResponse(response)) {
876
877
  Map<String, Object> retError = new HashMap<>();
877
878
  retError.put("message", "Rate limit exceeded");
878
879
  retError.put("error", "rate_limit_exceeded");
880
+ retError.put("statusCode", statusCode);
879
881
  callback.callback(retError);
880
882
  return;
881
883
  }
@@ -884,6 +886,7 @@ public class CapgoUpdater {
884
886
  Map<String, Object> retError = new HashMap<>();
885
887
  retError.put("message", "Server error: " + response.code());
886
888
  retError.put("error", "response_error");
889
+ retError.put("statusCode", statusCode);
887
890
  callback.callback(retError);
888
891
  return;
889
892
  }
@@ -901,11 +904,13 @@ public class CapgoUpdater {
901
904
  } else {
902
905
  retError.put("message", "server did not provide a message");
903
906
  }
907
+ retError.put("statusCode", statusCode);
904
908
  callback.callback(retError);
905
909
  return;
906
910
  }
907
911
 
908
912
  Map<String, Object> ret = new HashMap<>();
913
+ ret.put("statusCode", statusCode);
909
914
 
910
915
  Iterator<String> keys = jsonResponse.keys();
911
916
  while (keys.hasNext()) {