@capgo/capacitor-updater 4.5.1 → 4.6.1

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.
@@ -45,7 +45,7 @@ public class CapacitorUpdater {
45
45
  private static final String bundleDirectory = "versions";
46
46
 
47
47
  public static final String TAG = "Capacitor-updater";
48
- public static final String pluginVersion = "4.5.1";
48
+ public static final String pluginVersion = "4.6.1";
49
49
 
50
50
  public SharedPreferences.Editor editor;
51
51
  public SharedPreferences prefs;
@@ -61,6 +61,10 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
61
61
  @Override
62
62
  public void load() {
63
63
  super.load();
64
+ final Boolean allowEmulatorProd = this.getConfig().getBoolean("allowEmulatorProd", true);
65
+ if (allowEmulatorProd && this.isEmulator() && this.isProd()) {
66
+ return;
67
+ }
64
68
  this.prefs = this.getContext().getSharedPreferences(WebView.WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
65
69
  this.editor = this.prefs.edit();
66
70
 
@@ -112,6 +116,30 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
112
116
  this._checkCancelDelay(true);
113
117
  }
114
118
 
119
+ private boolean isProd() {
120
+ return !BuildConfig.DEBUG;
121
+ }
122
+
123
+ private boolean isEmulator() {
124
+ return (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
125
+ || Build.FINGERPRINT.startsWith("generic")
126
+ || Build.FINGERPRINT.startsWith("unknown")
127
+ || Build.HARDWARE.contains("goldfish")
128
+ || Build.HARDWARE.contains("ranchu")
129
+ || Build.MODEL.contains("google_sdk")
130
+ || Build.MODEL.contains("Emulator")
131
+ || Build.MODEL.contains("Android SDK built for x86")
132
+ || Build.MANUFACTURER.contains("Genymotion")
133
+ || Build.PRODUCT.contains("sdk_google")
134
+ || Build.PRODUCT.contains("google_sdk")
135
+ || Build.PRODUCT.contains("sdk")
136
+ || Build.PRODUCT.contains("sdk_x86")
137
+ || Build.PRODUCT.contains("sdk_gphone64_arm64")
138
+ || Build.PRODUCT.contains("vbox86p")
139
+ || Build.PRODUCT.contains("emulator")
140
+ || Build.PRODUCT.contains("simulator");
141
+ }
142
+
115
143
  private void cleanupObsoleteVersions() {
116
144
  try {
117
145
  final Version previous = new Version(this.prefs.getString("LatestVersionNative", ""));
@@ -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.5.1"
151
+ public let pluginVersion = "4.6.1"
152
152
  public var statsUrl = ""
153
153
  public var appId = ""
154
154
  public var deviceID = UIDevice.current.identifierForVendor?.uuidString ?? ""
@@ -25,6 +25,10 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
25
25
  private var taskRunning = false
26
26
 
27
27
  override public func load() {
28
+ let allowEmulatorProd = getConfig().getBoolean("allowEmulatorProd", true)
29
+ if (!allowEmulatorProd && self.isEmulator() && (self.isAppStoreReceiptSandbox() || self.hasEmbeddedMobileProvision())) {
30
+ return
31
+ }
28
32
  print("\(self.implementation.TAG) init for device \(self.implementation.deviceID)")
29
33
  do {
30
34
  currentVersionNative = try Version(Bundle.main.versionName ?? "0.0.0")
@@ -55,6 +59,37 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
55
59
  self.appMovedToForeground()
56
60
  }
57
61
 
62
+ // MARK: Private
63
+ private func hasEmbeddedMobileProvision() -> Bool {
64
+ guard Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") == nil else {
65
+ return true
66
+ }
67
+ return false
68
+ }
69
+
70
+ private func isAppStoreReceiptSandbox() -> Bool {
71
+
72
+ if isEmulator() {
73
+ return false
74
+ } else {
75
+ guard let url = Bundle.main.appStoreReceiptURL else {
76
+ return false
77
+ }
78
+ guard url.lastPathComponent == "sandboxReceipt" else {
79
+ return false
80
+ }
81
+ return true
82
+ }
83
+ }
84
+
85
+ private func isEmulator() -> Bool {
86
+ #if targetEnvironment(simulator)
87
+ return true
88
+ #else
89
+ return false
90
+ #endif
91
+ }
92
+
58
93
  private func cleanupObsoleteVersions() {
59
94
  var LatestVersionNative: Version = "0.0.0"
60
95
  do {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.5.1",
3
+ "version": "4.6.1",
4
4
  "license": "LGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",