@capgo/inappbrowser 8.0.1 → 8.0.2

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.0.1";
53
+ private final String pluginVersion = "8.0.2";
54
54
 
55
55
  public static final String CUSTOM_TAB_PACKAGE_NAME = "com.android.chrome"; // Change when in stable
56
56
  private CustomTabsClient customTabsClient;
@@ -386,9 +386,7 @@ public class WebViewDialog extends Dialog {
386
386
  _webView.getSettings().setGeolocationEnabled(true);
387
387
 
388
388
  // Ensure secure context for Payment Request API
389
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
390
- _webView.getSettings().setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
391
- }
389
+ _webView.getSettings().setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
392
390
 
393
391
  // Enable Payment Request API only if feature is supported
394
392
  if (WebViewFeature.isFeatureSupported(WebViewFeature.PAYMENT_REQUEST)) {
@@ -16,23 +16,23 @@ public enum WKWebSource: Equatable {
16
16
 
17
17
  public var url: URL? {
18
18
  switch self {
19
- case .remote(let u): return u
20
- case .file(let u, access: _): return u
19
+ case .remote(let urlValue): return urlValue
20
+ case .file(let urlValue, access: _): return urlValue
21
21
  default: return nil
22
22
  }
23
23
  }
24
24
 
25
25
  public var remoteURL: URL? {
26
26
  switch self {
27
- case .remote(let u): return u
27
+ case .remote(let urlValue): return urlValue
28
28
  default: return nil
29
29
  }
30
30
  }
31
31
 
32
32
  public var absoluteString: String? {
33
33
  switch self {
34
- case .remote(let u): return u.absoluteString
35
- case .file(let u, access: _): return u.absoluteString
34
+ case .remote(let urlValue): return urlValue.absoluteString
35
+ case .file(let urlValue, access: _): return urlValue.absoluteString
36
36
  default: return nil
37
37
  }
38
38
  }
@@ -24,7 +24,7 @@ extension UIColor {
24
24
  */
25
25
  @objc(InAppBrowserPlugin)
26
26
  public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
27
- private let pluginVersion: String = "8.0.1"
27
+ private let pluginVersion: String = "8.0.2"
28
28
  public let identifier = "InAppBrowserPlugin"
29
29
  public let jsName = "InAppBrowser"
30
30
  public let pluginMethods: [CAPPluginMethod] = [
@@ -174,11 +174,10 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
174
174
  call.reject("IOS settings not found")
175
175
  return
176
176
  }
177
- if !(iosSettingsRaw is JSObject) {
177
+ guard let iosSettings = iosSettingsRaw as? JSObject else {
178
178
  call.reject("IOS settings are not an object")
179
179
  return
180
180
  }
181
- let iosSettings = iosSettingsRaw as! JSObject
182
181
 
183
182
  guard let iconType = iosSettings["iconType"] as? String else {
184
183
  call.reject("buttonNearDone.iconType is empty")
@@ -371,8 +370,8 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
371
370
  // Read dimension options
372
371
  let width = call.getFloat("width")
373
372
  let height = call.getFloat("height")
374
- let x = call.getFloat("x")
375
- let y = call.getFloat("y")
373
+ let xPos = call.getFloat("x")
374
+ let yPos = call.getFloat("y")
376
375
 
377
376
  // Validate dimension parameters
378
377
  if width != nil && height == nil {
@@ -410,11 +409,11 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
410
409
  if let height = height {
411
410
  webViewController.customHeight = CGFloat(height)
412
411
  }
413
- if let x = x {
414
- webViewController.customX = CGFloat(x)
412
+ if let xPos = xPos {
413
+ webViewController.customX = CGFloat(xPos)
415
414
  }
416
- if let y = y {
417
- webViewController.customY = CGFloat(y)
415
+ if let yPos = yPos {
416
+ webViewController.customY = CGFloat(yPos)
418
417
  }
419
418
 
420
419
  // Set native navigation gestures before view loads
@@ -618,24 +617,24 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
618
617
  containerView.backgroundColor = .clear
619
618
 
620
619
  // Calculate dimensions - use screen width if only height is provided
621
- let finalWidth = width != nil ? CGFloat(width!) : UIScreen.main.bounds.width
622
- let finalHeight = height != nil ? CGFloat(height!) : UIScreen.main.bounds.height
620
+ let finalWidth = width.map { CGFloat($0) } ?? UIScreen.main.bounds.width
621
+ let finalHeight = height.map { CGFloat($0) } ?? UIScreen.main.bounds.height
623
622
 
624
623
  containerView.targetFrame = CGRect(
625
- x: CGFloat(x ?? 0),
626
- y: CGFloat(y ?? 0),
624
+ x: CGFloat(xPos ?? 0),
625
+ y: CGFloat(yPos ?? 0),
627
626
  width: finalWidth,
628
627
  height: finalHeight
629
628
  )
630
629
 
631
630
  // Replace the navigation controller's view with our pass-through container
632
- if let navController = self.navigationWebViewController {
633
- let originalView = navController.view!
631
+ if let navController = self.navigationWebViewController,
632
+ let originalView = navController.view {
634
633
  navController.view = containerView
635
634
  containerView.addSubview(originalView)
636
635
  originalView.frame = CGRect(
637
- x: CGFloat(x ?? 0),
638
- y: CGFloat(y ?? 0),
636
+ x: CGFloat(xPos ?? 0),
637
+ y: CGFloat(yPos ?? 0),
639
638
  width: finalWidth,
640
639
  height: finalHeight
641
640
  )
@@ -760,7 +759,7 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
760
759
  do {
761
760
  let regex = try NSRegularExpression(pattern: hexColorRegex)
762
761
  let range = NSRange(location: 0, length: input.utf16.count)
763
- if let _ = regex.firstMatch(in: input, options: [], range: range) {
762
+ if regex.firstMatch(in: input, options: [], range: range) != nil {
764
763
  return true
765
764
  }
766
765
  } catch {
@@ -876,20 +875,23 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
876
875
 
877
876
  private func showPrivacyScreen() {
878
877
  if privacyScreen == nil {
879
- self.privacyScreen = UIImageView()
878
+ let newPrivacyScreen = UIImageView()
879
+ self.privacyScreen = newPrivacyScreen
880
880
  if let launchImage = UIImage(named: "LaunchImage") {
881
- privacyScreen!.image = launchImage
882
- privacyScreen!.frame = UIScreen.main.bounds
883
- privacyScreen!.contentMode = .scaleAspectFill
884
- privacyScreen!.isUserInteractionEnabled = false
881
+ newPrivacyScreen.image = launchImage
882
+ newPrivacyScreen.frame = UIScreen.main.bounds
883
+ newPrivacyScreen.contentMode = .scaleAspectFill
884
+ newPrivacyScreen.isUserInteractionEnabled = false
885
885
  } else if let launchImage = UIImage(named: "Splash") {
886
- privacyScreen!.image = launchImage
887
- privacyScreen!.frame = UIScreen.main.bounds
888
- privacyScreen!.contentMode = .scaleAspectFill
889
- privacyScreen!.isUserInteractionEnabled = false
886
+ newPrivacyScreen.image = launchImage
887
+ newPrivacyScreen.frame = UIScreen.main.bounds
888
+ newPrivacyScreen.contentMode = .scaleAspectFill
889
+ newPrivacyScreen.isUserInteractionEnabled = false
890
890
  }
891
891
  }
892
- self.navigationWebViewController?.view.addSubview(self.privacyScreen!)
892
+ if let screen = self.privacyScreen {
893
+ self.navigationWebViewController?.view.addSubview(screen)
894
+ }
893
895
  }
894
896
 
895
897
  private func hidePrivacyScreen() {
@@ -929,8 +931,8 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
929
931
  @objc func updateDimensions(_ call: CAPPluginCall) {
930
932
  let width = call.getFloat("width")
931
933
  let height = call.getFloat("height")
932
- let x = call.getFloat("x")
933
- let y = call.getFloat("y")
934
+ let xPos = call.getFloat("x")
935
+ let yPos = call.getFloat("y")
934
936
 
935
937
  DispatchQueue.main.async {
936
938
  guard let webViewController = self.webViewController else {
@@ -939,10 +941,10 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
939
941
  }
940
942
 
941
943
  webViewController.updateDimensions(
942
- width: width != nil ? CGFloat(width!) : nil,
943
- height: height != nil ? CGFloat(height!) : nil,
944
- x: x != nil ? CGFloat(x!) : nil,
945
- y: y != nil ? CGFloat(y!) : nil
944
+ width: width.map { CGFloat($0) },
945
+ height: height.map { CGFloat($0) },
946
+ xPos: xPos.map { CGFloat($0) },
947
+ yPos: yPos.map { CGFloat($0) }
946
948
  )
947
949
 
948
950
  call.resolve()
@@ -735,8 +735,8 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
735
735
  self.previousToolbarState = (navigation.toolbar.tintColor, navigation.toolbar.isHidden)
736
736
  }
737
737
 
738
- if let s = self.source {
739
- self.load(source: s)
738
+ if let sourceValue = self.source {
739
+ self.load(source: sourceValue)
740
740
  } else {
741
741
  print("[\(type(of: self))][Error] Invalid url")
742
742
  }
@@ -753,11 +753,9 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
753
753
  @objc func restateViewHeight() {
754
754
  var bottomPadding = CGFloat(0.0)
755
755
  var topPadding = CGFloat(0.0)
756
- if #available(iOS 11.0, *) {
757
- let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow })
758
- bottomPadding = window?.safeAreaInsets.bottom ?? 0.0
759
- topPadding = window?.safeAreaInsets.top ?? 0.0
760
- }
756
+ let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow })
757
+ bottomPadding = window?.safeAreaInsets.bottom ?? 0.0
758
+ topPadding = window?.safeAreaInsets.top ?? 0.0
761
759
  if UIDevice.current.orientation.isPortrait {
762
760
  // Don't force toolbar visibility
763
761
  if self.viewHeightPortrait == nil {
@@ -909,8 +907,8 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
909
907
  // MARK: - Public Methods
910
908
  public extension WKWebViewController {
911
909
 
912
- func load(source s: WKWebSource) {
913
- switch s {
910
+ func load(source sourceValue: WKWebSource) {
911
+ switch sourceValue {
914
912
  case .remote(let url):
915
913
  self.load(remote: url)
916
914
  case .file(let url, access: let access):
@@ -1188,16 +1186,14 @@ fileprivate extension WKWebViewController {
1188
1186
  forwardBarButtonItem.isEnabled = webView?.canGoForward ?? false
1189
1187
 
1190
1188
  let updateReloadBarButtonItem: (UIBarButtonItem, Bool) -> UIBarButtonItem = {
1191
- [unowned self] barButtonItem, isLoading in
1189
+ [weak self] barButtonItem, isLoading in
1190
+ guard let self = self else { return barButtonItem }
1192
1191
  switch barButtonItem {
1193
- case self.reloadBarButtonItem:
1194
- fallthrough
1195
- case self.stopBarButtonItem:
1192
+ case self.reloadBarButtonItem, self.stopBarButtonItem:
1196
1193
  return isLoading ? self.stopBarButtonItem : self.reloadBarButtonItem
1197
1194
  default:
1198
- break
1195
+ return barButtonItem
1199
1196
  }
1200
- return barButtonItem
1201
1197
  }
1202
1198
 
1203
1199
  let isLoading = webView?.isLoading ?? false
@@ -1295,9 +1291,9 @@ fileprivate extension WKWebViewController {
1295
1291
  }
1296
1292
 
1297
1293
  private func normalizeHost(_ host: String?) -> String? {
1298
- guard var h = host?.lowercased() else { return nil }
1299
- if h.hasPrefix("www.") { h.removeFirst(4) }
1300
- return h
1294
+ guard var hostValue = host?.lowercased() else { return nil }
1295
+ if hostValue.hasPrefix("www.") { hostValue.removeFirst(4) }
1296
+ return hostValue
1301
1297
  }
1302
1298
 
1303
1299
  func isUrlAuthorized(_ url: URL, authorizedLinks: [String]) -> Bool {
@@ -1411,8 +1407,8 @@ fileprivate extension WKWebViewController {
1411
1407
  webView?.stopLoading()
1412
1408
  if webView?.url != nil {
1413
1409
  webView?.reload()
1414
- } else if let s = self.source {
1415
- self.load(source: s)
1410
+ } else if let sourceValue = self.source {
1411
+ self.load(source: sourceValue)
1416
1412
  }
1417
1413
  }
1418
1414
 
@@ -1423,17 +1419,17 @@ fileprivate extension WKWebViewController {
1423
1419
  @objc func activityDidClick(sender: AnyObject) {
1424
1420
  print("[DEBUG] Activity button clicked, shareSubject: \(self.shareSubject ?? "nil")")
1425
1421
 
1426
- guard let s = self.source else {
1422
+ guard let sourceValue = self.source else {
1427
1423
  print("[DEBUG] Activity button: No source available")
1428
1424
  return
1429
1425
  }
1430
1426
 
1431
1427
  let items: [Any]
1432
- switch s {
1433
- case .remote(let u):
1434
- items = [u]
1435
- case .file(let u, access: _):
1436
- items = [u]
1428
+ switch sourceValue {
1429
+ case .remote(let urlValue):
1430
+ items = [urlValue]
1431
+ case .file(let urlValue, access: _):
1432
+ items = [urlValue]
1437
1433
  case .string(let str, base: _):
1438
1434
  items = [str]
1439
1435
  }
@@ -1482,7 +1478,9 @@ fileprivate extension WKWebViewController {
1482
1478
  private func showShareSheet(items: [Any], sender: AnyObject) {
1483
1479
  let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
1484
1480
  activityViewController.setValue(self.shareSubject ?? self.title, forKey: "subject")
1485
- activityViewController.popoverPresentationController?.barButtonItem = (sender as! UIBarButtonItem)
1481
+ if let barButtonItem = sender as? UIBarButtonItem {
1482
+ activityViewController.popoverPresentationController?.barButtonItem = barButtonItem
1483
+ }
1486
1484
  self.present(activityViewController, animated: true, completion: nil)
1487
1485
  }
1488
1486
 
@@ -1763,16 +1761,15 @@ extension WKWebViewController: WKNavigationDelegate {
1763
1761
  public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
1764
1762
  updateBarButtonItems()
1765
1763
  self.progressView?.progress = 0
1766
- if let u = webView.url {
1767
- self.url = u
1768
- delegate?.webViewController?(self, didStart: u)
1764
+ if let urlValue = webView.url {
1765
+ self.url = urlValue
1766
+ delegate?.webViewController?(self, didStart: urlValue)
1769
1767
  }
1770
1768
  }
1771
1769
  public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
1772
1770
  if !didpageInit && self.capBrowserPlugin?.isPresentAfterPageLoad == true {
1773
1771
  // Only inject preShowScript if it wasn't already injected at document start
1774
- let shouldInjectScript = self.preShowScript != nil &&
1775
- !self.preShowScript!.isEmpty &&
1772
+ let shouldInjectScript = self.preShowScript.map { !$0.isEmpty } ?? false &&
1776
1773
  self.preShowScriptInjectionTime != "documentStart"
1777
1774
 
1778
1775
  if shouldInjectScript {
@@ -1927,26 +1924,26 @@ extension WKWebViewController: WKNavigationDelegate {
1927
1924
 
1928
1925
  // Apply custom dimensions if both width and height are specified
1929
1926
  if let width = customWidth, let height = customHeight {
1930
- let x = customX ?? 0
1931
- let y = customY ?? 0
1927
+ let xPos = customX ?? 0
1928
+ let yPos = customY ?? 0
1932
1929
 
1933
1930
  // Set the frame for the navigation controller's view
1934
- navigationController.view.frame = CGRect(x: x, y: y, width: width, height: height)
1931
+ navigationController.view.frame = CGRect(x: xPos, y: yPos, width: width, height: height)
1935
1932
  }
1936
1933
  // If only height is specified, use fullscreen width
1937
1934
  else if let height = customHeight, customWidth == nil {
1938
- let x = customX ?? 0
1939
- let y = customY ?? 0
1935
+ let xPos = customX ?? 0
1936
+ let yPos = customY ?? 0
1940
1937
  let screenWidth = UIScreen.main.bounds.width
1941
1938
 
1942
1939
  // Set the frame with fullscreen width and custom height
1943
- navigationController.view.frame = CGRect(x: x, y: y, width: screenWidth, height: height)
1940
+ navigationController.view.frame = CGRect(x: xPos, y: yPos, width: screenWidth, height: height)
1944
1941
  }
1945
1942
  // Otherwise, use default fullscreen behavior (no action needed)
1946
1943
  }
1947
1944
 
1948
1945
  /// Update dimensions at runtime
1949
- open func updateDimensions(width: CGFloat?, height: CGFloat?, x: CGFloat?, y: CGFloat?) {
1946
+ open func updateDimensions(width: CGFloat?, height: CGFloat?, xPos: CGFloat?, yPos: CGFloat?) {
1950
1947
  // Update stored dimensions
1951
1948
  if let width = width {
1952
1949
  customWidth = width
@@ -1954,11 +1951,11 @@ extension WKWebViewController: WKNavigationDelegate {
1954
1951
  if let height = height {
1955
1952
  customHeight = height
1956
1953
  }
1957
- if let x = x {
1958
- customX = x
1954
+ if let xPos = xPos {
1955
+ customX = xPos
1959
1956
  }
1960
- if let y = y {
1961
- customY = y
1957
+ if let yPos = yPos {
1958
+ customY = yPos
1962
1959
  }
1963
1960
 
1964
1961
  // Apply the new dimensions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/inappbrowser",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -23,6 +23,7 @@
23
23
  "bugs": {
24
24
  "url": "https://github.com/Cap-go/capacitor-inappbrowser/issues"
25
25
  },
26
+ "homepage": "https://capgo.app/docs/plugins/inappbrowser/",
26
27
  "keywords": [
27
28
  "capacitor",
28
29
  "plugin",
@@ -37,7 +38,7 @@
37
38
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
38
39
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
39
40
  "eslint": "eslint .",
40
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
41
+ "prettier": "prettier-pretty-check \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
41
42
  "swiftlint": "node-swiftlint",
42
43
  "docgen": "docgen --api InAppBrowserPlugin --output-readme README.md --output-json dist/docs.json",
43
44
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
@@ -63,7 +64,8 @@
63
64
  "rimraf": "^6.1.0",
64
65
  "rollup": "^4.53.2",
65
66
  "swiftlint": "^2.0.0",
66
- "typescript": "^5.9.3"
67
+ "typescript": "^5.9.3",
68
+ "prettier-pretty-check": "^0.2.0"
67
69
  },
68
70
  "peerDependencies": {
69
71
  "@capacitor/core": ">=8.0.0"