Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-apples-find.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@capawesome/capacitor-live-update': minor
---

feat: track device ID on bundle download
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public LiveUpdate(@NonNull LiveUpdateConfig config, @NonNull LiveUpdatePlugin pl
// Check version and reset config if version changed
checkAndResetConfigIfVersionChanged();

// Set the device ID on the HTTP client (after any potential config reset)
this.httpClient.setDeviceId(getDeviceId());

// Start the rollback timer to rollback to the default bundle
// if the app is not ready after a certain time
startRollbackTimer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class LiveUpdateHttpClient {
@NonNull
private final LiveUpdateConfig config;

@Nullable
private String deviceId;

@NonNull
private final OkHttpClient okHttpClient;

Expand Down Expand Up @@ -62,8 +65,16 @@ public LiveUpdateHttpClient(@NonNull LiveUpdateConfig config) {
.build();
}

public void setDeviceId(@NonNull String deviceId) {
this.deviceId = deviceId;
}

public Call enqueue(String url, NonEmptyCallback<Response> callback) {
Request request = new Request.Builder().url(url).build();
Request.Builder builder = new Request.Builder().url(url);
if (deviceId != null) {
builder.addHeader("X-Device-Id", deviceId);
}
Request request = builder.build();

Call call = okHttpClient.newCall(request);
call.enqueue(
Expand Down
3 changes: 3 additions & 0 deletions packages/live-update/ios/Plugin/LiveUpdate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import CommonCrypto
// Check version and reset config if version changed
checkAndResetConfigIfVersionChanged()

// Set the device ID on the HTTP client (after any potential config reset)
self.httpClient.setDeviceId(getDeviceId())

// Start the rollback timer to rollback to the default bundle
// if the app is not ready after a certain time
startRollbackTimer()
Expand Down
11 changes: 11 additions & 0 deletions packages/live-update/ios/Plugin/LiveUpdateHttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Alamofire
public class LiveUpdateHttpClient: NSObject {

private let config: LiveUpdateConfig
private var deviceId: String?

public static func getChecksumFromResponse(response: HTTPURLResponse) -> String? {
guard let headers = response.allHeaderFields as? [String: String] else { return nil }
Expand All @@ -20,10 +21,17 @@ public class LiveUpdateHttpClient: NSObject {
self.config = config
}

public func setDeviceId(_ deviceId: String) {
self.deviceId = deviceId
}

public func download(url: URL, destination: @escaping DownloadRequest.Destination, callback: ((Progress) -> Void)?) async throws -> AFDownloadResponse<Data> {
var request = URLRequest(url: url)
request.httpMethod = HTTPMethod.get.rawValue
request.timeoutInterval = Double(config.httpTimeout) / 1000.0
if let deviceId = deviceId, !deviceId.isEmpty {
request.setValue(deviceId, forHTTPHeaderField: "X-Device-Id")
}
return try await withCheckedThrowingContinuation { continuation in
AF.download(request, to: destination).downloadProgress { progress in
if let callback = callback {
Expand All @@ -39,6 +47,9 @@ public class LiveUpdateHttpClient: NSObject {
var request = URLRequest(url: url)
request.httpMethod = HTTPMethod.get.rawValue
request.timeoutInterval = Double(config.httpTimeout) / 1000.0
if let deviceId = deviceId, !deviceId.isEmpty {
request.setValue(deviceId, forHTTPHeaderField: "X-Device-Id")
}
return try await withCheckedThrowingContinuation { continuation in
AF.request(request).validate().responseDecodable(of: type) { response in
continuation.resume(returning: response)
Expand Down
Loading