@capawesome/capacitor-live-update 7.5.1 → 7.5.2

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.
@@ -7,9 +7,11 @@ import android.content.pm.PackageManager;
7
7
  import android.content.res.AssetManager;
8
8
  import android.os.Build;
9
9
  import android.os.Handler;
10
+ import android.os.Looper;
10
11
  import android.util.Base64;
11
12
  import androidx.annotation.NonNull;
12
13
  import androidx.annotation.Nullable;
14
+ import androidx.core.content.pm.PackageInfoCompat;
13
15
  import com.getcapacitor.Bridge;
14
16
  import com.getcapacitor.Logger;
15
17
  import com.getcapacitor.plugin.WebView;
@@ -103,7 +105,7 @@ public class LiveUpdate {
103
105
 
104
106
  private final String bundlesDirectory = "_capacitor_live_update_bundles"; // DO NOT CHANGE!
105
107
  private final String downloadsDirectory = "capawesome_capacitor_live_update_downloads";
106
- private final Handler rollbackHandler = new Handler();
108
+ private final Handler rollbackHandler = new Handler(Looper.getMainLooper());
107
109
  private final String manifestFileName = "capawesome-live-update-manifest.json"; // DO NOT CHANGE!
108
110
 
109
111
  private boolean initialPageLoaded = false;
@@ -1190,7 +1192,7 @@ public class LiveUpdate {
1190
1192
  }
1191
1193
 
1192
1194
  private int getVersionCodeAsInt() throws PackageManager.NameNotFoundException {
1193
- return getPackageInfo().versionCode;
1195
+ return (int) PackageInfoCompat.getLongVersionCode(getPackageInfo());
1194
1196
  }
1195
1197
 
1196
1198
  private String getVersionCodeAsString() throws PackageManager.NameNotFoundException {
@@ -37,7 +37,7 @@ import io.capawesome.capacitorjs.plugins.liveupdate.interfaces.Result;
37
37
  public class LiveUpdatePlugin extends Plugin {
38
38
 
39
39
  public static final String TAG = "LiveUpdate";
40
- public static final String VERSION = "7.5.1";
40
+ public static final String VERSION = "7.5.2";
41
41
  public static final String SHARED_PREFERENCES_NAME = "CapawesomeLiveUpdate"; // DO NOT CHANGE
42
42
  public static final String ERROR_APP_ID_MISSING = "appId must be configured.";
43
43
  public static final String ERROR_BUNDLE_EXISTS = "bundle already exists.";
@@ -468,7 +468,8 @@ import CommonCrypto
468
468
 
469
469
  private func downloadAndVerifyFile(url: String, file: URL, checksum: String?, signature: String?, callback: ((Progress) -> Void)?) async throws {
470
470
  let destination: DownloadRequest.Destination = { _, _ in
471
- return (file, [.createIntermediateDirectories])
471
+ // `removePreviousFile` ensures that a leftover file from a failed attempt does not fail the download
472
+ return (file, [.createIntermediateDirectories, .removePreviousFile])
472
473
  }
473
474
  let urlComponents = URLComponents(string: url)!
474
475
  let result = try await httpClient.download(url: urlComponents.asURL(), destination: destination, callback: callback)
@@ -27,13 +27,16 @@ public class LiveUpdateHttpClient: NSObject {
27
27
 
28
28
  public func download(url: URL, destination: @escaping DownloadRequest.Destination, callback: ((Progress) -> Void)?) async throws -> AFDownloadResponse<Data> {
29
29
  var request = URLRequest(url: url)
30
+ // Ignore the URL cache so that a cached response is never replayed for a deterministic request URL
31
+ request.cachePolicy = .reloadIgnoringLocalCacheData
30
32
  request.httpMethod = HTTPMethod.get.rawValue
31
33
  request.timeoutInterval = Double(config.httpTimeout) / 1000.0
32
34
  if let deviceId = deviceId, !deviceId.isEmpty {
33
35
  request.setValue(deviceId, forHTTPHeaderField: "X-Device-Id")
34
36
  }
35
37
  return try await withCheckedThrowingContinuation { continuation in
36
- AF.download(request, to: destination).downloadProgress { progress in
38
+ // `validate()` treats non-2xx responses as errors so that an error body is never saved as a bundle file
39
+ AF.download(request, to: destination).validate().downloadProgress { progress in
37
40
  if let callback = callback {
38
41
  callback(progress)
39
42
  }
@@ -45,6 +48,8 @@ public class LiveUpdateHttpClient: NSObject {
45
48
 
46
49
  public func request<T: Decodable>(url: URL, type: T.Type) async throws -> AFDataResponse<T> {
47
50
  var request = URLRequest(url: url)
51
+ // Ignore the URL cache so that a cached response is never replayed for a deterministic request URL
52
+ request.cachePolicy = .reloadIgnoringLocalCacheData
48
53
  request.httpMethod = HTTPMethod.get.rawValue
49
54
  request.timeoutInterval = Double(config.httpTimeout) / 1000.0
50
55
  if let deviceId = deviceId, !deviceId.isEmpty {
@@ -8,7 +8,7 @@ import Capacitor
8
8
  @objc(LiveUpdatePlugin)
9
9
  public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
10
10
  public static let tag = "LiveUpdate"
11
- public static let version = "7.5.1"
11
+ public static let version = "7.5.2"
12
12
  public static let userDefaultsPrefix = "CapawesomeLiveUpdate" // DO NOT CHANGE
13
13
 
14
14
  public let identifier = "LiveUpdatePlugin"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-live-update",
3
- "version": "7.5.1",
3
+ "version": "7.5.2",
4
4
  "description": "Capacitor plugin to update your app remotely in real-time.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",