Skip to content

Commit

Permalink
fix: add download_fail event
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Oct 28, 2022
1 parent f63864a commit f00713b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ public void run() {
final JSObject ret = new JSObject();
ret.put("version", version);
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
CapacitorUpdaterPlugin.this.implementation.sendStats("download_fail", current.getVersionName());
}
}
}
Expand Down Expand Up @@ -713,6 +715,8 @@ public void run() {
final JSObject ret = new JSObject();
ret.put("version", latestVersionName);
CapacitorUpdaterPlugin.this.notifyListeners("downloadFailed", ret);
final BundleInfo current = CapacitorUpdaterPlugin.this.implementation.getCurrentBundle();
CapacitorUpdaterPlugin.this.implementation.sendStats("download_fail", current.getVersionName());
final JSObject retNoNeed = new JSObject();
retNoNeed.put("bundle", current.toJSON());
CapacitorUpdaterPlugin.this.notifyListeners("noNeedUpdate", retNoNeed);
Expand Down
6 changes: 5 additions & 1 deletion ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
let url = URL(string: urlString)
print("\(self.implementation.TAG) Downloading \(url!)")
do {
let res = try implementation.download(url: url!, version: version)
let res = try self.implementation.download(url: url!, version: version)
call.resolve(res.toJSON())
} catch {
print("\(self.implementation.TAG) Failed to download from: \(url!) \(error.localizedDescription)")
self.notifyListeners("downloadFailed", data: ["version": version])
let current: BundleInfo = self.implementation.getCurrentBundle()
self.implementation.sendStats(action: "download_fail", versionName: current.getVersionName())
call.reject("Failed to download from: \(url!)", error.localizedDescription)
}
}
Expand Down Expand Up @@ -480,6 +482,8 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
_ = self.implementation.setNextBundle(next: next.getId())
} catch {
print("\(self.implementation.TAG) Error downloading file", error.localizedDescription)
let current: BundleInfo = self.implementation.getCurrentBundle()
self.implementation.sendStats(action: "download_fail", versionName: current.getVersionName())
self.notifyListeners("downloadFailed", data: ["version": latestVersionName])
self.notifyListeners("noNeedUpdate", data: ["bundle": current.toJSON()])
}
Expand Down

0 comments on commit f00713b

Please sign in to comment.