@capgo/capacitor-updater 4.9.1 → 4.10.0

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.
@@ -1,6 +1,7 @@
1
1
  package ee.forgr.capacitor_updater;
2
2
 
3
3
  import android.content.SharedPreferences;
4
+ import android.os.Build;
4
5
  import android.util.Log;
5
6
  import com.android.volley.Request;
6
7
  import com.android.volley.RequestQueue;
@@ -51,7 +52,7 @@ public class CapacitorUpdater {
51
52
  private static final String bundleDirectory = "versions";
52
53
 
53
54
  public static final String TAG = "Capacitor-updater";
54
- public static final String pluginVersion = "4.9.1";
55
+ public static final String pluginVersion = "4.10.0";
55
56
 
56
57
  public SharedPreferences.Editor editor;
57
58
  public SharedPreferences prefs;
@@ -77,6 +78,30 @@ public class CapacitorUpdater {
77
78
  }
78
79
  };
79
80
 
81
+ private boolean isProd() {
82
+ return !BuildConfig.DEBUG;
83
+ }
84
+
85
+ private boolean isEmulator() {
86
+ return (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
87
+ || Build.FINGERPRINT.startsWith("generic")
88
+ || Build.FINGERPRINT.startsWith("unknown")
89
+ || Build.HARDWARE.contains("goldfish")
90
+ || Build.HARDWARE.contains("ranchu")
91
+ || Build.MODEL.contains("google_sdk")
92
+ || Build.MODEL.contains("Emulator")
93
+ || Build.MODEL.contains("Android SDK built for x86")
94
+ || Build.MANUFACTURER.contains("Genymotion")
95
+ || Build.PRODUCT.contains("sdk_google")
96
+ || Build.PRODUCT.contains("google_sdk")
97
+ || Build.PRODUCT.contains("sdk")
98
+ || Build.PRODUCT.contains("sdk_x86")
99
+ || Build.PRODUCT.contains("sdk_gphone64_arm64")
100
+ || Build.PRODUCT.contains("vbox86p")
101
+ || Build.PRODUCT.contains("emulator")
102
+ || Build.PRODUCT.contains("simulator");
103
+ }
104
+
80
105
  private int calcTotalPercent(final int percent, final int min, final int max) {
81
106
  return (percent * (max - min)) / 100 + min;
82
107
  }
@@ -358,18 +383,25 @@ public class CapacitorUpdater {
358
383
  }
359
384
  }
360
385
 
