@capgo/capacitor-updater 7.27.8 → 7.28.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 +30 -6
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +5 -0
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +10 -4
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +2 -0
- package/ios/Sources/CapacitorUpdaterPlugin/InternalUtils.swift +2 -0
- package/package.json +1 -1
|
@@ -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 = "7.
|
|
74
|
+
private final String pluginVersion = "7.28.0";
|
|
75
75
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
76
76
|
|
|
77
77
|
private SharedPreferences.Editor editor;
|
|
@@ -1567,7 +1567,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1567
1567
|
}
|
|
1568
1568
|
|
|
1569
1569
|
private void endBackGroundTaskWithNotif(String msg, String latestVersionName, BundleInfo current, Boolean error) {
|
|
1570
|
-
endBackGroundTaskWithNotif(msg, latestVersionName, current, error, false, "download_fail", "downloadFailed");
|
|
1570
|
+
endBackGroundTaskWithNotif(msg, latestVersionName, current, error, false, "download_fail", "downloadFailed", true);
|
|
1571
1571
|
}
|
|
1572
1572
|
|
|
1573
1573
|
private void endBackGroundTaskWithNotif(
|
|
@@ -1577,7 +1577,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1577
1577
|
Boolean error,
|
|
1578
1578
|
Boolean isDirectUpdate
|
|
1579
1579
|
) {
|
|
1580
|
-
endBackGroundTaskWithNotif(msg, latestVersionName, current, error, isDirectUpdate, "download_fail", "downloadFailed");
|
|
1580
|
+
endBackGroundTaskWithNotif(msg, latestVersionName, current, error, isDirectUpdate, "download_fail", "downloadFailed", true);
|
|
1581
1581
|
}
|
|
1582
1582
|
|
|
1583
1583
|
private void endBackGroundTaskWithNotif(
|
|
@@ -1588,6 +1588,19 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1588
1588
|
Boolean isDirectUpdate,
|
|
1589
1589
|
String failureAction,
|
|
1590
1590
|
String failureEvent
|
|
1591
|
+
) {
|
|
1592
|
+
endBackGroundTaskWithNotif(msg, latestVersionName, current, error, isDirectUpdate, failureAction, failureEvent, true);
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
private void endBackGroundTaskWithNotif(
|
|
1596
|
+
String msg,
|
|
1597
|
+
String latestVersionName,
|
|
1598
|
+
BundleInfo current,
|
|
1599
|
+
Boolean error,
|
|
1600
|
+
Boolean isDirectUpdate,
|
|
1601
|
+
String failureAction,
|
|
1602
|
+
String failureEvent,
|
|
1603
|
+
boolean shouldSendStats
|
|
1591
1604
|
) {
|
|
1592
1605
|
if (error) {
|
|
1593
1606
|
logger.info(
|
|
@@ -1598,7 +1611,9 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1598
1611
|
"latestVersionName: " +
|
|
1599
1612
|
latestVersionName
|
|
1600
1613
|
);
|
|
1601
|
-
|
|
1614
|
+
if (shouldSendStats) {
|
|
1615
|
+
this.implementation.sendStats(failureAction, current.getVersionName());
|
|
1616
|
+
}
|
|
1602
1617
|
final JSObject ret = new JSObject();
|
|
1603
1618
|
ret.put("version", latestVersionName);
|
|
1604
1619
|
this.notifyListeners(failureEvent, ret);
|
|
@@ -1629,14 +1644,23 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1629
1644
|
if (jsRes.has("error")) {
|
|
1630
1645
|
String error = jsRes.getString("error");
|
|
1631
1646
|
String errorMessage = jsRes.has("message") ? jsRes.getString("message") : "server did not provide a message";
|
|
1632
|
-
|
|
1647
|
+
int statusCode = jsRes.has("statusCode") ? jsRes.optInt("statusCode", 0) : 0;
|
|
1648
|
+
boolean responseIsOk = statusCode >= 200 && statusCode < 300;
|
|
1649
|
+
|
|
1650
|
+
logger.error(
|
|
1651
|
+
"getLatest failed with error: " + error + ", message: " + errorMessage + ", statusCode: " + statusCode
|
|
1652
|
+
);
|
|
1633
1653
|
String latestVersion = jsRes.has("version") ? jsRes.getString("version") : current.getVersionName();
|
|
1654
|
+
|
|
1634
1655
|
CapacitorUpdaterPlugin.this.endBackGroundTaskWithNotif(
|
|
1635
1656
|
errorMessage,
|
|
1636
1657
|
latestVersion,
|
|
1637
1658
|
current,
|
|
1638
1659
|
true,
|
|
1639
|
-
plannedDirectUpdate
|
|
1660
|
+
plannedDirectUpdate,
|
|
1661
|
+
"download_fail",
|
|
1662
|
+
"downloadFailed",
|
|
1663
|
+
!responseIsOk
|
|
1640
1664
|
);
|
|
1641
1665
|
return;
|
|
1642
1666
|
}
|
|
@@ -864,11 +864,13 @@ public class CapgoUpdater {
|
|
|
864
864
|
@Override
|
|
865
865
|
public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
|
|
866
866
|
try (ResponseBody responseBody = response.body()) {
|
|
867
|
+
final int statusCode = response.code();
|
|
867
868
|
// Check for 429 rate limit
|
|
868
869
|
if (checkAndHandleRateLimitResponse(response)) {
|
|
869
870
|
Map<String, Object> retError = new HashMap<>();
|
|
870
871
|
retError.put("message", "Rate limit exceeded");
|
|
871
872
|
retError.put("error", "rate_limit_exceeded");
|
|
873
|
+
retError.put("statusCode", statusCode);
|
|
872
874
|
callback.callback(retError);
|
|
873
875
|
return;
|
|
874
876
|
}
|
|
@@ -877,6 +879,7 @@ public class CapgoUpdater {
|
|
|
877
879
|
Map<String, Object> retError = new HashMap<>();
|
|
878
880
|
retError.put("message", "Server error: " + response.code());
|
|
879
881
|
retError.put("error", "response_error");
|
|
882
|
+
retError.put("statusCode", statusCode);
|
|
880
883
|
callback.callback(retError);
|
|
881
884
|
return;
|
|
882
885
|
}
|
|
@@ -894,11 +897,13 @@ public class CapgoUpdater {
|
|
|
894
897
|
} else {
|
|
895
898
|
retError.put("message", "server did not provide a message");
|
|
896
899
|
}
|
|
900
|
+
retError.put("statusCode", statusCode);
|
|
897
901
|
callback.callback(retError);
|
|
898
902
|
return;
|
|
899
903
|
}
|
|
900
904
|
|
|
901
905
|
Map<String, Object> ret = new HashMap<>();
|
|
906
|
+
ret.put("statusCode", statusCode);
|
|
902
907
|
|
|
903
908
|
Iterator<String> keys = jsonResponse.keys();
|
|
904
909
|
while (keys.hasNext()) {
|
|
@@ -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.28.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"
|
|
@@ -1228,10 +1228,13 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
1228
1228
|
current: BundleInfo,
|
|
1229
1229
|
error: Bool = true,
|
|
1230
1230
|
failureAction: String = "download_fail",
|
|
1231
|
-
failureEvent: String = "downloadFailed"
|
|
1231
|
+
failureEvent: String = "downloadFailed",
|
|
1232
|
+
sendStats: Bool = true
|
|
1232
1233
|
) {
|
|
1233
1234
|
if error {
|
|
1234
|
-
|
|
1235
|
+
if sendStats {
|
|
1236
|
+
self.implementation.sendStats(action: failureAction, versionName: current.getVersionName())
|
|
1237
|
+
}
|
|
1235
1238
|
self.notifyListeners(failureEvent, data: ["version": latestVersionName])
|
|
1236
1239
|
}
|
|
1237
1240
|
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
@@ -1259,11 +1262,14 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
1259
1262
|
// Handle network errors and other failures first
|
|
1260
1263
|
if let backendError = res.error, !backendError.isEmpty {
|
|
1261
1264
|
self.logger.error("getLatest failed with error: \(backendError)")
|
|
1265
|
+
let statusCode = res.statusCode
|
|
1266
|
+
let responseIsOk = statusCode >= 200 && statusCode < 300
|
|
1262
1267
|
self.endBackGroundTaskWithNotif(
|
|
1263
1268
|
msg: res.message ?? backendError,
|
|
1264
1269
|
latestVersionName: res.version,
|
|
1265
1270
|
current: current,
|
|
1266
|
-
error: true
|
|
1271
|
+
error: true,
|
|
1272
|
+
sendStats: !responseIsOk
|
|
1267
1273
|
)
|
|
1268
1274
|
return
|
|
1269
1275
|
}
|
|
@@ -341,6 +341,7 @@ import UIKit
|
|
|
341
341
|
request.validate().responseDecodable(of: AppVersionDec.self) { response in
|
|
342
342
|
switch response.result {
|
|
343
343
|
case .success:
|
|
344
|
+
latest.statusCode = response.response?.statusCode ?? 0
|
|
344
345
|
if let url = response.value?.url {
|
|
345
346
|
latest.url = url
|
|
346
347
|
}
|
|
@@ -375,6 +376,7 @@ import UIKit
|
|
|
375
376
|
self.logger.error("Error getting Latest \(response.value.debugDescription) \(error)")
|
|
376
377
|
latest.message = "Error getting Latest \(String(describing: response.value))"
|
|
377
378
|
latest.error = "response_error"
|
|
379
|
+
latest.statusCode = response.response?.statusCode ?? 0
|
|
378
380
|
}
|
|
379
381
|
semaphore.signal()
|
|
380
382
|
}
|
|
@@ -160,6 +160,7 @@ struct AppVersionDec: Decodable {
|
|
|
160
160
|
let breaking: Bool?
|
|
161
161
|
let data: [String: String]?
|
|
162
162
|
let manifest: [ManifestEntry]?
|
|
163
|
+
// The HTTP status code is captured separately in CapgoUpdater; this struct only mirrors JSON.
|
|
163
164
|
}
|
|
164
165
|
|
|
165
166
|
public class AppVersion: NSObject {
|
|
@@ -173,6 +174,7 @@ public class AppVersion: NSObject {
|
|
|
173
174
|
var breaking: Bool?
|
|
174
175
|
var data: [String: String]?
|
|
175
176
|
var manifest: [ManifestEntry]?
|
|
177
|
+
var statusCode: Int = 0
|
|
176
178
|
}
|
|
177
179
|
|
|
178
180
|
extension AppVersion {
|