@capgo/capacitor-updater 6.1.6 → 6.1.8
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 +5 -9
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +1 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/DownloadService.java +4 -4
- package/ios/Plugin/CapacitorUpdater.swift +38 -22
- package/ios/Plugin/CapacitorUpdaterPlugin.swift +1 -1
- package/package.json +1 -1
|
@@ -254,17 +254,13 @@ public class CapacitorUpdater {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
public void onResume() {
|
|
257
|
+
IntentFilter filter = new IntentFilter();
|
|
258
|
+
filter.addAction(DownloadService.NOTIFICATION);
|
|
259
|
+
filter.addAction(DownloadService.PERCENTDOWNLOAD);
|
|
257
260
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
258
|
-
this.activity.registerReceiver(
|
|
259
|
-
receiver,
|
|
260
|
-
new IntentFilter(DownloadService.NOTIFICATION),
|
|
261
|
-
RECEIVER_NOT_EXPORTED
|
|
262
|
-
);
|
|
261
|
+
this.activity.registerReceiver(receiver, filter, RECEIVER_NOT_EXPORTED);
|
|
263
262
|
} else {
|
|
264
|
-
this.activity.registerReceiver(
|
|
265
|
-
receiver,
|
|
266
|
-
new IntentFilter(DownloadService.NOTIFICATION)
|
|
267
|
-
);
|
|
263
|
+
this.activity.registerReceiver(receiver, filter);
|
|
268
264
|
}
|
|
269
265
|
}
|
|
270
266
|
|
|
@@ -56,7 +56,7 @@ public class CapacitorUpdaterPlugin extends Plugin {
|
|
|
56
56
|
private static final String channelUrlDefault =
|
|
57
57
|
"https://api.capgo.app/channel_self";
|
|
58
58
|
|
|
59
|
-
private final String PLUGIN_VERSION = "6.1.
|
|
59
|
+
private final String PLUGIN_VERSION = "6.1.8";
|
|
60
60
|
private static final String DELAY_CONDITION_PREFERENCES = "";
|
|
61
61
|
|
|
62
62
|
private SharedPreferences.Editor editor;
|
|
@@ -118,7 +118,7 @@ public class DownloadService extends IntentService {
|
|
|
118
118
|
|
|
119
119
|
int bytesRead = -1;
|
|
120
120
|
byte[] buffer = new byte[4096];
|
|
121
|
-
int
|
|
121
|
+
int lastNotifiedPercent = 0;
|
|
122
122
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
123
123
|
outputStream.write(buffer, 0, bytesRead);
|
|
124
124
|
downloadedBytes += bytesRead;
|
|
@@ -128,9 +128,9 @@ public class DownloadService extends IntentService {
|
|
|
128
128
|
}
|
|
129
129
|
// Computing percentage
|
|
130
130
|
int percent = calcTotalPercent(downloadedBytes, contentLength);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
while (lastNotifiedPercent + 10 <= percent) {
|
|
132
|
+
lastNotifiedPercent += 10;
|
|
133
|
+
notifyDownload(id, lastNotifiedPercent);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -661,13 +661,13 @@ extension CustomError: LocalizedError {
|
|
|
661
661
|
self.savePartialData(startingAt: UInt64(totalReceivedBytes)) // Saving the received data in the package.tmp file
|
|
662
662
|
totalReceivedBytes += Int64(data.count)
|
|
663
663
|
|
|
664
|
-
let percent = Int((Double(totalReceivedBytes) / Double(targetSize)) *
|
|
664
|
+
let percent = max(10, Int((Double(totalReceivedBytes) / Double(targetSize)) * 70.0))
|
|
665
665
|
|
|
666
666
|
print("\(self.TAG) Downloading: \(percent)%")
|
|
667
667
|
let currentMilestone = (percent / 10) * 10
|
|
668
668
|
if currentMilestone > lastSentProgress && currentMilestone <= 70 {
|
|
669
669
|
for milestone in stride(from: lastSentProgress + 10, through: currentMilestone, by: 10) {
|
|
670
|
-
|
|
670
|
+
self.notifyDownload(id: id, percent: milestone, ignoreMultipleOfTen: false)
|
|
671
671
|
}
|
|
672
672
|
lastSentProgress = currentMilestone
|
|
673
673
|
}
|
|
@@ -680,6 +680,7 @@ extension CustomError: LocalizedError {
|
|
|
680
680
|
|
|
681
681
|
case .complete(_):
|
|
682
682
|
print("\(self.TAG) Download complete, total received bytes: \(totalReceivedBytes)")
|
|
683
|
+
self.notifyDownload(id: id, percent: 70, ignoreMultipleOfTen: true)
|
|
683
684
|
semaphore.signal()
|
|
684
685
|
}
|
|
685
686
|
}
|
|
@@ -727,7 +728,9 @@ extension CustomError: LocalizedError {
|
|
|
727
728
|
|
|
728
729
|
do {
|
|
729
730
|
checksum = self.calcChecksum(filePath: finalPath)
|
|
731
|
+
print("\(self.TAG) Downloading: 80% (unzipping)")
|
|
730
732
|
try self.saveDownloaded(sourceZip: finalPath, id: id, base: self.libraryDir.appendingPathComponent(self.bundleDirectory), notify: true)
|
|
733
|
+
|
|
731
734
|
} catch {
|
|
732
735
|
print("\(self.TAG) Failed to unzip file: \(error)")
|
|
733
736
|
self.saveBundleInfo(id: id, bundle: BundleInfo(id: id, version: version, status: BundleStatus.ERROR, downloaded: Date(), checksum: checksum))
|
|
@@ -736,10 +739,13 @@ extension CustomError: LocalizedError {
|
|
|
736
739
|
throw error
|
|
737
740
|
}
|
|
738
741
|
|
|
742
|
+
self.notifyDownload(id: id, percent: 90)
|
|
743
|
+
print("\(self.TAG) Downloading: 90% (wrapping up)")
|
|
739
744
|
let info = BundleInfo(id: id, version: version, status: BundleStatus.PENDING, downloaded: Date(), checksum: checksum)
|
|
740
745
|
self.saveBundleInfo(id: id, bundle: info)
|
|
741
|
-
self.notifyDownload(id: id, percent: 100)
|
|
742
746
|
self.cleanDlData()
|
|
747
|
+
self.notifyDownload(id: id, percent: 100)
|
|
748
|
+
print("\(self.TAG) Downloading: 100% (complete)")
|
|
743
749
|
return info
|
|
744
750
|
}
|
|
745
751
|
private func ensureResumableFilesExist() {
|
|
@@ -1080,38 +1086,48 @@ extension CustomError: LocalizedError {
|
|
|
1080
1086
|
return getChannel
|
|
1081
1087
|
}
|
|
1082
1088
|
|
|
1089
|
+
private let operationQueue = OperationQueue()
|
|
1090
|
+
|
|
1083
1091
|
func sendStats(action: String, versionName: String? = nil, oldVersionName: String? = "") {
|
|
1084
1092
|
guard !statsUrl.isEmpty else {
|
|
1085
1093
|
return
|
|
1086
1094
|
}
|
|
1095
|
+
operationQueue.maxConcurrentOperationCount = 1
|
|
1087
1096
|
|
|
1088
1097
|
let versionName = versionName ?? getCurrentBundle().getVersionName()
|
|
1089
1098
|
|
|
1090
1099
|
var parameters = createInfoObject()
|
|
1091
1100
|
parameters.action = action
|
|
1092
1101
|
parameters.version_name = versionName
|
|
1093
|
-
parameters.old_version_name = oldVersionName
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1102
|
+
parameters.old_version_name = oldVersionName ?? ""
|
|
1103
|
+
|
|
1104
|
+
|
|
1105
|
+
let operation = BlockOperation {
|
|
1106
|
+
let semaphore = DispatchSemaphore(value: 0)
|
|
1107
|
+
AF.request(
|
|
1108
|
+
self.statsUrl,
|
|
1109
|
+
method: .post,
|
|
1110
|
+
parameters: parameters,
|
|
1111
|
+
encoder: JSONParameterEncoder.default,
|
|
1112
|
+
requestModifier: { $0.timeoutInterval = self.timeout }
|
|
1113
|
+
).responseData { response in
|
|
1114
|
+
switch response.result {
|
|
1115
|
+
case .success:
|
|
1116
|
+
print("\(self.TAG) Stats sent for \(action), version \(versionName)")
|
|
1117
|
+
case let .failure(error):
|
|
1118
|
+
print("\(self.TAG) Error sending stats: ", response.value ?? "", error.localizedDescription)
|
|
1119
|
+
}
|
|
1120
|
+
semaphore.signal()
|
|
1121
|
+
}
|
|
1122
|
+
semaphore.wait()
|
|
1123
|
+
}
|
|
1124
|
+
operationQueue.addOperation(operation)
|
|
1125
|
+
|
|
1103
1126
|
|
|
1104
|
-
|
|
1105
|
-
switch response.result {
|
|
1106
|
-
case .success:
|
|
1107
|
-
print("\(self.TAG) Stats sent for \(action), version \(versionName)")
|
|
1108
|
-
case let .failure(error):
|
|
1109
|
-
print("\(self.TAG) Error sending stats: ", response.value ?? "", error)
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1127
|
+
|
|
1113
1128
|
}
|
|
1114
1129
|
|
|
1130
|
+
|
|
1115
1131
|
public func getBundleInfo(id: String?) -> BundleInfo {
|
|
1116
1132
|
var trueId = BundleInfo.VERSION_UNKNOWN
|
|
1117
1133
|
if id != nil {
|
|
@@ -16,7 +16,7 @@ import SwiftyRSA
|
|
|
16
16
|
@objc(CapacitorUpdaterPlugin)
|
|
17
17
|
public class CapacitorUpdaterPlugin: CAPPlugin {
|
|
18
18
|
public var implementation = CapacitorUpdater()
|
|
19
|
-
private let PLUGIN_VERSION: String = "6.1.
|
|
19
|
+
private let PLUGIN_VERSION: String = "6.1.8"
|
|
20
20
|
static let updateUrlDefault = "https://api.capgo.app/updates"
|
|
21
21
|
static let statsUrlDefault = "https://api.capgo.app/stats"
|
|
22
22
|
static let channelUrlDefault = "https://api.capgo.app/channel_self"
|