Skip to content

Commit

Permalink
fix: download async
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Nov 29, 2022
1 parent 5d23d18 commit 8dd0d54
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,17 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
}
let url = URL(string: urlString)
print("\(self.implementation.TAG) Downloading \(url!)")
do {
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)
DispatchQueue.global(qos: .background).async {
do {
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

0 comments on commit 8dd0d54

Please sign in to comment.