@capgo/capacitor-updater 8.49.1 → 8.49.3
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/README.md +30 -7
- package/android/src/main/java/ee/forgr/capacitor_updater/CapacitorUpdaterPlugin.java +110 -1
- package/android/src/main/java/ee/forgr/capacitor_updater/CapgoUpdater.java +44 -5
- package/android/src/main/java/ee/forgr/capacitor_updater/DeviceIdHelper.java +45 -30
- package/dist/docs.json +3 -3
- package/dist/esm/definitions.d.ts +15 -6
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapacitorUpdaterPlugin.swift +87 -1
- package/ios/Sources/CapacitorUpdaterPlugin/CapgoUpdater.swift +32 -6
- package/package.json +1 -1
|
@@ -51,11 +51,16 @@ import UIKit
|
|
|
51
51
|
private static var rateLimitStatisticSent = false
|
|
52
52
|
|
|
53
53
|
// Stats batching - queue events and send max once per second
|
|
54
|
-
private var statsQueue: [
|
|
54
|
+
private var statsQueue: [QueuedStatsEvent] = []
|
|
55
55
|
private let statsQueueLock = NSLock()
|
|
56
56
|
private var statsFlushTimer: Timer?
|
|
57
57
|
private static let statsFlushInterval: TimeInterval = 1.0
|
|
58
58
|
|
|
59
|
+
private struct QueuedStatsEvent {
|
|
60
|
+
let event: StatsEvent
|
|
61
|
+
let onSent: (() -> Void)?
|
|
62
|
+
}
|
|
63
|
+
|
|
59
64
|
private static func sanitizeHeaderValue(_ value: String) -> String {
|
|
60
65
|
if value.isEmpty {
|
|
61
66
|
return "unknown"
|
|
@@ -2474,14 +2479,24 @@ import UIKit
|
|
|
2474
2479
|
}()
|
|
2475
2480
|
|
|
2476
2481
|
func sendStats(action: String, versionName: String? = nil, oldVersionName: String? = "") {
|
|
2477
|
-
sendStatsWithMetadata(action: action, versionName: versionName, oldVersionName: oldVersionName, metadata: nil)
|
|
2482
|
+
sendStatsWithMetadata(action: action, versionName: versionName, oldVersionName: oldVersionName, metadata: nil, onSent: nil)
|
|
2478
2483
|
}
|
|
2479
2484
|
|
|
2480
2485
|
func sendStats(action: String, versionName: String?, oldVersionName: String?, metadata: [String: String]) {
|
|
2481
|
-
sendStatsWithMetadata(action: action, versionName: versionName, oldVersionName: oldVersionName, metadata: metadata)
|
|
2486
|
+
sendStatsWithMetadata(action: action, versionName: versionName, oldVersionName: oldVersionName, metadata: metadata, onSent: nil)
|
|
2482
2487
|
}
|
|
2483
2488
|
|
|
2484
|
-
|
|
2489
|
+
func sendStats(action: String, versionName: String?, oldVersionName: String?, metadata: [String: String], onSent: @escaping () -> Void) {
|
|
2490
|
+
sendStatsWithMetadata(action: action, versionName: versionName, oldVersionName: oldVersionName, metadata: metadata, onSent: onSent)
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
private func sendStatsWithMetadata(
|
|
2494
|
+
action: String,
|
|
2495
|
+
versionName: String?,
|
|
2496
|
+
oldVersionName: String?,
|
|
2497
|
+
metadata: [String: String]?,
|
|
2498
|
+
onSent: (() -> Void)?
|
|
2499
|
+
) {
|
|
2485
2500
|
if previewSession {
|
|
2486
2501
|
logger.debug("Skipping sendStats during preview session.")
|
|
2487
2502
|
return
|
|
@@ -2522,7 +2537,7 @@ import UIKit
|
|
|
2522
2537
|
)
|
|
2523
2538
|
|
|
2524
2539
|
statsQueueLock.lock()
|
|
2525
|
-
statsQueue.append(event)
|
|
2540
|
+
statsQueue.append(QueuedStatsEvent(event: event, onSent: onSent))
|
|
2526
2541
|
statsQueueLock.unlock()
|
|
2527
2542
|
|
|
2528
2543
|
ensureStatsTimerStarted()
|
|
@@ -2549,10 +2564,13 @@ import UIKit
|
|
|
2549
2564
|
statsQueueLock.unlock()
|
|
2550
2565
|
return
|
|
2551
2566
|
}
|
|
2552
|
-
let
|
|
2567
|
+
let queuedEvents = statsQueue
|
|
2553
2568
|
statsQueue.removeAll()
|
|
2554
2569
|
statsQueueLock.unlock()
|
|
2555
2570
|
|
|
2571
|
+
let eventsToSend = queuedEvents.map(\.event)
|
|
2572
|
+
let onSentCallbacks = queuedEvents.compactMap(\.onSent)
|
|
2573
|
+
|
|
2556
2574
|
operationQueue.maxConcurrentOperationCount = 1
|
|
2557
2575
|
|
|
2558
2576
|
let operation = BlockOperation {
|
|
@@ -2570,10 +2588,18 @@ import UIKit
|
|
|
2570
2588
|
return
|
|
2571
2589
|
}
|
|
2572
2590
|
|
|
2591
|
+
if let statusCode = response.response?.statusCode, !(200...299).contains(statusCode) {
|
|
2592
|
+
self.logger.error("Error sending stats batch")
|
|
2593
|
+
self.logger.debug("Response code: \(statusCode)")
|
|
2594
|
+
semaphore.signal()
|
|
2595
|
+
return
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2573
2598
|
switch response.result {
|
|
2574
2599
|
case .success:
|
|
2575
2600
|
self.logger.info("Stats batch sent successfully")
|
|
2576
2601
|
self.logger.debug("Sent \(eventsToSend.count) events")
|
|
2602
|
+
onSentCallbacks.forEach { $0() }
|
|
2577
2603
|
case let .failure(error):
|
|
2578
2604
|
self.logger.error("Error sending stats batch")
|
|
2579
2605
|
self.logger.debug("Response: \(response.value?.debugDescription ?? "nil"), Error: \(error.localizedDescription)")
|