@capgo/capacitor-updater 8.47.5 → 8.47.6
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 +207 -41
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +278 -260
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +23 -26
- package/android/src/main/java/ee/forgr/capacitor_updater/ShakeMenu.java +45 -52
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +162 -11
- package/package.json +1 -1
|
@@ -82,7 +82,7 @@ public class CapgoUpdater {
|
|
|
82
82
|
public String channelUrl = "";
|
|
83
83
|
public String defaultChannel = "";
|
|
84
84
|
public String appId = "";
|
|
85
|
-
public boolean previewSession = false;
|
|
85
|
+
public volatile boolean previewSession = false;
|
|
86
86
|
public String publicKey = "";
|
|
87
87
|
public String deviceID = "";
|
|
88
88
|
public int timeout = 20000;
|
|
@@ -742,11 +742,15 @@ public class CapgoUpdater {
|
|
|
742
742
|
CapgoUpdater.this.notifyListeners("updateAvailable", ret);
|
|
743
743
|
logger.info("setNext: " + setNext);
|
|
744
744
|
if (setNext) {
|
|
745
|
-
|
|
746
|
-
|
|
745
|
+
if (this.previewSession) {
|
|
746
|
+
logger.info("Preview session is active, skipping automatic install of downloaded bundle");
|
|
747
|
+
this.directUpdate = false;
|
|
748
|
+
} else if (this.directUpdate) {
|
|
749
|
+
logger.info("directUpdate: " + this.directUpdate);
|
|
747
750
|
CapgoUpdater.this.directUpdateFinish(next);
|
|
748
751
|
this.directUpdate = false;
|
|
749
752
|
} else {
|
|
753
|
+
logger.info("directUpdate: " + this.directUpdate);
|
|
750
754
|
this.setNextBundle(next.getId());
|
|
751
755
|
}
|
|
752
756
|
}
|
|
@@ -1187,12 +1191,10 @@ public class CapgoUpdater {
|
|
|
1187
1191
|
}
|
|
1188
1192
|
|
|
1189
1193
|
void restoreResetState(final ResetState state) {
|
|
1190
|
-
final String currentBundlePath =
|
|
1191
|
-
? "public"
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
? BundleInfo.ID_BUILTIN
|
|
1195
|
-
: state.fallbackBundleId;
|
|
1194
|
+
final String currentBundlePath =
|
|
1195
|
+
state.currentBundlePath == null || state.currentBundlePath.trim().isEmpty() ? "public" : state.currentBundlePath;
|
|
1196
|
+
final String fallbackBundleId =
|
|
1197
|
+
state.fallbackBundleId == null || state.fallbackBundleId.isEmpty() ? BundleInfo.ID_BUILTIN : state.fallbackBundleId;
|
|
1196
1198
|
|
|
1197
1199
|
this.editor.putString(this.CAP_SERVER_PATH, currentBundlePath);
|
|
1198
1200
|
this.editor.putString(FALLBACK_VERSION, fallbackBundleId);
|
|
@@ -1459,107 +1461,105 @@ public class CapgoUpdater {
|
|
|
1459
1461
|
|
|
1460
1462
|
Request request = new Request.Builder().url(url).post(body).build();
|
|
1461
1463
|
|
|
1462
|
-
DownloadService.sharedClient
|
|
1463
|
-
.
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
callback.callback(retError);
|
|
1473
|
-
}
|
|
1464
|
+
DownloadService.sharedClient.newCall(request).enqueue(
|
|
1465
|
+
new okhttp3.Callback() {
|
|
1466
|
+
@Override
|
|
1467
|
+
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
1468
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1469
|
+
retError.put("message", "Request failed: " + e.getMessage());
|
|
1470
|
+
retError.put("error", "network_error");
|
|
1471
|
+
retError.put("kind", "failed");
|
|
1472
|
+
callback.callback(retError);
|
|
1473
|
+
}
|
|
1474
1474
|
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
}
|
|
1475
|
+
@Override
|
|
1476
|
+
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
|
1477
|
+
try (ResponseBody responseBody = response.body()) {
|
|
1478
|
+
final int statusCode = response.code();
|
|
1479
|
+
final String responseData = responseBody != null ? responseBody.string() : "";
|
|
1480
|
+
JSONObject jsonResponse = null;
|
|
1481
|
+
if (!responseData.isEmpty()) {
|
|
1482
|
+
try {
|
|
1483
|
+
jsonResponse = new JSONObject(responseData);
|
|
1484
|
+
} catch (JSONException ignored) {
|
|
1485
|
+
// Non-JSON responses are handled as response or parse errors below.
|
|
1487
1486
|
}
|
|
1487
|
+
}
|
|
1488
1488
|
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
}
|
|
1493
|
-
Map<String, Object> retError = new HashMap<>();
|
|
1494
|
-
if (jsonResponse.has("error") && !jsonResponse.isNull("error")) {
|
|
1495
|
-
retError.put("error", jsonResponse.getString("error"));
|
|
1496
|
-
}
|
|
1497
|
-
if (jsonResponse.has("kind") && !jsonResponse.isNull("kind")) {
|
|
1498
|
-
retError.put("kind", jsonResponse.getString("kind"));
|
|
1499
|
-
}
|
|
1500
|
-
if (jsonResponse.has("message") && !jsonResponse.isNull("message")) {
|
|
1501
|
-
retError.put("message", jsonResponse.getString("message"));
|
|
1502
|
-
} else {
|
|
1503
|
-
retError.put("message", "server did not provide a message");
|
|
1504
|
-
}
|
|
1505
|
-
if (jsonResponse.has("version") && !jsonResponse.isNull("version")) {
|
|
1506
|
-
retError.put("version", jsonResponse.getString("version"));
|
|
1507
|
-
}
|
|
1508
|
-
retError.put("statusCode", statusCode);
|
|
1509
|
-
callback.callback(retError);
|
|
1510
|
-
return;
|
|
1489
|
+
if (jsonResponse != null && (jsonResponse.has("error") || jsonResponse.has("kind"))) {
|
|
1490
|
+
if (statusCode == 429) {
|
|
1491
|
+
checkAndHandleRateLimitResponse(response);
|
|
1511
1492
|
}
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
Map<String, Object> retError = new HashMap<>();
|
|
1516
|
-
retError.put("message", "Rate limit exceeded");
|
|
1517
|
-
retError.put("error", "rate_limit_exceeded");
|
|
1518
|
-
retError.put("kind", "failed");
|
|
1519
|
-
retError.put("statusCode", statusCode);
|
|
1520
|
-
callback.callback(retError);
|
|
1521
|
-
return;
|
|
1493
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1494
|
+
if (jsonResponse.has("error") && !jsonResponse.isNull("error")) {
|
|
1495
|
+
retError.put("error", jsonResponse.getString("error"));
|
|
1522
1496
|
}
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
Map<String, Object> retError = new HashMap<>();
|
|
1526
|
-
retError.put("message", "Server error: " + response.code());
|
|
1527
|
-
retError.put("error", "response_error");
|
|
1528
|
-
retError.put("kind", "failed");
|
|
1529
|
-
retError.put("statusCode", statusCode);
|
|
1530
|
-
callback.callback(retError);
|
|
1531
|
-
return;
|
|
1497
|
+
if (jsonResponse.has("kind") && !jsonResponse.isNull("kind")) {
|
|
1498
|
+
retError.put("kind", jsonResponse.getString("kind"));
|
|
1532
1499
|
}
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1500
|
+
if (jsonResponse.has("message") && !jsonResponse.isNull("message")) {
|
|
1501
|
+
retError.put("message", jsonResponse.getString("message"));
|
|
1502
|
+
} else {
|
|
1503
|
+
retError.put("message", "server did not provide a message");
|
|
1536
1504
|
}
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
ret.put("statusCode", statusCode);
|
|
1540
|
-
|
|
1541
|
-
Iterator<String> keys = jsonResponse.keys();
|
|
1542
|
-
while (keys.hasNext()) {
|
|
1543
|
-
String key = keys.next();
|
|
1544
|
-
if (jsonResponse.has(key)) {
|
|
1545
|
-
if ("session_key".equals(key)) {
|
|
1546
|
-
ret.put("sessionKey", jsonResponse.get(key));
|
|
1547
|
-
} else {
|
|
1548
|
-
ret.put(key, jsonResponse.get(key));
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1505
|
+
if (jsonResponse.has("version") && !jsonResponse.isNull("version")) {
|
|
1506
|
+
retError.put("version", jsonResponse.getString("version"));
|
|
1551
1507
|
}
|
|
1552
|
-
|
|
1553
|
-
|
|
1508
|
+
retError.put("statusCode", statusCode);
|
|
1509
|
+
callback.callback(retError);
|
|
1510
|
+
return;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
// Check for 429 rate limit
|
|
1514
|
+
if (checkAndHandleRateLimitResponse(response)) {
|
|
1554
1515
|
Map<String, Object> retError = new HashMap<>();
|
|
1555
|
-
retError.put("message", "
|
|
1556
|
-
retError.put("error", "
|
|
1516
|
+
retError.put("message", "Rate limit exceeded");
|
|
1517
|
+
retError.put("error", "rate_limit_exceeded");
|
|
1518
|
+
retError.put("kind", "failed");
|
|
1519
|
+
retError.put("statusCode", statusCode);
|
|
1520
|
+
callback.callback(retError);
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
if (!response.isSuccessful()) {
|
|
1525
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1526
|
+
retError.put("message", "Server error: " + response.code());
|
|
1527
|
+
retError.put("error", "response_error");
|
|
1557
1528
|
retError.put("kind", "failed");
|
|
1529
|
+
retError.put("statusCode", statusCode);
|
|
1558
1530
|
callback.callback(retError);
|
|
1531
|
+
return;
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1534
|
+
if (jsonResponse == null) {
|
|
1535
|
+
throw new JSONException("Response is not a JSON object");
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
Map<String, Object> ret = new HashMap<>();
|
|
1539
|
+
ret.put("statusCode", statusCode);
|
|
1540
|
+
|
|
1541
|
+
Iterator<String> keys = jsonResponse.keys();
|
|
1542
|
+
while (keys.hasNext()) {
|
|
1543
|
+
String key = keys.next();
|
|
1544
|
+
if (jsonResponse.has(key)) {
|
|
1545
|
+
if ("session_key".equals(key)) {
|
|
1546
|
+
ret.put("sessionKey", jsonResponse.get(key));
|
|
1547
|
+
} else {
|
|
1548
|
+
ret.put(key, jsonResponse.get(key));
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1559
1551
|
}
|
|
1552
|
+
callback.callback(ret);
|
|
1553
|
+
} catch (JSONException e) {
|
|
1554
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1555
|
+
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
1556
|
+
retError.put("error", "parse_error");
|
|
1557
|
+
retError.put("kind", "failed");
|
|
1558
|
+
callback.callback(retError);
|
|
1560
1559
|
}
|
|
1561
1560
|
}
|
|
1562
|
-
|
|
1561
|
+
}
|
|
1562
|
+
);
|
|
1563
1563
|
}
|
|
1564
1564
|
|
|
1565
1565
|
public void getLatest(final String updateUrl, final String channel, final Callback callback) {
|
|
@@ -1717,88 +1717,98 @@ public class CapgoUpdater {
|
|
|
1717
1717
|
.put(RequestBody.create(json.toString(), MediaType.get("application/json")))
|
|
1718
1718
|
.build();
|
|
1719
1719
|
|
|
1720
|
-
DownloadService.sharedClient
|
|
1721
|
-
.
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
callback.callback(retError);
|
|
1730
|
-
}
|
|
1720
|
+
DownloadService.sharedClient.newCall(request).enqueue(
|
|
1721
|
+
new okhttp3.Callback() {
|
|
1722
|
+
@Override
|
|
1723
|
+
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
1724
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1725
|
+
retError.put("message", "Request failed: " + e.getMessage());
|
|
1726
|
+
retError.put("error", "network_error");
|
|
1727
|
+
callback.callback(retError);
|
|
1728
|
+
}
|
|
1731
1729
|
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1730
|
+
@Override
|
|
1731
|
+
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
|
1732
|
+
try (ResponseBody responseBody = response.body()) {
|
|
1733
|
+
// Check for 429 rate limit
|
|
1734
|
+
if (checkAndHandleRateLimitResponse(response)) {
|
|
1735
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1736
|
+
retError.put("message", "Rate limit exceeded");
|
|
1737
|
+
retError.put("error", "rate_limit_exceeded");
|
|
1738
|
+
callback.callback(retError);
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
if (response.code() == 400) {
|
|
1743
|
+
if (responseBody == null) {
|
|
1737
1744
|
Map<String, Object> retError = new HashMap<>();
|
|
1738
|
-
retError.put("message", "
|
|
1739
|
-
retError.put("error", "
|
|
1745
|
+
retError.put("message", "Empty response body");
|
|
1746
|
+
retError.put("error", "no_response_body");
|
|
1740
1747
|
callback.callback(retError);
|
|
1741
1748
|
return;
|
|
1742
1749
|
}
|
|
1743
|
-
|
|
1744
|
-
if (
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
ret.put("status", "default");
|
|
1751
|
-
logger.info("Channel get to \"" + ret);
|
|
1752
|
-
callback.callback(ret);
|
|
1753
|
-
return;
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
|
|
1757
|
-
if (!response.isSuccessful()) {
|
|
1758
|
-
Map<String, Object> retError = new HashMap<>();
|
|
1759
|
-
retError.put("message", "Server error: " + response.code());
|
|
1760
|
-
retError.put("error", "response_error");
|
|
1761
|
-
callback.callback(retError);
|
|
1750
|
+
String data = responseBody.string();
|
|
1751
|
+
if (data.contains("channel_not_found") && !defaultChannel.isEmpty()) {
|
|
1752
|
+
Map<String, Object> ret = new HashMap<>();
|
|
1753
|
+
ret.put("channel", defaultChannel);
|
|
1754
|
+
ret.put("status", "default");
|
|
1755
|
+
logger.info("Channel get to \"" + ret);
|
|
1756
|
+
callback.callback(ret);
|
|
1762
1757
|
return;
|
|
1763
1758
|
}
|
|
1759
|
+
}
|
|
1764
1760
|
|
|
1765
|
-
|
|
1766
|
-
String
|
|
1767
|
-
|
|
1761
|
+
if (!response.isSuccessful()) {
|
|
1762
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1763
|
+
retError.put("message", "Server error: " + response.code());
|
|
1764
|
+
retError.put("error", "response_error");
|
|
1765
|
+
callback.callback(retError);
|
|
1766
|
+
return;
|
|
1767
|
+
}
|
|
1768
1768
|
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1769
|
+
if (responseBody == null) {
|
|
1770
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1771
|
+
retError.put("message", "Empty response body");
|
|
1772
|
+
retError.put("error", "no_response_body");
|
|
1773
|
+
callback.callback(retError);
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
String responseData = responseBody.string();
|
|
1777
|
+
JSONObject jsonResponse = new JSONObject(responseData);
|
|
1778
|
+
|
|
1779
|
+
// Check for server-side errors first
|
|
1780
|
+
if (jsonResponse.has("error")) {
|
|
1781
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1782
|
+
retError.put("error", jsonResponse.getString("error"));
|
|
1783
|
+
if (jsonResponse.has("message")) {
|
|
1784
|
+
retError.put("message", jsonResponse.getString("message"));
|
|
1785
|
+
} else {
|
|
1786
|
+
retError.put("message", "server did not provide a message");
|
|
1780
1787
|
}
|
|
1788
|
+
callback.callback(retError);
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1781
1791
|
|
|
1782
|
-
|
|
1792
|
+
Map<String, Object> ret = new HashMap<>();
|
|
1783
1793
|
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
}
|
|
1794
|
+
Iterator<String> keys = jsonResponse.keys();
|
|
1795
|
+
while (keys.hasNext()) {
|
|
1796
|
+
String key = keys.next();
|
|
1797
|
+
if (jsonResponse.has(key)) {
|
|
1798
|
+
ret.put(key, jsonResponse.get(key));
|
|
1790
1799
|
}
|
|
1791
|
-
logger.info("Channel get to \"" + ret);
|
|
1792
|
-
callback.callback(ret);
|
|
1793
|
-
} catch (JSONException e) {
|
|
1794
|
-
Map<String, Object> retError = new HashMap<>();
|
|
1795
|
-
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
1796
|
-
retError.put("error", "parse_error");
|
|
1797
|
-
callback.callback(retError);
|
|
1798
1800
|
}
|
|
1801
|
+
logger.info("Channel get to \"" + ret);
|
|
1802
|
+
callback.callback(ret);
|
|
1803
|
+
} catch (JSONException e) {
|
|
1804
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1805
|
+
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
1806
|
+
retError.put("error", "parse_error");
|
|
1807
|
+
callback.callback(retError);
|
|
1799
1808
|
}
|
|
1800
1809
|
}
|
|
1801
|
-
|
|
1810
|
+
}
|
|
1811
|
+
);
|
|
1802
1812
|
}
|
|
1803
1813
|
|
|
1804
1814
|
public void listChannels(final Callback callback) {
|
|
@@ -1853,94 +1863,104 @@ public class CapgoUpdater {
|
|
|
1853
1863
|
|
|
1854
1864
|
Request request = new Request.Builder().url(urlBuilder.build()).get().build();
|
|
1855
1865
|
|
|
1856
|
-
DownloadService.sharedClient
|
|
1857
|
-
.
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
callback.callback(retError);
|
|
1866
|
-
}
|
|
1866
|
+
DownloadService.sharedClient.newCall(request).enqueue(
|
|
1867
|
+
new okhttp3.Callback() {
|
|
1868
|
+
@Override
|
|
1869
|
+
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
1870
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1871
|
+
retError.put("message", "Request failed: " + e.getMessage());
|
|
1872
|
+
retError.put("error", "network_error");
|
|
1873
|
+
callback.callback(retError);
|
|
1874
|
+
}
|
|
1867
1875
|
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1876
|
+
@Override
|
|
1877
|
+
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
|
1878
|
+
try (ResponseBody responseBody = response.body()) {
|
|
1879
|
+
// Check for 429 rate limit
|
|
1880
|
+
if (checkAndHandleRateLimitResponse(response)) {
|
|
1881
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1882
|
+
retError.put("message", "Rate limit exceeded");
|
|
1883
|
+
retError.put("error", "rate_limit_exceeded");
|
|
1884
|
+
callback.callback(retError);
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1879
1887
|
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1888
|
+
if (!response.isSuccessful()) {
|
|
1889
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1890
|
+
retError.put("message", "Server error: " + response.code());
|
|
1891
|
+
retError.put("error", "response_error");
|
|
1892
|
+
callback.callback(retError);
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1887
1895
|
|
|
1888
|
-
|
|
1889
|
-
String
|
|
1896
|
+
if (responseBody == null) {
|
|
1897
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1898
|
+
retError.put("message", "Empty response body");
|
|
1899
|
+
retError.put("error", "no_response_body");
|
|
1900
|
+
callback.callback(retError);
|
|
1901
|
+
return;
|
|
1902
|
+
}
|
|
1903
|
+
String data = responseBody.string();
|
|
1904
|
+
|
|
1905
|
+
try {
|
|
1906
|
+
Map<String, Object> ret = new HashMap<>();
|
|
1890
1907
|
|
|
1891
1908
|
try {
|
|
1892
|
-
|
|
1909
|
+
// Try to parse as direct array first
|
|
1910
|
+
JSONArray channelsJson = new JSONArray(data);
|
|
1911
|
+
List<Map<String, Object>> channelsList = new ArrayList<>();
|
|
1912
|
+
|
|
1913
|
+
for (int i = 0; i < channelsJson.length(); i++) {
|
|
1914
|
+
JSONObject channelJson = channelsJson.getJSONObject(i);
|
|
1915
|
+
Map<String, Object> channel = new HashMap<>();
|
|
1916
|
+
channel.put("id", channelJson.optString("id", ""));
|
|
1917
|
+
channel.put("name", channelJson.optString("name", ""));
|
|
1918
|
+
channel.put("public", channelJson.optBoolean("public", false));
|
|
1919
|
+
channel.put("allow_self_set", channelJson.optBoolean("allow_self_set", false));
|
|
1920
|
+
channelsList.add(channel);
|
|
1921
|
+
}
|
|
1893
1922
|
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
JSONArray channelsJson = new JSONArray(data);
|
|
1897
|
-
List<Map<String, Object>> channelsList = new ArrayList<>();
|
|
1898
|
-
|
|
1899
|
-
for (int i = 0; i < channelsJson.length(); i++) {
|
|
1900
|
-
JSONObject channelJson = channelsJson.getJSONObject(i);
|
|
1901
|
-
Map<String, Object> channel = new HashMap<>();
|
|
1902
|
-
channel.put("id", channelJson.optString("id", ""));
|
|
1903
|
-
channel.put("name", channelJson.optString("name", ""));
|
|
1904
|
-
channel.put("public", channelJson.optBoolean("public", false));
|
|
1905
|
-
channel.put("allow_self_set", channelJson.optBoolean("allow_self_set", false));
|
|
1906
|
-
channelsList.add(channel);
|
|
1907
|
-
}
|
|
1923
|
+
// Wrap in channels object for JS API
|
|
1924
|
+
ret.put("channels", channelsList);
|
|
1908
1925
|
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
if (json.has("
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
retError.put("message", json.getString("message"));
|
|
1923
|
-
} else {
|
|
1924
|
-
retError.put("message", "server did not provide a message");
|
|
1925
|
-
}
|
|
1926
|
-
callback.callback(retError);
|
|
1927
|
-
return;
|
|
1926
|
+
logger.info("Channels listed successfully");
|
|
1927
|
+
callback.callback(ret);
|
|
1928
|
+
} catch (JSONException arrayException) {
|
|
1929
|
+
// If not an array, try to parse as error object
|
|
1930
|
+
try {
|
|
1931
|
+
JSONObject json = new JSONObject(data);
|
|
1932
|
+
if (json.has("error")) {
|
|
1933
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1934
|
+
retError.put("error", json.getString("error"));
|
|
1935
|
+
if (json.has("message")) {
|
|
1936
|
+
retError.put("message", json.getString("message"));
|
|
1937
|
+
} else {
|
|
1938
|
+
retError.put("message", "server did not provide a message");
|
|
1928
1939
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
throw arrayException;
|
|
1940
|
+
callback.callback(retError);
|
|
1941
|
+
return;
|
|
1932
1942
|
}
|
|
1943
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1944
|
+
retError.put("message", "Unexpected channels response format");
|
|
1945
|
+
retError.put("error", "parse_error");
|
|
1946
|
+
callback.callback(retError);
|
|
1947
|
+
return;
|
|
1948
|
+
} catch (JSONException objException) {
|
|
1949
|
+
// If neither array nor object, throw parse error
|
|
1950
|
+
arrayException.addSuppressed(objException);
|
|
1951
|
+
throw arrayException;
|
|
1933
1952
|
}
|
|
1934
|
-
} catch (JSONException e) {
|
|
1935
|
-
Map<String, Object> retError = new HashMap<>();
|
|
1936
|
-
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
1937
|
-
retError.put("error", "parse_error");
|
|
1938
|
-
callback.callback(retError);
|
|
1939
1953
|
}
|
|
1954
|
+
} catch (JSONException e) {
|
|
1955
|
+
Map<String, Object> retError = new HashMap<>();
|
|
1956
|
+
retError.put("message", "JSON parse error: " + e.getMessage());
|
|
1957
|
+
retError.put("error", "parse_error");
|
|
1958
|
+
callback.callback(retError);
|
|
1940
1959
|
}
|
|
1941
1960
|
}
|
|
1942
1961
|
}
|
|
1943
|
-
|
|
1962
|
+
}
|
|
1963
|
+
);
|
|
1944
1964
|
}
|
|
1945
1965
|
|
|
1946
1966
|
public void sendStats(final String action) {
|
|
@@ -2037,35 +2057,33 @@ public class CapgoUpdater {
|
|
|
2037
2057
|
.build();
|
|
2038
2058
|
|
|
2039
2059
|
final int eventCount = eventsToSend.size();
|
|
2040
|
-
DownloadService.sharedClient
|
|
2041
|
-
.
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
logger.debug("Error: " + e.getMessage());
|
|
2048
|
-
}
|
|
2060
|
+
DownloadService.sharedClient.newCall(request).enqueue(
|
|
2061
|
+
new okhttp3.Callback() {
|
|
2062
|
+
@Override
|
|
2063
|
+
public void onFailure(@NonNull Call call, @NonNull IOException e) {
|
|
2064
|
+
logger.error("Failed to send stats batch");
|
|
2065
|
+
logger.debug("Error: " + e.getMessage());
|
|
2066
|
+
}
|
|
2049
2067
|
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2068
|
+
@Override
|
|
2069
|
+
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
|
2070
|
+
try (ResponseBody responseBody = response.body()) {
|
|
2071
|
+
// Check for 429 rate limit
|
|
2072
|
+
if (checkAndHandleRateLimitResponse(response)) {
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2057
2075
|
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
}
|
|
2076
|
+
if (response.isSuccessful()) {
|
|
2077
|
+
logger.info("Stats batch sent successfully");
|
|
2078
|
+
logger.debug("Sent " + eventCount + " events");
|
|
2079
|
+
} else {
|
|
2080
|
+
logger.error("Error sending stats batch");
|
|
2081
|
+
logger.debug("Response code: " + response.code());
|
|
2065
2082
|
}
|
|
2066
2083
|
}
|
|
2067
2084
|
}
|
|
2068
|
-
|
|
2085
|
+
}
|
|
2086
|
+
);
|
|
2069
2087
|
}
|
|
2070
2088
|
|
|
2071
2089
|
public BundleInfo getBundleInfo(final String id) {
|