@capgo/capacitor-updater 6.25.8 → 6.27.11
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 +29 -10
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +10 -4
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +22 -12
- 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 = "6.
|
|
74
|
+
private final String pluginVersion = "6.27.11";
|
|
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
|
-
|
|
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
|
-
|
|
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()) {
|
|
@@ -1237,18 +1242,32 @@ public class CapgoUpdater {
|
|
|
1237
1242
|
return;
|
|
1238
1243
|
}
|
|
1239
1244
|
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
+
JSONObject json;
|
|
1246
|
+
try {
|
|
1247
|
+
json = this.createInfoObject();
|
|
1248
|
+
} catch (JSONException e) {
|
|
1249
|
+
logger.error("Error creating info object: " + e.getMessage());
|
|
1250
|
+
final Map<String, Object> retError = new HashMap<>();
|
|
1251
|
+
retError.put("message", "Cannot get info: " + e);
|
|
1252
|
+
retError.put("error", "json_error");
|
|
1253
|
+
callback.callback(retError);
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1245
1256
|
|
|
1246
|
-
// Build URL with query parameters
|
|
1257
|
+
// Build URL with query parameters from JSON
|
|
1247
1258
|
HttpUrl.Builder urlBuilder = HttpUrl.parse(channelUrl).newBuilder();
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1259
|
+
try {
|
|
1260
|
+
Iterator<String> keys = json.keys();
|
|
1261
|
+
while (keys.hasNext()) {
|
|
1262
|
+
String key = keys.next();
|
|
1263
|
+
Object value = json.get(key);
|
|
1264
|
+
if (value != null) {
|
|
1265
|
+
urlBuilder.addQueryParameter(key, value.toString());
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
} catch (JSONException e) {
|
|
1269
|
+
logger.error("Error adding query parameters: " + e.getMessage());
|
|
1270
|
+
}
|
|
1252
1271
|
|
|
1253
1272
|
Request request = new Request.Builder().url(urlBuilder.build()).get().build();
|
|
1254
1273
|
|
|
@@ -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 = "6.
|
|
57
|
+
private let pluginVersion: String = "6.27.11"
|
|
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"
|
|
@@ -1234,10 +1234,13 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
1234
1234
|
current: BundleInfo,
|
|
1235
1235
|
error: Bool = true,
|
|
1236
1236
|
failureAction: String = "download_fail",
|
|
1237
|
-
failureEvent: String = "downloadFailed"
|
|
1237
|
+
failureEvent: String = "downloadFailed",
|
|
1238
|
+
sendStats: Bool = true
|
|
1238
1239
|
) {
|
|
1239
1240
|
if error {
|
|
1240
|
-
|
|
1241
|
+
if sendStats {
|
|
1242
|
+
self.implementation.sendStats(action: failureAction, versionName: current.getVersionName())
|
|
1243
|
+
}
|
|
1241
1244
|
self.notifyListeners(failureEvent, data: ["version": latestVersionName])
|
|
1242
1245
|
}
|
|
1243
1246
|
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
|
|
@@ -1265,11 +1268,14 @@ public class CapacitorUpdaterPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
1265
1268
|
// Handle network errors and other failures first
|
|
1266
1269
|
if let backendError = res.error, !backendError.isEmpty {
|
|
1267
1270
|
self.logger.error("getLatest failed with error: \(backendError)")
|
|
1271
|
+
let statusCode = res.statusCode
|
|
1272
|
+
let responseIsOk = statusCode >= 200 && statusCode < 300
|
|
1268
1273
|
self.endBackGroundTaskWithNotif(
|
|
1269
1274
|
msg: res.message ?? backendError,
|
|
1270
1275
|
latestVersionName: res.version,
|
|
1271
1276
|
current: current,
|
|
1272
|
-
error: true
|
|
1277
|
+
error: true,
|
|
1278
|
+
sendStats: !responseIsOk
|
|
1273
1279
|
)
|
|
1274
1280
|
return
|
|
1275
1281
|
}
|
|
@@ -343,6 +343,7 @@ import UIKit
|
|
|
343
343
|
request.validate().responseDecodable(of: AppVersionDec.self) { response in
|
|
344
344
|
switch response.result {
|
|
345
345
|
case .success:
|
|
346
|
+
latest.statusCode = response.response?.statusCode ?? 0
|
|
346
347
|
if let url = response.value?.url {
|
|
347
348
|
latest.url = url
|
|
348
349
|
}
|
|
@@ -377,6 +378,7 @@ import UIKit
|
|
|
377
378
|
self.logger.error("Error getting Latest \(response.value.debugDescription) \(error)")
|
|
378
379
|
latest.message = "Error getting Latest \(String(describing: response.value))"
|
|
379
380
|
latest.error = "response_error"
|
|
381
|
+
latest.statusCode = response.response?.statusCode ?? 0
|
|
380
382
|
}
|
|
381
383
|
semaphore.signal()
|
|
382
384
|
}
|
|
@@ -1299,20 +1301,28 @@ import UIKit
|
|
|
1299
1301
|
|
|
1300
1302
|
let semaphore: DispatchSemaphore = DispatchSemaphore(value: 0)
|
|
1301
1303
|
|
|
1302
|
-
//
|
|
1303
|
-
let
|
|
1304
|
-
let platform = "ios"
|
|
1305
|
-
let isEmulator = self.isEmulator()
|
|
1306
|
-
let isProd = self.isProd()
|
|
1304
|
+
// Create info object and convert to query parameters
|
|
1305
|
+
let infoObject = self.createInfoObject()
|
|
1307
1306
|
|
|
1308
|
-
// Create query parameters
|
|
1307
|
+
// Create query parameters from InfoObject
|
|
1309
1308
|
var urlComponents = URLComponents(string: self.channelUrl)
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1309
|
+
var queryItems: [URLQueryItem] = []
|
|
1310
|
+
|
|
1311
|
+
// Convert InfoObject to dictionary using Mirror
|
|
1312
|
+
let mirror = Mirror(reflecting: infoObject)
|
|
1313
|
+
for child in mirror.children {
|
|
1314
|
+
if let key = child.label, let value = child.value as? CustomStringConvertible {
|
|
1315
|
+
queryItems.append(URLQueryItem(name: key, value: String(describing: value)))
|
|
1316
|
+
} else if let key = child.label {
|
|
1317
|
+
// Handle optional values
|
|
1318
|
+
let mirror = Mirror(reflecting: child.value)
|
|
1319
|
+
if let value = mirror.children.first?.value {
|
|
1320
|
+
queryItems.append(URLQueryItem(name: key, value: String(describing: value)))
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
urlComponents?.queryItems = queryItems
|
|
1316
1326
|
|
|
1317
1327
|
guard let url = urlComponents?.url else {
|
|
1318
1328
|
logger.error("Invalid channel URL")
|
|
@@ -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 {
|