386
+ private JSONObject createInfoObject() throws JSONException {
387
+ JSONObject json = new JSONObject();
388
+ json.put("platform", "android");
389
+ json.put("device_id", this.deviceID);
390
+ json.put("app_id", this.appId);
391
+ json.put("custom_id", this.customId);
392
+ json.put("version_build", this.versionBuild);
393
+ json.put("version_code", this.versionCode);
394
+ json.put("version_os", this.versionOs);
395
+ json.put("version_name", this.getCurrentBundle().getVersionName());
396
+ json.put("plugin_version", this.pluginVersion);
397
+ json.put("is_emulator", this.isEmulator());
398
+ json.put("is_prod", this.isProd());
399
+ return json;
400
+ }
401
+
361
402
  public void getLatest(final String updateUrl, final Callback callback) {
362
403
  try {
363
- JSONObject json = new JSONObject();
364
- json.put("platform", "android");
365
- json.put("device_id", this.deviceID);
366
- json.put("custom_id", this.customId);
367
- json.put("app_id", this.appId);
368
- json.put("version_build", this.versionBuild);
369
- json.put("version_code", this.versionCode);
370
- json.put("version_os", this.versionOs);
371
- json.put("version_name", this.getCurrentBundle().getVersionName());
372
- json.put("plugin_version", CapacitorUpdater.pluginVersion);
404
+ JSONObject json = this.createInfoObject();
373
405
 
374
406
  Log.i(CapacitorUpdater.TAG, "Auto-update parameters: " + json);
375
407
  // Building a request
@@ -403,16 +435,7 @@ public class CapacitorUpdater {
403
435
  return;
404
436
  }
405
437
  try {
406
- JSONObject json = new JSONObject();
407
- json.put("platform", "android");
408
- json.put("device_id", this.deviceID);
409
- json.put("custom_id", this.customId);
410
- json.put("app_id", this.appId);
411
- json.put("version_build", this.versionBuild);
412
- json.put("version_code", this.versionCode);
413
- json.put("version_os", this.versionOs);
414
- json.put("version_name", this.getCurrentBundle().getVersionName());
415
- json.put("plugin_version", pluginVersion);
438
+ JSONObject json = this.createInfoObject();
416
439
  json.put("channel", channel);
417
440
 
418
441
  // Building a request
@@ -459,16 +482,7 @@ public class CapacitorUpdater {
459
482
  return;
460
483
  }
461
484
  try {
462
- JSONObject json = new JSONObject();
463
- json.put("platform", "android");
464
- json.put("device_id", this.deviceID);
465
- json.put("custom_id", this.customId);
466
- json.put("app_id", this.appId);
467
- json.put("version_build", this.versionBuild);
468
- json.put("version_code", this.versionCode);
469
- json.put("version_os", this.versionOs);
470
- json.put("version_name", this.getCurrentBundle().getVersionName());
471
- json.put("plugin_version", pluginVersion);
485
+ JSONObject json = this.createInfoObject();
472
486
 
473
487
  // Building a request
474
488
  JsonObjectRequest request = new JsonObjectRequest(
@@ -514,16 +528,7 @@ public class CapacitorUpdater {
514
528
  return;
515
529
  }
516
530
  try {
517
- JSONObject json = new JSONObject();
518
- json.put("platform", "android");
519
- json.put("device_id", this.deviceID);
520
- json.put("custom_id", this.customId);
521
- json.put("app_id", this.appId);
522
- json.put("version_build", this.versionBuild);
523
- json.put("version_code", this.versionCode);
524
- json.put("version_os", this.versionOs);
525
- json.put("version_name", versionName);
526
- json.put("plugin_version", pluginVersion);
531
+ JSONObject json = this.createInfoObject();
527
532
  json.put("action", action);
528
533
 
529
534
  // Building a request
@@ -62,10 +62,6 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
62
62
  @Override
63
63
  public void load() {
64
64
  super.load();
65
- final Boolean allowEmulatorProd = this.getConfig().getBoolean("allowEmulatorProd", true);
66
- if (!allowEmulatorProd && this.isEmulator() && this.isProd()) {
67
- return;
68
- }
69
65
  this.prefs = this.getContext().getSharedPreferences(WebView.WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
70
66
  this.editor = this.prefs.edit();
71
67
 
@@ -118,30 +114,6 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
118
114
  this._checkCancelDelay(true);
119
115
  }
120
116
 
121
- private boolean isProd() {
122
- return !BuildConfig.DEBUG;
123
- }
124
-
125
- private boolean isEmulator() {
126
- return (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
127
- || Build.FINGERPRINT.startsWith("generic")
128
- || Build.FINGERPRINT.startsWith("unknown")
129
- || Build.HARDWARE.contains("goldfish")
130
- || Build.HARDWARE.contains("ranchu")
131
- || Build.MODEL.contains("google_sdk")
132
- || Build.MODEL.contains("Emulator")
133
- || Build.MODEL.contains("Android SDK built for x86")
134
- || Build.MANUFACTURER.contains("Genymotion")
135
- || Build.PRODUCT.contains("sdk_google")
136
- || Build.PRODUCT.contains("google_sdk")
137
- || Build.PRODUCT.contains("sdk")
138
- || Build.PRODUCT.contains("sdk_x86")
139
- || Build.PRODUCT.contains("sdk_gphone64_arm64")
140
- || Build.PRODUCT.contains("vbox86p")
141
- || Build.PRODUCT.contains("emulator")
142
- || Build.PRODUCT.contains("simulator");
143
- }
144
-
145
117
  private void cleanupObsoleteVersions() {
146
118
  try {
147
119
  final Version previous = new Version(this.prefs.getString("LatestVersionNative", ""));
@@ -234,9 +206,9 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
234
206
  @Override
235
207
  public void run() {
236
208
  CapacitorUpdaterPlugin.this.implementation.setChannel(channel,
237
- res -> {
238
- call.resolve(res);
239
- });
209
+ res -> {
210
+ call.resolve(res);
211
+ });
240
212
  }
241
213
  }
242
214
  )
@@ -256,9 +228,9 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
256
228
  @Override
257
229
  public void run() {
258
230
  CapacitorUpdaterPlugin.this.implementation.getChannel(
259
- res -> {
260
- call.resolve(res);
261
- });
231
+ res -> {
232
+ call.resolve(res);
233
+ });
262
234
  }
263
235
  }
264
236
  )
package/dist/docs.json CHANGED
@@ -1907,22 +1907,6 @@
1907
1907
  "docs": "Configure the URL / endpoint to which update statistics are sent.\n\nOnly available for Android and iOS. Set to \"\" to disable stats reporting.",
1908
1908
  "complexTypes": [],
1909
1909
  "type": "string | undefined"
1910
- },
1911
- {
1912
- "name": "allowEmulatorProd",
1913
- "tags": [
1914
- {
1915
- "text": "true",
1916
- "name": "default"
1917
- },
1918
- {
1919
- "text": "false",
1920
- "name": "example"
1921
- }
1922
- ],
1923
- "docs": "Allow the plugin to automatically check for updates on app launch on emulator devices in production app.\n\nThis is useful for CI/CD who send builds to google at each commit.",
1924
- "complexTypes": [],
1925
- "type": "boolean | undefined"
1926
1910
  }
1927
1911
  ],
1928
1912
  "docs": "These configuration values are available:"
@@ -68,15 +68,6 @@ declare module '@capacitor/cli' {
68
68
  * @example https://example.com/api/stats
69
69
  */
70
70
  statsUrl?: string;
71
- /**
72
- * Allow the plugin to automatically check for updates on app launch on emulator devices in production app.
73
- *
74
- * This is useful for CI/CD who send builds to google at each commit.
75
- *
76
- * @default true
77
- * @example false
78
- */
79
- allowEmulatorProd?: boolean;
80
71
  };
81
72
  }
82
73
  }
