@capawesome/capacitor-live-update 8.4.3 → 8.4.4

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.
@@ -57,6 +57,7 @@ import java.io.FileInputStream;
57
57
  import java.io.FileOutputStream;
58
58
  import java.io.IOException;
59
59
  import java.io.InputStream;
60
+ import java.net.SocketTimeoutException;
60
61
  import java.security.KeyFactory;
61
62
  import java.security.MessageDigest;
62
63
  import java.security.PublicKey;
@@ -180,7 +181,7 @@ public class LiveUpdate {
180
181
  .host(config.getServerDomain())
181
182
  .addPathSegment("v1")
182
183
  .addPathSegment("apps")
183
- .addPathSegment(getAppId())
184
+ .addPathSegment(requireAppId())
184
185
  .addPathSegment("channels");
185
186
  if (options.getLimit() != null) {
186
187
  urlBuilder.addQueryParameter("limit", String.valueOf(options.getLimit()));
@@ -739,6 +740,8 @@ public class LiveUpdate {
739
740
  Logger.error(LiveUpdatePlugin.TAG, errorMessage, exception);
740
741
  completionCallback.error(exception);
741
742
  }
743
+ } catch (IOException e) {
744
+ handleDownloadFailure(e, completionCallback);
742
745
  } catch (Exception e) {
743
746
  completionCallback.error(e);
744
747
  }
@@ -746,7 +749,7 @@ public class LiveUpdate {
746
749
 
747
750
  @Override
748
751
  public void error(@NonNull Exception exception) {
749
- completionCallback.error(exception);
752
+ handleDownloadFailure(exception, completionCallback);
750
753
  }
751
754
  }
752
755
  );
