@capgo/capacitor-updater 5.6.14 → 5.7.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/CapacitorUpdater.java +14 -9
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +4 -17
- package/ios/Plugin/CapacitorUpdater.swift +18 -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
|
|
|
@@ -311,10 +318,7 @@ public class CapacitorUpdater {
|
|
|
311
318
|
CapacitorUpdater.this.getCurrentBundle().getVersionName()
|
|
312
319
|
);
|
|
313
320
|
CapacitorUpdater.this.notifyListeners("downloadFailed", ret);
|
|
314
|
-
CapacitorUpdater.this.sendStats(
|
|
315
|
-
"download_fail",
|
|
316
|
-
CapacitorUpdater.this.getCurrentBundle().getVersionName()
|
|
317
|
-
);
|
|
321
|
+
CapacitorUpdater.this.sendStats("download_fail");
|
|
318
322
|
return;
|
|
319
323
|
}
|
|
320
324
|
CapacitorUpdater.this.finishDownload(
|
|
@@ -370,7 +374,7 @@ public class CapacitorUpdater {
|
|
|
370
374
|
CapacitorUpdater.TAG,
|
|
371
375
|
"Error checksum " + checksumRes + " " + checksum
|
|
372
376
|
);
|
|
373
|
-
this.sendStats("checksum_fail"
|
|
377
|
+
this.sendStats("checksum_fail");
|
|
374
378
|
final Boolean res = this.delete(id);
|
|
375
379
|
if (res) {
|
|
376
380
|
Log.i(
|
|
@@ -399,10 +403,7 @@ public class CapacitorUpdater {
|
|
|
399
403
|
CapacitorUpdater.this.getCurrentBundle().getVersionName()
|
|
400
404
|
);
|
|
401
405
|
CapacitorUpdater.this.notifyListeners("downloadFailed", ret);
|
|
402
|
-
CapacitorUpdater.this.sendStats(
|
|
403
|
-
"download_fail",
|
|
404
|
-
CapacitorUpdater.this.getCurrentBundle().getVersionName()
|
|
405
|
-
);
|
|
406
|
+
CapacitorUpdater.this.sendStats("download_fail");
|
|
406
407
|
return false;
|
|
407
408
|
}
|
|
408
409
|
return true;
|
|
@@ -1050,6 +1051,10 @@ public class CapacitorUpdater {
|
|
|
1050
1051
|
this.requestQueue.add(setRetryPolicy(request));
|
|
1051
1052
|
}
|
|
1052
1053
|
|
|
1054
|
+
public void sendStats(final String action) {
|
|
1055
|
+
this.sendStats(action, this.getCurrentBundle().getVersionName());
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1053
1058
|
public void sendStats(final String action, final String versionName) {
|
|
1054
1059
|
String statsUrl = this.statsUrl;
|
|
1055
1060
|
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.0";
|
|
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 {
|
|
@@ -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) {
|
|
@@ -664,7 +665,7 @@ extension CustomError: LocalizedError {
|
|
|
664
665
|
self.setFallbackBundle(fallback: Optional<BundleInfo>.none)
|
|
665
666
|
_ = self.setNextBundle(next: Optional<String>.none)
|
|
666
667
|
if !isInternal {
|
|
667
|
-
self.sendStats(action: "reset"
|
|
668
|
+
self.sendStats(action: "reset")
|
|
668
669
|
}
|
|
669
670
|
}
|
|
670
671
|
|
|
@@ -802,18 +803,29 @@ extension CustomError: LocalizedError {
|
|
|
802
803
|
return getChannel
|
|
803
804
|
}
|
|
804
805
|
|
|
805
|
-
func sendStats(action: String, versionName: String) {
|
|
806
|
-
|
|
806
|
+
func sendStats(action: String, versionName: String? = nil) {
|
|
807
|
+
guard !statsUrl.isEmpty else {
|
|
807
808
|
return
|
|
808
809
|
}
|
|
809
|
-
|
|
810
|
+
|
|
811
|
+
let versionName = versionName ?? getCurrentBundle().getVersionName()
|
|
812
|
+
|
|
813
|
+
var parameters = createInfoObject()
|
|
810
814
|
parameters.action = action
|
|
815
|
+
|
|
811
816
|
DispatchQueue.global(qos: .background).async {
|
|
812
|
-
let request = AF.request(
|
|
817
|
+
let request = AF.request(
|
|
818
|
+
self.statsUrl,
|
|
819
|
+
method: .post,
|
|
820
|
+
parameters: parameters,
|
|
821
|
+
encoder: JSONParameterEncoder.default,
|
|
822
|
+
requestModifier: { $0.timeoutInterval = self.timeout }
|
|
823
|
+
)
|
|
824
|
+
|
|
813
825
|
request.responseData { response in
|
|
814
826
|
switch response.result {
|
|
815
827
|
case .success:
|
|
816
|
-
print("\(self.TAG) Stats
|
|
828
|
+
print("\(self.TAG) Stats sent for \(action), version \(versionName)")
|
|
817
829
|
case let .failure(error):
|
|
818
830
|
print("\(self.TAG) Error sending stats: ", response.value ?? "", error)
|
|
819
831
|
}
|
|
@@ -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.0"
|
|
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
|
|