@@ -60,6 +60,21 @@ extension GetChannel {
60
60
  return dict
61
61
  }
62
62
  }
63
+ struct InfoObject : Codable {
64
+ let platform : String?
65
+ let device_id : String?
66
+ let app_id : String?
67
+ let custom_id : String?
68
+ let version_build : String?
69
+ let version_code : String?
70
+ let version_os : String?
71
+ let version_name : String?
72
+ let plugin_version : String?
73
+ let is_emulator : Bool?
74
+ let is_prod : Bool?
75
+ var action : String?
76
+ var channel : String?
77
+ }
63
78
  struct AppVersionDec: Decodable {
64
79
  let version: String?
65
80
  let checksum: String?
@@ -193,7 +208,7 @@ extension CustomError: LocalizedError {
193
208
  public let TAG = "✨ Capacitor-updater:"
194
209
  public let CAP_SERVER_PATH = "serverBasePath"
195
210
  public var customId = ""
196
- public let pluginVersion = "4.9.1"
211
+ public let pluginVersion = "4.10.0"
197
212
  public var statsUrl = ""
198
213
  public var channelUrl = ""
199
214
  public var appId = ""
@@ -210,6 +225,40 @@ extension CustomError: LocalizedError {
210
225
  return String((0..<length).map { _ in letters.randomElement()! })
211
226
  }
212
227
 
228
+ private func isProd() -> Bool {
229
+ return !self.isAppStoreReceiptSandbox() && !self.hasEmbeddedMobileProvision()
230
+ }
231
+
232
+ // MARK: Private
233
+ private func hasEmbeddedMobileProvision() -> Bool {
234
+ guard Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") == nil else {
235
+ return true
236
+ }
237
+ return false
238
+ }
239
+
240
+ private func isAppStoreReceiptSandbox() -> Bool {
241
+
242
+ if isEmulator() {
243
+ return false
244
+ } else {
245
+ guard let url = Bundle.main.appStoreReceiptURL else {
246
+ return false
247
+ }
248
+ guard url.lastPathComponent == "sandboxReceipt" else {
249
+ return false
250
+ }
251
+ return true
252
+ }
253
+ }
254
+
255
+ private func isEmulator() -> Bool {
256
+ #if targetEnvironment(simulator)
257
+ return true
258
+ #else
259
+ return false
260
+ #endif
261
+ }
213
262
  // Persistent path /var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Library/NoCloud/ionic_built_snapshots/FOLDER
214
263
  // Hot Reload path /var/mobile/Containers/Data/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/Documents/FOLDER
215
264
  // Normal /private/var/containers/Bundle/Application/8C0C07BE-0FD3-4FD4-B7DF-90A88E12B8C3/App.app/public
@@ -274,20 +323,28 @@ extension CustomError: LocalizedError {
274
323
  }
275
324
  }
276
325
 