@@ -1006,7 +1009,7 @@ public class LiveUpdate {
1006
1009
  .host(config.getServerDomain())
1007
1010
  .addPathSegment("v1")
1008
1011
  .addPathSegment("apps")
1009
- .addPathSegment(getAppId())
1012
+ .addPathSegment(requireAppId())
1010
1013
  .addPathSegment("bundles")
1011
1014
  .addPathSegment("latest")
1012
1015
  .addQueryParameter("appVersionCode", getVersionCodeAsString())
@@ -1207,6 +1210,15 @@ public class LiveUpdate {
1207
1210
  return getPackageInfo().versionName;
1208
1211
  }
1209
1212
 
1213
+ private void handleDownloadFailure(@NonNull Exception exception, @NonNull EmptyCallback callback) {
1214
+ Logger.error(LiveUpdatePlugin.TAG, exception.getMessage(), exception);
1215
+ if (exception instanceof SocketTimeoutException) {
1216
+ callback.error(exception);
1217
+ } else {
1218
+ callback.error(new Exception(LiveUpdatePlugin.ERROR_DOWNLOAD_FAILED));
1219
+ }
1220
+ }
1221
+
1210
1222
  private boolean hasBundleById(@NonNull String bundleId) {
1211
1223
  File bundleDirectory = buildBundleDirectoryFor(bundleId);
1212
1224
  return bundleDirectory.exists();
@@ -1285,6 +1297,15 @@ public class LiveUpdate {
1285
1297
  sync(options, callback);
1286
1298
  }
1287
1299
 
1300
+ @NonNull
1301
+ private String requireAppId() throws Exception {
1302
+ String appId = getAppId();
1303
+ if (appId == null || appId.isEmpty()) {
1304
+ throw new Exception(LiveUpdatePlugin.ERROR_APP_ID_MISSING);
1305
+ }
1306
+ return appId;
1307
+ }
1308
+
1288
1309
  private void rollback() {
1289
1310
  // Set the rollback flag
1290
1311
  rollbackPerformed = true;
@@ -88,7 +88,7 @@ public class LiveUpdateHttpClient {
88
88
 
89
89
  @Override
90
90
  public void onFailure(@NonNull Call call, @NonNull IOException e) {
91
- callback.error(new Exception(e));
91
+ callback.error(e);
92
92
  }
93
93
  }
94
94
  );
@@ -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 = "8.4.3";
40
+ public static final String VERSION = "8.4.4";
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.";
@@ -60,9 +60,6 @@ public class LiveUpdatePlugin extends Plugin {
60
60
  public static final String EVENT_NEXT_BUNDLE_SET = "nextBundleSet";
61
61
  public static final String EVENT_RELOADED = "reloaded";
62
62
 
63
- @Nullable
64
- private LiveUpdateConfig config;
65
-
66
63
  @Nullable
67
64
  private LiveUpdate implementation;
68
65
 
@@ -70,8 +67,7 @@ public class LiveUpdatePlugin extends Plugin {
70
67
 
71
68
  public void load() {
72
69
  try {
73
- config = getLiveUpdateConfig();
74
- implementation = new LiveUpdate(config, this);
70
+ implementation = new LiveUpdate(getLiveUpdateConfig(), this);
75
71
  } catch (Exception exception) {
76
72
  Logger.error(TAG, exception.getMessage(), exception);
77
73
  }
@@ -183,12 +179,6 @@ public class LiveUpdatePlugin extends Plugin {
183
179
  @PluginMethod
184
180
  public void fetchChannels(PluginCall call) {
185
181
  try {
186
- String appId = config.getAppId();
187
- if (appId == null || appId.isEmpty()) {
188
- call.reject(ERROR_APP_ID_MISSING);
189
- return;
190
- }
191
-
192
182
  FetchChannelsOptions options = new FetchChannelsOptions(call);
193
183
  NonEmptyCallback<FetchChannelsResult> callback = new NonEmptyCallback<>() {
194
184
  @Override
@@ -211,12 +201,6 @@ public class LiveUpdatePlugin extends Plugin {
211
201
  @PluginMethod
212
202
  public void fetchLatestBundle(PluginCall call) {
213
203
  try {
214
- String appId = config.getAppId();
215
- if (appId == null || appId.isEmpty()) {
216
- call.reject(ERROR_APP_ID_MISSING);
217
- return;
218
- }
219
-
220
204
  FetchLatestBundleOptions options = new FetchLatestBundleOptions(call);
221
205
  NonEmptyCallback<FetchLatestBundleResult> callback = new NonEmptyCallback<>() {
222
206
  @Override
@@ -633,12 +617,6 @@ public class LiveUpdatePlugin extends Plugin {
633
617
  @PluginMethod
634
618
  public void sync(PluginCall call) {
635
619
  try {
636
- String appId = config.getAppId();
637
- if (appId == null || appId.isEmpty()) {
638
- call.reject(ERROR_APP_ID_MISSING);
639
- return;
640
- }
641
-
642
620
  SyncOptions options = new SyncOptions(call);
643
621
  NonEmptyCallback<Result> callback = new NonEmptyCallback<>() {
644
622
  @Override
@@ -98,7 +98,8 @@ import CommonCrypto
98
98
  if let query = options.getQuery() {
99
99
  parameters["query"] = query
100
100
  }
101
- var urlComponents = URLComponents(string: "https://\(config.serverDomain)/v1/apps/\(getAppId() ?? "")/channels")!
101
+ let appId = try requireAppId()
102
+ var urlComponents = URLComponents(string: "https://\(config.serverDomain)/v1/apps/\(appId)/channels")!
102
103
  if !parameters.isEmpty {
103
104
  urlComponents.queryItems = parameters.map { URLQueryItem(name: $0.key, value: $0.value) }
104
105
  }
@@ -603,7 +604,8 @@ import CommonCrypto
603
604
  parameters["osVersion"] = await UIDevice.current.systemVersion
604
605
  parameters["platform"] = "1"
605
606
  parameters["pluginVersion"] = LiveUpdatePlugin.version
606
- var urlComponents = URLComponents(string: "https://\(config.serverDomain)/v1/apps/\(getAppId() ?? "")/bundles/latest")!
607
+ let appId = try requireAppId()
608
+ var urlComponents = URLComponents(string: "https://\(config.serverDomain)/v1/apps/\(appId)/bundles/latest")!
607
609
  urlComponents.queryItems = parameters.map { URLQueryItem(name: $0.key, value: $0.value) }
608
610
  let url = try urlComponents.asURL()
609
611
  CAPLog.print("[", LiveUpdatePlugin.tag, "] Fetching latest bundle: ", url)
@@ -802,6 +804,13 @@ import CommonCrypto
802
804
  }
803
805
  }
804
806
 
807
+ private func requireAppId() throws -> String {
808
+ guard let appId = getAppId(), !appId.isEmpty else {
809
+ throw CustomError.appIdMissing
810
+ }
811
+ return appId
812
+ }
813
+
805
814
  private func rollback() {
806
815
  // Set the rollback flag
807
816
  rollbackPerformed = true
@@ -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 = "8.4.3"
11
+ public static let version = "8.4.4"
12
12
  public static let userDefaultsPrefix = "CapawesomeLiveUpdate" // DO NOT CHANGE
13
13
 
14
14
  public let identifier = "LiveUpdatePlugin"
@@ -46,12 +46,10 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
46
46
  private let eventNextBundleSet = "nextBundleSet"
47
47
  private let eventReloaded = "reloaded"
48
48
 
49
- private var config: LiveUpdateConfig?
50
49
  private var implementation: LiveUpdate?
51
50
 
52
51
  override public func load() {
53
- self.config = liveUpdateConfig()
54
- self.implementation = LiveUpdate(config: config!, plugin: self)
52
+ self.implementation = LiveUpdate(config: liveUpdateConfig(), plugin: self)
55
53
 
56
54
  // Notify implementation about load
57
55
  implementation?.handleLoad()
@@ -115,11 +113,6 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
115
113
  @objc func fetchChannels(_ call: CAPPluginCall) {
116
114
  Task {
117
115
  do {
118
- guard let appId = config?.appId, !appId.isEmpty else {
119
- call.reject(CustomError.appIdMissing.localizedDescription)
120
- return
121
- }
122
-
123
116
  let options = FetchChannelsOptions(call)
124
117
  let result = try await implementation?.fetchChannels(options)
125
118
  if let result = result?.toJSObject() as? JSObject {
@@ -134,11 +127,6 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
134
127
  @objc func fetchLatestBundle(_ call: CAPPluginCall) {
135
128
  Task {
136
129
  do {
137
- guard let appId = config?.appId, !appId.isEmpty else {
138
- call.reject(CustomError.appIdMissing.localizedDescription)
139
- return
140
- }
141
-
142
130
  let options = FetchLatestBundleOptions(call)
143
131
  let result = try await implementation?.fetchLatestBundle(options)
144
132
  if let result = result?.toJSObject() as? JSObject {
@@ -373,11 +361,6 @@ public class LiveUpdatePlugin: CAPPlugin, CAPBridgedPlugin {
373
361
  @objc func sync(_ call: CAPPluginCall) {
374
362
  Task {
375
363
  do {
376
- guard let appId = config?.appId, !appId.isEmpty else {
377
- call.reject(CustomError.appIdMissing.localizedDescription)
378
- return
379
- }
380
-
381
364
  let options = SyncOptions(call)
382
365
  let result = try await implementation?.sync(options)
383
366
  if let result = result?.toJSObject() as? JSObject {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-live-update",
3
- "version": "8.4.3",
3
+ "version": "8.4.4",
4
4
  "description": "Capacitor plugin to update your app remotely in real-time on Android and iOS.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",