@capgo/inappbrowser 8.1.3 → 8.1.5

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.
@@ -50,7 +50,7 @@ import org.json.JSONObject;
50
50
  )
51
51
  public class InAppBrowserPlugin extends Plugin implements WebViewDialog.PermissionHandler {
52
52
 
53
- private final String pluginVersion = "8.1.3";
53
+ private final String pluginVersion = "8.1.5";
54
54
 
55
55
  public static final String CUSTOM_TAB_PACKAGE_NAME = "com.android.chrome"; // Change when in stable
56
56
  private CustomTabsClient customTabsClient;
@@ -404,6 +404,8 @@ public class WebViewDialog extends Dialog {
404
404
  applyInsets();
405
405
 
406
406
  _webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidInterface");
407
+ // Provide window.mobileApp at document start via native interface
408
+ _webView.addJavascriptInterface(new JavaScriptInterface(), "mobileApp");
407
409
  _webView.addJavascriptInterface(new PreShowScriptInterface(), "PreShowScriptInterface");
408
410
  _webView.addJavascriptInterface(new PrintInterface(this._context, _webView), "PrintInterface");
409
411
  _webView.getSettings().setJavaScriptEnabled(true);
@@ -1138,13 +1140,20 @@ public class WebViewDialog extends Dialog {
1138
1140
  // Apply system insets to WebView content view (compatible with all Android versions)
1139
1141
  ViewCompat.setOnApplyWindowInsetsListener(_webView, (v, windowInsets) -> {
1140
1142
  Insets bars = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
1143
+ Insets navigationBars = windowInsets.getInsets(WindowInsetsCompat.Type.navigationBars());
1144
+ Insets systemGestures = windowInsets.getInsets(WindowInsetsCompat.Type.systemGestures());
1145
+ Insets mandatoryGestures = windowInsets.getInsets(WindowInsetsCompat.Type.mandatorySystemGestures());
1141
1146
  Insets ime = windowInsets.getInsets(WindowInsetsCompat.Type.ime());
1142
1147
  Boolean keyboardVisible = windowInsets.isVisible(WindowInsetsCompat.Type.ime());
1143
1148
 
1144
1149
  ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
1145
1150
 
1146
1151
  // Apply safe margin inset to bottom margin if enabled in options or fallback to 0px
1147
- int navBottom = _options.getEnabledSafeMargin() ? bars.bottom : 0;
1152
+ int safeBottomInset = Math.max(
1153
+ bars.bottom,
1154
+ Math.max(navigationBars.bottom, Math.max(systemGestures.bottom, mandatoryGestures.bottom))
1155
+ );
1156
+ int navBottom = _options.getEnabledSafeMargin() ? safeBottomInset : 0;
1148
1157
 
1149
1158
  // Apply top inset only if useTopInset option is enabled or fallback to 0px
1150
1159
  int navTop = _options.getUseTopInset() ? bars.top : 0;
@@ -1161,6 +1170,7 @@ public class WebViewDialog extends Dialog {
1161
1170
 
1162
1171
  return WindowInsetsCompat.CONSUMED;
1163
1172
  });
1173
+ ViewCompat.requestApplyInsets(_webView);
1164
1174
 
1165
1175
  // Handle window decoration - version-specific handling
1166
1176
  if (getWindow() != null) {
@@ -1278,27 +1288,27 @@ public class WebViewDialog extends Dialog {
1278
1288
  String script = String.format(
1279
1289
  """
1280
1290
  (function() {
1281
- if (window.AndroidInterface) {
1282
- // Create mobileApp object for backward compatibility
1283
- if (!window.mobileApp) {
1284
- window.mobileApp = {
1285
- postMessage: function(message) {
1286
- try {
1287
- var msg = typeof message === 'string' ? message : JSON.stringify(message);
1288
- window.AndroidInterface.postMessage(msg);
1289
- } catch(e) {
1290
- console.error('Error in mobileApp.postMessage:', e);
1291
- }
1292
- },
1293
- close: function() {
1294
- try {
1295
- window.AndroidInterface.close();
1296
- } catch(e) {
1297
- console.error('Error in mobileApp.close:', e);
1298
- }
1299
- }%s
1300
- };
1301
- }
1291
+ // Prefer AndroidInterface when available, otherwise fall back to native window.mobileApp
1292
+ var nativeBridge = window.AndroidInterface || window.mobileApp;
1293
+ if (nativeBridge) {
1294
+ // Wrap native bridge to normalize behavior (stringify objects, expose close/hide/show)
1295
+ window.mobileApp = {
1296
+ postMessage: function(message) {
1297
+ try {
1298
+ var msg = typeof message === 'string' ? message : JSON.stringify(message);
1299
+ nativeBridge.postMessage(msg);
1300
+ } catch(e) {
1301
+ console.error('Error in mobileApp.postMessage:', e);
1302
+ }
1303
+ },
1304
+ close: function() {
1305
+ try {
1306
+ nativeBridge.close();
1307
+ } catch(e) {
1308
+ console.error('Error in mobileApp.close:', e);
1309
+ }
1310
+ }%s
1311
+ };
1302
1312
  }
1303
1313
  // Override window.print function to use our PrintInterface
1304
1314
  if (window.PrintInterface) {
@@ -2977,20 +2987,8 @@ public class WebViewDialog extends Dialog {
2977
2987
  }
2978
2988
  }
2979
2989
 
2980
- // Shutdown executor service safely
2981
- if (executorService != null && !executorService.isShutdown()) {
2982
- try {
2983
- executorService.shutdown();
2984
- if (!executorService.awaitTermination(500, TimeUnit.MILLISECONDS)) {
2985
- executorService.shutdownNow();
2986
- }
2987
- } catch (InterruptedException e) {
2988
- Thread.currentThread().interrupt();
2989
- executorService.shutdownNow();
2990
- } catch (Exception e) {
2991
- Log.e("InAppBrowser", "Error shutting down executor: " + e.getMessage());
2992
- }
2993
- }
2990
+ // Shutdown executor service asynchronously to avoid blocking UI thread
2991
+ shutdownExecutorServiceAsync();
2994
2992
 
2995
2993
  // Clear any remaining proxied requests
2996
2994
  synchronized (proxiedRequestsHashmap) {
@@ -3004,6 +3002,30 @@ public class WebViewDialog extends Dialog {
3004
3002
  }
3005
3003
  }
3006
3004
 
3005
+ private void shutdownExecutorServiceAsync() {
3006
+ if (executorService.isShutdown()) {
3007
+ return;
3008
+ }
3009
+ Thread shutdownThread = new Thread(
3010
+ () -> {
3011
+ try {
3012
+ executorService.shutdown();
3013
+ if (!executorService.awaitTermination(500, TimeUnit.MILLISECONDS)) {
3014
+ executorService.shutdownNow();
3015
+ }
3016
+ } catch (InterruptedException e) {
3017
+ Thread.currentThread().interrupt();
3018
+ executorService.shutdownNow();
3019
+ } catch (Exception e) {
3020
+ Log.e("InAppBrowser", "Error shutting down executor: " + e.getMessage());
3021
+ }
3022
+ },
3023
+ "InAppBrowser-ExecutorShutdown"
3024
+ );
3025
+ shutdownThread.setDaemon(true);
3026
+ shutdownThread.start();
3027
+ }
3028
+
3007
3029
  public void addProxiedRequest(String key, ProxiedRequest request) {
3008
3030
  synchronized (proxiedRequestsHashmap) {
3009
3031
  proxiedRequestsHashmap.put(key, request);
@@ -28,7 +28,7 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
28
28
  case aware = "AWARE"
29
29
  case fakeVisible = "FAKE_VISIBLE"
30
30
  }
31
- private let pluginVersion: String = "8.1.3"
31
+ private let pluginVersion: String = "8.1.5"
32
32
  public let identifier = "InAppBrowserPlugin"
33
33
  public let jsName = "InAppBrowser"
34
34
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/inappbrowser",
3
- "version": "8.1.3",
3
+ "version": "8.1.5",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",