@capgo/capacitor-updater 5.6.15 → 5.7.1
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/CapacitorUpdater.java +26 -10
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +4 -17
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +3 -0
- package/ios/Plugin/CapacitorUpdater.swift +23 -6
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +3 -5
- package/package.json +1 -1
|
@@ -187,6 +187,7 @@ public class CapacitorUpdater {
|
|
|
187
187
|
"unzip: Windows path is not supported, please use unix path as require by zip RFC: " +
|
|
188
188
|
entry.getName()
|
|
189
189
|
);
|
|
190
|
+
this.sendStats("windows_path_fail");
|
|
190
191
|
}
|
|
191
192
|
final File file = new File(targetDirectory, entry.getName());
|
|
192
193
|
final String canonicalPath = file.getCanonicalPath();
|
|
@@ -194,6 +195,7 @@ public class CapacitorUpdater {
|
|
|
194
195
|
final File dir = entry.isDirectory() ? file : file.getParentFile();
|
|
195
196
|
|
|
196
197
|
if (!canonicalPath.startsWith(canonicalDir)) {
|
|
198
|
+
this.sendStats("canonical_path_fail");
|
|
197
199
|
throw new FileNotFoundException(
|
|
198
200
|
"SecurityException, Failed to ensure directory is the start path : " +
|
|
199
201
|
canonicalDir +
|
|
@@ -203,6 +205,8 @@ public class CapacitorUpdater {
|
|
|
203
205
|
}
|
|
204
206
|
|
|
205
207
|
if (!dir.isDirectory() && !dir.mkdirs()) {
|
|
208
|
+
final JSObject ret = new JSObject();
|
|
209
|
+
this.sendStats("directory_path_fail");
|
|
206
210
|
throw new FileNotFoundException(
|
|
207
211
|
"Failed to ensure directory: " + dir.getAbsolutePath()
|
|
208
212
|
);
|
|
@@ -229,6 +233,9 @@ public class CapacitorUpdater {
|
|
|
229
233
|
lengthRead += entry.getCompressedSize();
|
|
230
234
|
}
|
|
231
235
|
return targetDirectory;
|
|
236
|
+
} catch (IOException e) {
|
|
237
|
+
this.sendStats("unzip_fail");
|
|
238
|
+
throw new IOException("Failed to unzip: " + zipFile.getPath());
|
|
232
239
|
}
|
|
233
240
|
}
|
|
234
241
|
|
|
@@ -291,6 +298,7 @@ public class CapacitorUpdater {
|
|
|
291
298
|
String version = bundle.getString(DownloadService.VERSION);
|
|
292
299
|
String sessionKey = bundle.getString(DownloadService.SESSIONKEY);
|
|
293
300
|
String checksum = bundle.getString(DownloadService.CHECKSUM);
|
|
301
|
+
String error = bundle.getString(DownloadService.ERROR);
|
|
294
302
|
Log.i(
|
|
295
303
|
CapacitorUpdater.TAG,
|
|
296
304
|
"res " +
|
|
@@ -302,7 +310,9 @@ public class CapacitorUpdater {
|
|
|
302
310
|
" " +
|
|
303
311
|
sessionKey +
|
|
304
312
|
" " +
|
|
305
|
-
checksum
|
|
313
|
+
checksum +
|
|
314
|
+
" " +
|
|
315
|
+
error
|
|
306
316
|
);
|
|
307
317
|
if (dest == null) {
|
|
308
318
|
final JSObject ret = new JSObject();
|
|
@@ -310,11 +320,12 @@ public class CapacitorUpdater {
|
|
|
310
320
|
"version",
|
|
311
321
|
CapacitorUpdater.this.getCurrentBundle().getVersionName()
|
|
312
322
|
);
|
|
323
|
+
if ("low_mem_fail".equals(error)) {
|
|
324
|
+
CapacitorUpdater.this.sendStats("low_mem_fail", version);
|
|
325
|
+
}
|
|
326
|
+
ret.put("error", "download_fail");
|
|
327
|
+
CapacitorUpdater.this.sendStats("download_fail", version);
|
|
313
328
|
CapacitorUpdater.this.notifyListeners("downloadFailed", ret);
|
|
314
|
-
CapacitorUpdater.this.sendStats(
|
|
315
|
-
"download_fail",
|
|
316
|
-
CapacitorUpdater.this.getCurrentBundle().getVersionName()
|
|
317
|
-
);
|
|
318
329
|
return;
|
|
319
330
|
}
|
|
320
331
|
CapacitorUpdater.this.finishDownload(
|
|
@@ -370,7 +381,7 @@ public class CapacitorUpdater {
|
|
|
370
381
|
CapacitorUpdater.TAG,
|
|
371
382
|
"Error checksum " + checksumRes + " " + checksum
|
|
372
383
|
);
|
|
373
|
-
this.sendStats("checksum_fail"
|
|
384
|
+
this.sendStats("checksum_fail");
|
|
374
385
|
final Boolean res = this.delete(id);
|
|
375
386
|
if (res) {
|
|
376
387
|
Log.i(
|
|
@@ -399,10 +410,7 @@ public class CapacitorUpdater {
|
|
|
399
410
|
CapacitorUpdater.this.getCurrentBundle().getVersionName()
|
|
400
411
|
);
|
|
401
412
|
CapacitorUpdater.this.notifyListeners("downloadFailed", ret);
|
|
402
|
-
CapacitorUpdater.this.sendStats(
|
|
403
|
-
"download_fail",
|
|
404
|
-
CapacitorUpdater.this.getCurrentBundle().getVersionName()
|
|
405
|
-
);
|
|
413
|
+
CapacitorUpdater.this.sendStats("download_fail");
|
|
406
414
|
return false;
|
|
407
415
|
}
|
|
408
416
|
return true;
|
|
@@ -464,6 +472,10 @@ public class CapacitorUpdater {
|
|
|
464
472
|
}
|
|
465
473
|
bytesRead += length;
|
|
466
474
|
}
|
|
475
|
+
} catch (OutOfMemoryError e) {
|
|
476
|
+
Log.e(TAG, "OutOfMemoryError while downloading file", e);
|
|
477
|
+
this.sendStats("low_mem_fail");
|
|
478
|
+
throw new IOException("OutOfMemoryError while downloading file");
|
|
467
479
|
}
|
|
468
480
|
return target;
|
|
469
481
|
}
|
|
@@ -1050,6 +1062,10 @@ public class CapacitorUpdater {
|
|
|
1050
1062
|
this.requestQueue.add(setRetryPolicy(request));
|
|
1051
1063
|
}
|
|
1052
1064
|
|
|
1065
|
+
public void sendStats(final String action) {
|
|
1066
|
+
this.sendStats(action, this.getCurrentBundle().getVersionName());
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1053
1069
|
public void sendStats(final String action, final String versionName) {
|
|
1054
1070
|
String statsUrl = this.statsUrl;
|
|
1055
1071
|
if (statsUrl == null || "".equals(statsUrl) || statsUrl.length() == 0) {
|
|
@@ -55,7 +55,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
55
55
|
private static final String channelUrlDefault =
|
|
56
56
|
"https://api.capgo.app/channel_self";
|
|
57
57
|
|
|
58
|
-
private final String PLUGIN_VERSION = "5.
|
|
58
|
+
private final String PLUGIN_VERSION = "5.7.1";
|
|
59
59
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
60
60
|
|
|
61
61
|
private SharedPreferences.Editor editor;
|
|
@@ -606,12 +606,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
606
606
|
final JSObject ret = new JSObject();
|
|
607
607
|
ret.put("version", version);
|
|
608
608
|
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
609
|
-
|
|
610
|
-
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
611
|
-
CapacitorUpdaterPlugin.this.implementation.sendStats(
|
|
612
|
-
"download_fail",
|
|
613
|
-
current.getVersionName()
|
|
614
|
-
);
|
|
609
|
+
CapacitorUpdaterPlugin.this.implementation.sendStats("download_fail");
|
|
615
610
|
}
|
|
616
611
|
});
|
|
617
612
|
} catch (final Exception e) {
|
|
@@ -620,12 +615,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
620
615
|
final JSObject ret = new JSObject();
|
|
621
616
|
ret.put("version", version);
|
|
622
617
|
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
|
|
623
|
-
|
|
624
|
-
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
625
|
-
CapacitorUpdaterPlugin.this.implementation.sendStats(
|
|
626
|
-
"download_fail",
|
|
627
|
-
current.getVersionName()
|
|
628
|
-
);
|
|
618
|
+
CapacitorUpdaterPlugin.this.implementation.sendStats("download_fail");
|
|
629
619
|
}
|
|
630
620
|
}
|
|
631
621
|
|
|
@@ -1449,11 +1439,8 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
1449
1439
|
}
|
|
1450
1440
|
|
|
1451
1441
|
public void appMovedToBackground() {
|
|
1452
|
-
final BundleInfo current =
|
|
1453
|
-
CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
|
|
1454
1442
|
CapacitorUpdaterPlugin.this.implementation.sendStats(
|
|
1455
|
-
"app_moved_to_background"
|
|
1456
|
-
current.getVersionName()
|
|
1443
|
+
"app_moved_to_background"
|
|
1457
1444
|
);
|
|
1458
1445
|
Log.i(CapacitorUpdater.TAG, "Checking for pending update");
|
|
1459
1446
|
try {
|
|
@@ -84,6 +84,9 @@ public class DownloadService extends IntentService {
|
|
|
84
84
|
publishResults(dest, id, version, checksum, sessionKey, "");
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
+
} catch (OutOfMemoryError e) {
|
|
88
|
+
e.printStackTrace();
|
|
89
|
+
publishResults("", id, version, checksum, sessionKey, "low_mem_fail");
|
|
87
90
|
} catch (Exception e) {
|
|
88
91
|
e.printStackTrace();
|
|
89
92
|
publishResults(
|
|
@@ -412,6 +412,7 @@ extension CustomError: LocalizedError {
|
|
|
412
412
|
let destHot: URL = base.appendingPathComponent(id)
|
|
413
413
|
let destUnZip: URL = documentsDir.appendingPathComponent(randomString(length: 10))
|
|
414
414
|
if !SSZipArchive.unzipFile(atPath: sourceZip.path, toDestination: destUnZip.path) {
|
|
415
|
+
self.sendStats(action: "unzip_fail")
|
|
415
416
|
throw CustomError.cannotUnzip
|
|
416
417
|
}
|
|
417
418
|
if try unflatFolder(source: destUnZip, dest: destHot) {
|
|
@@ -526,6 +527,11 @@ extension CustomError: LocalizedError {
|
|
|
526
527
|
}
|
|
527
528
|
case let .failure(error):
|
|
528
529
|
print("\(self.TAG) download error", response.value ?? "", error)
|
|
530
|
+
if let afError = error as? AFError,
|
|
531
|
+
case .sessionTaskFailed(let urlError as URLError) = afError,
|
|
532
|
+
urlError.code == .cannotWriteToFile {
|
|
533
|
+
self.sendStats(action: "low_mem_fail", versionName: version)
|
|
534
|
+
}
|
|
529
535
|
mainError = error as NSError
|
|
530
536
|
}
|
|
531
537
|
}
|
|
@@ -664,7 +670,7 @@ extension CustomError: LocalizedError {
|
|
|
664
670
|
self.setFallbackBundle(fallback: Optional<BundleInfo>.none)
|
|
665
671
|
_ = self.setNextBundle(next: Optional<String>.none)
|
|
666
672
|
if !isInternal {
|
|
667
|
-
self.sendStats(action: "reset"
|
|
673
|
+
self.sendStats(action: "reset")
|
|
668
674
|
}
|
|
669
675
|
}
|
|
670
676
|
|
|
@@ -802,18 +808,29 @@ extension CustomError: LocalizedError {
|
|
|
802
808
|
return getChannel
|
|
803
809
|
}
|
|
804
810
|
|
|
805
|
-
func sendStats(action: String, versionName: String) {
|
|
806
|
-
|
|
811
|
+
func sendStats(action: String, versionName: String? = nil) {
|
|
812
|
+
guard !statsUrl.isEmpty else {
|
|
807
813
|
return
|
|
808
814
|
}
|
|
809
|
-
|
|
815
|
+
|
|
816
|
+
let versionName = versionName ?? getCurrentBundle().getVersionName()
|
|
817
|
+
|
|
818
|
+
var parameters = createInfoObject()
|
|
810
819
|
parameters.action = action
|
|
820
|
+
|
|
811
821
|
DispatchQueue.global(qos: .background).async {
|
|
812
|
-
let request = AF.request(
|
|
822
|
+
let request = AF.request(
|
|
823
|
+
self.statsUrl,
|
|
824
|
+
method: .post,
|
|
825
|
+
parameters: parameters,
|
|
826
|
+
encoder: JSONParameterEncoder.default,
|
|
827
|
+
requestModifier: { $0.timeoutInterval = self.timeout }
|
|
828
|
+
)
|
|
829
|
+
|
|
813
830
|
request.responseData { response in
|
|
814
831
|
switch response.result {
|
|
815
832
|
case .success:
|
|
816
|
-
print("\(self.TAG) Stats
|
|
833
|
+
print("\(self.TAG) Stats sent for \(action), version \(versionName)")
|
|
817
834
|
case let .failure(error):
|
|
818
835
|
print("\(self.TAG) Error sending stats: ", response.value ?? "", error)
|
|
819
836
|
}
|
|
@@ -15,7 +15,7 @@ import Version
|
|
|
15
15
|
@objc(CapacitorUpdaterPlugin)
|
|
16
16
|
public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
17
17
|
public var implementation = CapacitorUpdater()
|
|
18
|
-
private let PLUGIN_VERSION: String = "5.
|
|
18
|
+
private let PLUGIN_VERSION: String = "5.7.1"
|
|
19
19
|
static let updateUrlDefault = "https://api.capgo.app/updates"
|
|
20
20
|
static let statsUrlDefault = "https://api.capgo.app/stats"
|
|
21
21
|
static let channelUrlDefault = "https://api.capgo.app/channel_self"
|
|
@@ -232,8 +232,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
232
232
|
} catch {
|
|
233
233
|
print("\(self.implementation.TAG) Failed to download from: \(String(describing: url)) \(error.localizedDescription)")
|
|
234
234
|
self.notifyListeners("downloadFailed", data: ["version": version])
|
|
235
|
-
|
|
236
|
-
self.implementation.sendStats(action: "download_fail", versionName: current.getVersionName())
|
|
235
|
+
self.implementation.sendStats(action: "download_fail")
|
|
237
236
|
call.reject("Failed to download from: \(url!)", error.localizedDescription)
|
|
238
237
|
}
|
|
239
238
|
}
|
|
@@ -805,8 +804,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
|
805
804
|
}
|
|
806
805
|
|
|
807
806
|
@objc func appMovedToBackground() {
|
|
808
|
-
|
|
809
|
-
self.implementation.sendStats(action: "app_moved_to_background", versionName: current.getVersionName())
|
|
807
|
+
self.implementation.sendStats(action: "app_moved_to_background")
|
|
810
808
|
print("\(self.implementation.TAG) Check for pending update")
|
|
811
809
|
let delayUpdatePreferences = UserDefaults.standard.string(forKey: DELAY_CONDITION_PREFERENCES) ?? "[]"
|
|
812
810
|
|