@capgo/inappbrowser 6.0.0 → 6.0.3

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.
@@ -28,6 +28,16 @@ private struct UrlsHandledByApp {
28
28
  @objc optional func webViewController(_ controller: WKWebViewController, decidePolicy url: URL, navigationType: NavigationType) -> Bool
29
29
  }
30
30
 
31
+ extension Dictionary {
32
+ func mapKeys<T>(_ transform: (Key) throws -> T) rethrows -> [T: Value] {
33
+ var dictionary = [T: Value]()
34
+ for (key, value) in self {
35
+ dictionary[try transform(key)] = value
36
+ }
37
+ return dictionary
38
+ }
39
+ }
40
+
31
41
  open class WKWebViewController: UIViewController {
32
42
 
33
43
  public init() {
@@ -50,11 +60,11 @@ open class WKWebViewController: UIViewController {
50
60
  self.initWebview()
51
61
  }
52
62
 
53
- public init(url: URL, headers: [String: String]) {
63
+ public init(url: URL, headers: [String: String], isInspectable: Bool) {
54
64
  super.init(nibName: nil, bundle: nil)
55
65
  self.source = .remote(url)
56
66
  self.setHeaders(headers: headers)
57
- self.initWebview()
67
+ self.initWebview(isInspectable: isInspectable)
58
68
  }
59
69
 
60
70
  open var hasDynamicTitle = false
@@ -74,12 +84,20 @@ open class WKWebViewController: UIViewController {
74
84
  var viewHeightLandscape: CGFloat?
75
85
  var viewHeightPortrait: CGFloat?
76
86
  var currentViewHeight: CGFloat?
87
+ open var closeModal = false
88
+ open var closeModalTitle = ""
89
+ open var closeModalDescription = ""
90
+ open var closeModalOk = ""
91
+ open var closeModalCancel = ""
77
92
 
78
93
  func setHeaders(headers: [String: String]) {
79
94
  self.headers = headers
80
- let userAgent = self.headers?["User-Agent"]
95
+ let lowercasedHeaders = headers.mapKeys { $0.lowercased() }
96
+ let userAgent = lowercasedHeaders["user-agent"]
81
97
  self.headers?.removeValue(forKey: "User-Agent")
82
- if userAgent != nil {
98
+ self.headers?.removeValue(forKey: "user-agent")
99
+
100
+ if let userAgent = userAgent {
83
101
  self.customUserAgent = userAgent
84
102
  }
85
103
  }
@@ -188,7 +206,7 @@ open class WKWebViewController: UIViewController {
188
206
  }
189
207
  }
190
208
 
191
- open func initWebview() {
209
+ open func initWebview(isInspectable: Bool = true) {
192
210
 
193
211
  self.view.backgroundColor = UIColor.white
194
212
 
@@ -198,6 +216,11 @@ open class WKWebViewController: UIViewController {
198
216
  let webConfiguration = WKWebViewConfiguration()
199
217
  let webView = WKWebView(frame: .zero, configuration: webConfiguration)
200
218
 
219
+ if webView.responds(to: Selector(("setInspectable:"))) {
220
+ // Fix: https://stackoverflow.com/questions/76216183/how-to-debug-wkwebview-in-ios-16-4-1-using-xcode-14-2/76603043#76603043
221
+ webView.perform(Selector(("setInspectable:")), with: isInspectable)
222
+ }
223
+
201
224
  webView.uiDelegate = self
202
225
  webView.navigationDelegate = self
203
226
 
@@ -223,8 +246,6 @@ open class WKWebViewController: UIViewController {
223
246
  self.previousToolbarState = (navigation.toolbar.tintColor, navigation.toolbar.isHidden)
224
247
  }
225
248
 
226
- // self.restateViewHeight()
227
-
228
249
  if let s = self.source {
229
250
  self.load(source: s)
230
251
  } else {
@@ -242,19 +263,19 @@ open class WKWebViewController: UIViewController {
242
263
  var bottomPadding = CGFloat(0.0)
243
264
  var topPadding = CGFloat(0.0)
244
265
  if #available(iOS 11.0, *) {
245
- let window = UIApplication.shared.keyWindow
246
- bottomPadding = (window?.safeAreaInsets.bottom)!
247
- topPadding = (window?.safeAreaInsets.top)!
266
+ let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow })
267
+ bottomPadding = window?.safeAreaInsets.bottom ?? 0.0
268
+ topPadding = window?.safeAreaInsets.top ?? 0.0
248
269
  }
249
270
  if UIDevice.current.orientation.isPortrait {
250
271
  self.navigationController?.toolbar.isHidden = false
251
272
  if self.viewHeightPortrait == nil {
252
273
  self.viewHeightPortrait = self.view.safeAreaLayoutGuide.layoutFrame.size.height
253
274
  if toolbarItemTypes.count == 0 {
254
- self.viewHeightPortrait! = self.viewHeightPortrait! + bottomPadding
275
+ self.viewHeightPortrait! += bottomPadding
255
276
  }
256
277
  if self.navigationController?.navigationBar.isHidden == true {
257
- self.viewHeightPortrait = self.viewHeightPortrait! + topPadding
278
+ self.viewHeightPortrait! += topPadding
258
279
  }
259
280
  }
260
281
  self.currentViewHeight = self.viewHeightPortrait
@@ -263,10 +284,10 @@ open class WKWebViewController: UIViewController {
263
284
  if self.viewHeightLandscape == nil {
264
285
  self.viewHeightLandscape = self.view.safeAreaLayoutGuide.layoutFrame.size.height
265
286
  if toolbarItemTypes.count == 0 {
266
- self.viewHeightLandscape! = self.viewHeightLandscape! + bottomPadding
287
+ self.viewHeightLandscape! += bottomPadding
267
288
  }
268
289
  if self.navigationController?.navigationBar.isHidden == true {
269
- self.viewHeightLandscape = self.viewHeightLandscape! + topPadding
290
+ self.viewHeightLandscape! += topPadding
270
291
  }
271
292
  }
272
293
  self.currentViewHeight = self.viewHeightLandscape
@@ -295,11 +316,6 @@ open class WKWebViewController: UIViewController {
295
316
  rollbackState()
296
317
  }
297
318
 
298
- override open func didReceiveMemoryWarning() {
299
- super.didReceiveMemoryWarning()
300
- // Dispose of any resources that can be recreated.
301
- }
302
-
303
319
  override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
304
320
  switch keyPath {
305
321
  case estimatedProgressKeyPath?:
@@ -360,6 +376,13 @@ public extension WKWebViewController {
360
376
  webView?.go(to: firstPageItem)
361
377
  }
362
378
  }
379
+ func reload() {
380
+ webView?.reload()
381
+ }
382
+
383
+ func executeScript(script: String, completion: ((Any?, Error?) -> Void)? = nil) {
384
+ webView?.evaluateJavaScript(script, completionHandler: completion)
385
+ }
363
386
  }
364
387
 
365
388
  // MARK: - Fileprivate Methods
@@ -672,7 +695,7 @@ fileprivate extension WKWebViewController {
672
695
  }
673
696
  }
674
697
 
675
- @objc func doneDidClick(sender: AnyObject) {
698
+ func closeView () {
676
699
  var canDismiss = true
677
700
  if let url = self.source?.url {
678
701
  canDismiss = delegate?.webViewController?(self, canDismiss: url) ?? true
@@ -684,6 +707,21 @@ fileprivate extension WKWebViewController {
684
707
  }
685
708
  }
686
709
 
710
+ @objc func doneDidClick(sender: AnyObject) {
711
+ // check if closeModal is true, if true display alert before close
712
+ if self.closeModal {
713
+ let alert = UIAlertController(title: self.closeModalTitle, message: self.closeModalDescription, preferredStyle: UIAlertController.Style.alert)
714
+ alert.addAction(UIAlertAction(title: self.closeModalOk, style: UIAlertAction.Style.default, handler: { _ in
715
+ self.closeView()
716
+ }))
717
+ alert.addAction(UIAlertAction(title: self.closeModalCancel, style: UIAlertAction.Style.default, handler: nil))
718
+ self.present(alert, animated: true, completion: nil)
719
+ } else {
720
+ self.closeView()
721
+ }
722
+
723
+ }
724
+
687
725
  @objc func customDidClick(sender: BlockBarButtonItem) {
688
726
  sender.block?(self)
689
727
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/inappbrowser",
3
- "version": "6.0.0",
3
+ "version": "6.0.3",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -30,12 +30,12 @@
30
30
  ],
31
31
  "scripts": {
32
32
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
33
- "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
33
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -sdk iphoneos -scheme Plugin && cd ..",
34
34
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
35
35
  "verify:web": "npm run build",
36
36
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
37
37
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
38
- "eslint": "eslint . --ext ts",
38
+ "eslint": "eslint .",
39
39
  "prettier": "prettier --config .prettierrc.js \"**/*.{css,html,ts,js,java}\"",
40
40
  "swiftlint": "node-swiftlint",
41
41
  "docgen": "docgen --api InAppBrowserPlugin --output-readme README.md --output-json dist/docs.json",
@@ -45,34 +45,32 @@
45
45
  "prepublishOnly": "npm run build"
46
46
  },
47
47
  "devDependencies": {
48
- "@capacitor/android": "^5.0.3",
49
- "@capacitor/cli": "^5.0.3",
50
- "@capacitor/core": "^5.0.3",
51
- "@capacitor/docgen": "^0.2.1",
52
- "@capacitor/ios": "^5.0.3",
48
+ "@capacitor/android": "^6.0.0",
49
+ "@capacitor/cli": "^6.0.0",
50
+ "@capacitor/core": "^6.0.0",
51
+ "@capacitor/docgen": "^0.2.2",
52
+ "@capacitor/ios": "^6.0.0",
53
53
  "@ionic/eslint-config": "^0.3.0",
54
- "@ionic/prettier-config": "^3.0.0",
54
+ "@ionic/prettier-config": "^4.0.0",
55
55
  "@ionic/swiftlint-config": "^1.1.2",
56
- "@typescript-eslint/eslint-plugin": "^5.59.7",
57
- "@typescript-eslint/parser": "^5.59.7",
58
- "eslint": "^8.41.0",
59
- "eslint-plugin-import": "^2.27.5",
60
- "husky": "^8.0.3",
61
- "prettier": "^2.8.8",
62
- "prettier-plugin-java": "^2.1.0",
63
- "rimraf": "^5.0.1",
64
- "rollup": "^3.23.0",
56
+ "@types/node": "^20.12.7",
57
+ "@typescript-eslint/eslint-plugin": "^7.8.0",
58
+ "@typescript-eslint/parser": "^7.8.0",
59
+ "eslint": "^9.1.1",
60
+ "eslint-plugin-import": "^2.29.1",
61
+ "husky": "^9.0.11",
62
+ "prettier": "^3.2.5",
63
+ "prettier-plugin-java": "^2.6.0",
64
+ "rimraf": "^5.0.5",
65
+ "rollup": "^4.17.1",
65
66
  "swiftlint": "^1.0.2",
66
- "typescript": "^5.0.4"
67
+ "typescript": "^5.4.5"
67
68
  },
68
69
  "peerDependencies": {
69
- "@capacitor/core": "^5.0.0"
70
+ "@capacitor/core": "^6.0.0"
70
71
  },
71
72
  "prettier": "@ionic/prettier-config",
72
73
  "swiftlint": "@ionic/swiftlint-config",
73
- "eslintConfig": {
74
- "extends": "@ionic/eslint-config/recommended"
75
- },
76
74
  "capacitor": {
77
75
  "ios": {
78
76
  "src": "ios"