@capgo/capacitor-updater 4.0.0-alpha.28 → 4.0.0-alpha.31

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.
@@ -46,7 +46,7 @@ public class CapacitorUpdater {
46
46
  private static final String bundleDirectory = "versions";
47
47
 
48
48
  public static final String TAG = "Capacitor-updater";
49
- public static final String pluginVersion = "4.0.0-alpha.28";
49
+ public static final String pluginVersion = "4.0.0-alpha.31";
50
50
 
51
51
  public SharedPreferences.Editor editor;
52
52
  public SharedPreferences prefs;
@@ -180,9 +180,14 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
180
180
  public void download(final PluginCall call) {
181
181
  final String url = call.getString("url");
182
182
  final String version = call.getString("version");
183
- if (url == null || version == null) {
184
- Log.e(CapacitorUpdater.TAG, "missing url or version");
185
- call.reject("missing url or version");
183
+ if (url == null) {
184
+ Log.e(CapacitorUpdater.TAG, "Download called without url");
185
+ call.reject("Download called without url");
186
+ return;
187
+ }
188
+ if (version == null) {
189
+ Log.e(CapacitorUpdater.TAG, "Download called without version");
190
+ call.reject("Download called without version");
186
191
  return;
187
192
  }
188
193
  try {
@@ -236,7 +241,11 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
236
241
  @PluginMethod
237
242
  public void next(final PluginCall call) {
238
243
  final String id = call.getString("id");
239
-
244
+ if (id == null) {
245
+ Log.e(CapacitorUpdater.TAG, "Next called without id");
246
+ call.reject("Next called without id");
247
+ return;
248
+ }
240
249
  try {
241
250
  Log.i(CapacitorUpdater.TAG, "Setting next active id " + id);
242
251
  if (!this.implementation.setNextBundle(id)) {
@@ -254,7 +263,11 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
254
263
  @PluginMethod
255
264
  public void set(final PluginCall call) {
256
265
  final String id = call.getString("id");
257
-
266
+ if (id == null) {
267
+ Log.e(CapacitorUpdater.TAG, "Set called without id");
268
+ call.reject("Set called without id");
269
+ return;
270
+ }
258
271
  try {
259
272
  Log.i(CapacitorUpdater.TAG, "Setting active bundle " + id);
260
273
  if (!this.implementation.set(id)) {
@@ -273,6 +286,11 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
273
286
  @PluginMethod
274
287
  public void delete(final PluginCall call) {
275
288
  final String id = call.getString("id");
289
+ if (id == null) {
290
+ Log.e(CapacitorUpdater.TAG, "missing id");
291
+ call.reject("missing id");
292
+ return;
293
+ }
276
294
  Log.i(CapacitorUpdater.TAG, "Deleting id: " + id);
277
295
  try {
278
296
  final Boolean res = this.implementation.delete(id);
@@ -548,7 +566,7 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
548
566
 
549
567
  final String url = (String) res.get("url");
550
568
  final BundleInfo next = CapacitorUpdaterPlugin.this.implementation.download(url, latestVersionName);
551
-
569
+ this.notifyListeners("updateAvailable", next);
552
570
  CapacitorUpdaterPlugin.this.implementation.setNextBundle(next.getId());
553
571
  } catch (final Exception e) {
554
572
  Log.e(CapacitorUpdater.TAG, "error downloading file", e);
@@ -148,7 +148,7 @@ extension CustomError: LocalizedError {
148
148
 
149
149
  public let TAG = "✨ Capacitor-updater:";
150
150
  public let CAP_SERVER_PATH = "serverBasePath"
151
- public let pluginVersion = "4.0.0-alpha.28"
151
+ public let pluginVersion = "4.0.0-alpha.31"
152
152
  public var statsUrl = ""
153
153
  public var appId = ""
154
154
  public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
@@ -30,12 +30,12 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
30
30
  } catch {
31
31
  print("\(self.implementation.TAG) Cannot get version native \(currentVersionNative)")
32
32
  }
33
- autoDeleteFailed = getConfigValue("autoDeleteFailed") as? Bool ?? false
34
- autoDeletePrevious = getConfigValue("autoDeletePrevious") as? Bool ?? false
35
- updateUrl = getConfigValue("updateUrl") as? String ?? CapacitorUpdaterPlugin.updateUrlDefault
36
- autoUpdate = getConfigValue("autoUpdate") as? Bool ?? false
37
- appReadyTimeout = getConfigValue("appReadyTimeout") as? Int ?? 10000
38
- resetWhenUpdate = getConfigValue("resetWhenUpdate") as? Bool ?? true
33
+ autoDeleteFailed = getConfig().getBoolean("autoDeleteFailed", false)
34
+ autoDeletePrevious = getConfig().getBoolean("autoDeletePrevious", false)
35
+ updateUrl = getConfig().getString("updateUrl") ?? CapacitorUpdaterPlugin.updateUrlDefault
36
+ autoUpdate = getConfig().getBoolean("autoUpdate", false)
37
+ appReadyTimeout = getConfig().getInt("appReadyTimeout", 10000)
38
+ resetWhenUpdate = getConfig().getBoolean("resetWhenUpdate", true)
39
39
 
40
40
  implementation.appId = Bundle.main.bundleIdentifier ?? ""
41
41
  implementation.notifyDownload = notifyDownload
@@ -43,8 +43,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
43
43
  if (config?["appId"] != nil) {
44
44
  implementation.appId = config?["appId"] as! String
45
45
  }
46
- implementation.statsUrl = getConfigValue("statsUrl") as? String ?? CapacitorUpdaterPlugin.statsUrlDefault
47
-
46
+ implementation.statsUrl = getConfig().getString("statsUrl") ?? CapacitorUpdaterPlugin.updateUrlDefault
48
47
  if (resetWhenUpdate) {
49
48
  self.cleanupObsoleteVersions()
50
49
  }
@@ -381,7 +380,7 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
381
380
  do {
382
381
  print("\(self.implementation.TAG) New bundle: \(latestVersionName!) found. Current is: \(current.getVersionName()). Update will occur next time app moves to background.")
383
382
  let next = try self.implementation.download(url: downloadUrl, version: latestVersionName!)
384
-
383
+ self.notifyListeners("updateAvailable", data: ["version": next.toJSON()])
385
384
  let _ = self.implementation.setNextBundle(next: next.getId())
386
385
  } catch {
387
386
  print("\(self.implementation.TAG) Error downloading file", error.localizedDescription)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.0.0-alpha.28",
3
+ "version": "4.0.0-alpha.31",
4
4
  "license": "AGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",