326
+ private func createInfoObject() -> InfoObject {
327
+ return InfoObject(
328
+ platform: "ios",
329
+ device_id: self.deviceID,
330
+ app_id: self.appId,
331
+ custom_id: self.customId,
332
+ version_build: self.versionName,
333
+ version_code: self.versionCode,
334
+ version_os: self.versionOs,
335
+ version_name: self.getCurrentBundle().getVersionName(),
336
+ plugin_version: self.pluginVersion,
337
+ is_emulator: self.isEmulator(),
338
+ is_prod: self.isProd(),
339
+ action: nil,
340
+ channel: nil
341
+ )
342
+ }
343
+
277
344
  public func getLatest(url: URL) -> AppVersion {
278
345
  let semaphore = DispatchSemaphore(value: 0)
279
346
  let latest = AppVersion()
280
- let parameters: [String: String] = [
281
- "platform": "ios",
282
- "device_id": self.deviceID,
283
- "app_id": self.appId,
284
- "custom_id": self.customId,
285
- "version_build": self.versionName,
286
- "version_code": self.versionCode,
287
- "version_os": self.versionOs,
288
- "plugin_version": self.pluginVersion,
289
- "version_name": self.getCurrentBundle().getVersionName()
290
- ]
347
+ let parameters: InfoObject = self.createInfoObject()
291
348
  print("\(self.TAG) Auto-update parameters: \(parameters)")
292
349
  let request = AF.request(url, method: .post, parameters: parameters, encoder: JSONParameterEncoder.default)
293
350
 
@@ -510,18 +567,9 @@ extension CustomError: LocalizedError {
510
567
  }
511
568
  let semaphore = DispatchSemaphore(value: 0)
512
569
  let setChannel = SetChannel()
513
- let parameters: [String: String] = [
514
- "platform": "ios",
515
- "device_id": self.deviceID,
516
- "custom_id": self.customId,
517
- "version_name": self.getCurrentBundle().getVersionName(),
518
- "version_build": self.versionName,
519
- "version_code": self.versionCode,
520
- "version_os": self.versionOs,
521
- "plugin_version": self.pluginVersion,
522
- "channel": channel,
523
- "app_id": self.appId
524
- ]
570
+ var parameters: InfoObject = self.createInfoObject()
571
+ parameters.channel = channel
572
+
525
573
  let request = AF.request(self.channelUrl, method: .post, parameters: parameters, encoder: JSONParameterEncoder.default)
526
574
 
527
575
  request.validate().responseDecodable(of: SetChannelDec.self) { response in
@@ -548,17 +596,7 @@ extension CustomError: LocalizedError {
548
596
  }
549
597
  let semaphore = DispatchSemaphore(value: 0)
550
598
  let getChannel = GetChannel()
551
- let parameters: [String: String] = [
552
- "platform": "ios",
553
- "device_id": self.deviceID,
554
- "custom_id": self.customId,
555
- "version_name": self.getCurrentBundle().getVersionName(),
556
- "version_build": self.versionName,
557
- "version_code": self.versionCode,
558
- "version_os": self.versionOs,
559
- "plugin_version": self.pluginVersion,
560
- "app_id": self.appId
561
- ]
599
+ let parameters: InfoObject = self.createInfoObject()
562
600
  let request = AF.request(self.channelUrl, method: .put, parameters: parameters, encoder: JSONParameterEncoder.default)
563
601
 
564
602
  request.validate().responseDecodable(of: GetChannelDec.self) { response in
@@ -589,18 +627,8 @@ extension CustomError: LocalizedError {
589
627
  if self.statsUrl == "" {
590
628
  return
591
629
  }
592
- let parameters: [String: String] = [
593
- "platform": "ios",
594
- "action": action,
595
- "device_id": self.deviceID,
596
- "custom_id": self.customId,
597
- "version_name": versionName,
598
- "version_build": self.versionName,
599
- "version_code": self.versionCode,
600
- "version_os": self.versionOs,
601
- "plugin_version": self.pluginVersion,
602
- "app_id": self.appId
603
- ]
630
+ var parameters: InfoObject = self.createInfoObject()
631
+ parameters.action = action
604
632
  DispatchQueue.global(qos: .background).async {
605
633
  let request = AF.request(self.statsUrl, method: .post, parameters: parameters, encoder: JSONParameterEncoder.default)
606
634
  request.responseData { response in
@@ -26,10 +26,6 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
26
26
  private var taskRunning = false
27
27
 
28
28
  override public func load() {
29
- let allowEmulatorProd = getConfig().getBoolean("allowEmulatorProd", true)
30
- if (!allowEmulatorProd && self.isEmulator() && (self.isAppStoreReceiptSandbox() || self.hasEmbeddedMobileProvision())) {
31
- return
32
- }
33
29
  print("\(self.implementation.TAG) init for device \(self.implementation.deviceID)")
34
30
  do {
35
31
  currentVersionNative = try Version(Bundle.main.versionName ?? "0.0.0")
@@ -61,37 +57,6 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
61
57
  self.appMovedToForeground()
62
58
  }
63
59
 
64
- // MARK: Private
65
- private func hasEmbeddedMobileProvision() -> Bool {
66
- guard Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") == nil else {
67
- return true
68
- }
69
- return false
70
- }
71
-
72
- private func isAppStoreReceiptSandbox() -> Bool {
73
-
74
- if isEmulator() {
75
- return false
76
- } else {
77
- guard let url = Bundle.main.appStoreReceiptURL else {
78
- return false
79
- }
80
- guard url.lastPathComponent == "sandboxReceipt" else {
81
- return false
82
- }
83
- return true
84
- }
85
- }
86
-
87
- private func isEmulator() -> Bool {
88
- #if targetEnvironment(simulator)
89
- return true
90
- #else
91
- return false
92
- #endif
93
- }
94
-
95
60
  private func cleanupObsoleteVersions() {
96
61
  var LatestVersionNative: Version = "0.0.0"
97
62
  do {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.9.1",
3
+ "version": "4.10.0",
4
4
  "license": "LGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",