Skip to content

Commit

Permalink
feat: add allowEmulatorProd option to ignore store start app
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Nov 1, 2022
1 parent 541d6e7 commit 94e2799
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public class CapacitorUpdaterPlugin extends Plugin implements Application.Activi
@Override
public void load() {
super.load();
final allowEmulatorProd = this.getConfig().getBoolean("allowEmulatorProd", true);

This comment has been minimized.

Copy link
@arendjantetteroo

arendjantetteroo Nov 1, 2022

@riderx So if you define allowEmulatorProd as true (default), it will not load. Seems you are missing a negation?
Or am i reading this wrong?

if (allowEmulatorProd && this.isEmulator() && this.isProd()) {
return;
}
this.prefs = this.getContext().getSharedPreferences(WebView.WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
this.editor = this.prefs.edit();

Expand Down Expand Up @@ -112,6 +116,30 @@ public void notifyDownload(final String id, final int percent) {
this._checkCancelDelay(true);
}

private boolean isProd() {
return !BuildConfig.DEBUG;
}

private boolean isEmulator() {
return (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
|| Build.FINGERPRINT.startsWith("generic")
|| Build.FINGERPRINT.startsWith("unknown")
|| Build.HARDWARE.contains("goldfish")
|| Build.HARDWARE.contains("ranchu")
|| Build.MODEL.contains("google_sdk")
|| Build.MODEL.contains("Emulator")
|| Build.MODEL.contains("Android SDK built for x86")
|| Build.MANUFACTURER.contains("Genymotion")
|| Build.PRODUCT.contains("sdk_google")
|| Build.PRODUCT.contains("google_sdk")
|| Build.PRODUCT.contains("sdk")
|| Build.PRODUCT.contains("sdk_x86")
|| Build.PRODUCT.contains("sdk_gphone64_arm64")
|| Build.PRODUCT.contains("vbox86p")
|| Build.PRODUCT.contains("emulator")
|| Build.PRODUCT.contains("simulator");
}

private void cleanupObsoleteVersions() {
try {
final Version previous = new Version(this.prefs.getString("LatestVersionNative", ""));
Expand Down
35 changes: 35 additions & 0 deletions ios/Plugin/CapacitorUpdaterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
private var taskRunning = false

override public func load() {
let allowEmulatorProd = getConfig().getBoolean("allowEmulatorProd", true)
if (!allowEmulatorProd && self.isEmulator() && (self.isAppStoreReceiptSandbox() || self.hasEmbeddedMobileProvision())) {
return
}
print("\(self.implementation.TAG) init for device \(self.implementation.deviceID)")
do {
currentVersionNative = try Version(Bundle.main.versionName ?? "0.0.0")
Expand Down Expand Up @@ -55,6 +59,37 @@ public class CapacitorUpdaterPlugin: CAPPlugin {
self.appMovedToForeground()
}

// MARK: Private
private func hasEmbeddedMobileProvision() -> Bool {
guard Bundle.main.path(forResource: "embedded", ofType: "mobileprovision") == nil else {
return true
}
return false
}

private func isAppStoreReceiptSandbox() -> Bool {

if isEmulator() {
return false
} else {
guard let url = Bundle.main.appStoreReceiptURL else {
return false
}
guard url.lastPathComponent == "sandboxReceipt" else {
return false
}
return true
}
}

private func isEmulator() -> Bool {
#if targetEnvironment(simulator)
return true
#else
return false
#endif
}

private func cleanupObsoleteVersions() {
var LatestVersionNative: Version = "0.0.0"
do {
Expand Down

0 comments on commit 94e2799

Please sign in to comment.