@capgo/capacitor-inappbrowser 8.10.3 → 8.10.4
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.
|
@@ -2,6 +2,7 @@ import Foundation
|
|
|
2
2
|
import Capacitor
|
|
3
3
|
import WebKit
|
|
4
4
|
import AuthenticationServices
|
|
5
|
+
import SafariServices
|
|
5
6
|
|
|
6
7
|
enum ActiveWebViewSupport {
|
|
7
8
|
static func shouldActivateNewWebView(isHidden: Bool, hasActiveWebView: Bool) -> Bool {
|
|
@@ -198,7 +199,7 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
198
199
|
case aware = "AWARE"
|
|
199
200
|
case fakeVisible = "FAKE_VISIBLE"
|
|
200
201
|
}
|
|
201
|
-
private let pluginVersion: String = "8.10.
|
|
202
|
+
private let pluginVersion: String = "8.10.4"
|
|
202
203
|
public let identifier = "CapgoInAppBrowserPlugin"
|
|
203
204
|
public let jsName = "CapgoInAppBrowser"
|
|
204
205
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -255,6 +256,8 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
255
256
|
private var closeModalDescription: String?
|
|
256
257
|
private var closeModalOk: String?
|
|
257
258
|
private var closeModalCancel: String?
|
|
259
|
+
private var safariViewController: SFSafariViewController?
|
|
260
|
+
private var safariOpenedUrl: String?
|
|
258
261
|
private var openSecureWindowCall: CAPPluginCall?
|
|
259
262
|
|
|
260
263
|
private func setup() {
|
|
@@ -2183,12 +2186,6 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
2183
2186
|
self.setup()
|
|
2184
2187
|
}
|
|
2185
2188
|
|
|
2186
|
-
let isInspectable = call.getBool("isInspectable", false)
|
|
2187
|
-
let preventDeeplink = call.getBool("preventDeeplink", false)
|
|
2188
|
-
self.isPresentAfterPageLoad = call.getBool("isPresentAfterPageLoad", false)
|
|
2189
|
-
|
|
2190
|
-
self.currentPluginCall = call
|
|
2191
|
-
|
|
2192
2189
|
guard let urlString = call.getString("url") else {
|
|
2193
2190
|
call.reject("Must provide a URL to open")
|
|
2194
2191
|
return
|
|
@@ -2199,70 +2196,42 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
2199
2196
|
return
|
|
2200
2197
|
}
|
|
2201
2198
|
|
|
2202
|
-
let
|
|
2203
|
-
|
|
2199
|
+
guard let url = URL(string: urlString),
|
|
2200
|
+
let scheme = url.scheme?.lowercased(),
|
|
2201
|
+
["http", "https"].contains(scheme) else {
|
|
2202
|
+
call.reject("Must provide a valid http(s) URL to open")
|
|
2203
|
+
return
|
|
2204
|
+
}
|
|
2204
2205
|
|
|
2205
2206
|
DispatchQueue.main.async {
|
|
2206
|
-
|
|
2207
|
-
call.reject("
|
|
2207
|
+
if self.safariViewController != nil {
|
|
2208
|
+
call.reject("Browser is already open")
|
|
2208
2209
|
return
|
|
2209
2210
|
}
|
|
2210
2211
|
|
|
2211
|
-
let
|
|
2212
|
+
let safariVC = SFSafariViewController(url: url)
|
|
2213
|
+
safariVC.delegate = self
|
|
2214
|
+
safariVC.modalPresentationStyle = .fullScreen
|
|
2212
2215
|
|
|
2213
|
-
self.
|
|
2216
|
+
self.safariViewController = safariVC
|
|
2217
|
+
self.safariOpenedUrl = url.absoluteString
|
|
2214
2218
|
|
|
2215
|
-
guard let
|
|
2216
|
-
|
|
2219
|
+
guard let rootPresenter = self.bridge?.viewController else {
|
|
2220
|
+
self.safariViewController = nil
|
|
2221
|
+
self.safariOpenedUrl = nil
|
|
2222
|
+
call.reject("Unable to present Safari View Controller")
|
|
2217
2223
|
return
|
|
2218
2224
|
}
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
emptyStatusBar.removeFromSuperview()
|
|
2226
|
-
}
|
|
2227
|
-
}
|
|
2225
|
+
let top = BlankTargetNavigationSupport.topPresenter(from: rootPresenter)
|
|
2226
|
+
guard top.presentedViewController == nil else {
|
|
2227
|
+
self.safariViewController = nil
|
|
2228
|
+
self.safariOpenedUrl = nil
|
|
2229
|
+
call.reject("Unable to present Safari View Controller: another view is already presented")
|
|
2230
|
+
return
|
|
2228
2231
|
}
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
webViewController.leftNavigationBarItemTypes = [.back, .forward, .reload]
|
|
2232
|
-
webViewController.capBrowserPlugin = self
|
|
2233
|
-
webViewController.hasDynamicTitle = true
|
|
2234
|
-
|
|
2235
|
-
self.navigationWebViewController = UINavigationController.init(rootViewController: webViewController)
|
|
2236
|
-
self.navigationWebViewController?.navigationBar.isTranslucent = false
|
|
2237
|
-
|
|
2238
|
-
// Ensure no lines or borders appear by default
|
|
2239
|
-
self.navigationWebViewController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
|
|
2240
|
-
self.navigationWebViewController?.navigationBar.shadowImage = UIImage()
|
|
2241
|
-
self.navigationWebViewController?.navigationBar.setValue(true, forKey: "hidesShadow")
|
|
2242
|
-
|
|
2243
|
-
// Use system appearance
|
|
2244
|
-
let isDarkMode = UITraitCollection.current.userInterfaceStyle == .dark
|
|
2245
|
-
let backgroundColor = isDarkMode ? UIColor.black : UIColor.white
|
|
2246
|
-
let textColor = isDarkMode ? UIColor.white : UIColor.black
|
|
2247
|
-
|
|
2248
|
-
// Apply colors
|
|
2249
|
-
webViewController.setupStatusBarBackground(color: backgroundColor)
|
|
2250
|
-
webViewController.tintColor = textColor
|
|
2251
|
-
self.navigationWebViewController?.navigationBar.tintColor = textColor
|
|
2252
|
-
self.navigationWebViewController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: textColor]
|
|
2253
|
-
webViewController.statusBarStyle = isDarkMode ? .lightContent : .darkContent
|
|
2254
|
-
webViewController.updateStatusBarStyle()
|
|
2255
|
-
|
|
2256
|
-
// Always hide toolbar to ensure no bottom bar
|
|
2257
|
-
self.navigationWebViewController?.setToolbarHidden(true, animated: false)
|
|
2258
|
-
|
|
2259
|
-
self.navigationWebViewController?.modalPresentationStyle = .overCurrentContext
|
|
2260
|
-
self.navigationWebViewController?.modalTransitionStyle = .crossDissolve
|
|
2261
|
-
|
|
2262
|
-
if !self.isPresentAfterPageLoad {
|
|
2263
|
-
self.presentView()
|
|
2232
|
+
top.present(safariVC, animated: true) {
|
|
2233
|
+
call.resolve()
|
|
2264
2234
|
}
|
|
2265
|
-
call.resolve()
|
|
2266
2235
|
}
|
|
2267
2236
|
}
|
|
2268
2237
|
|
|
@@ -2359,6 +2328,17 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
2359
2328
|
let isAnimated = call.getBool("isAnimated", true)
|
|
2360
2329
|
|
|
2361
2330
|
DispatchQueue.main.async {
|
|
2331
|
+
if call.getString("id") == nil, let safariViewController = self.safariViewController {
|
|
2332
|
+
let url = self.safariOpenedUrl ?? ""
|
|
2333
|
+
self.safariViewController = nil
|
|
2334
|
+
self.safariOpenedUrl = nil
|
|
2335
|
+
safariViewController.dismiss(animated: isAnimated) {
|
|
2336
|
+
self.notifyListeners("closeEvent", data: ["url": url])
|
|
2337
|
+
call.resolve()
|
|
2338
|
+
}
|
|
2339
|
+
return
|
|
2340
|
+
}
|
|
2341
|
+
|
|
2362
2342
|
let targetId = call.getString("id") ?? self.activeWebViewId
|
|
2363
2343
|
if let targetId,
|
|
2364
2344
|
let webViewController = self.webViewControllers[targetId],
|
|
@@ -2402,6 +2382,7 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
2402
2382
|
}
|
|
2403
2383
|
}
|
|
2404
2384
|
|
|
2385
|
+
|
|
2405
2386
|
private func showPrivacyScreen() {
|
|
2406
2387
|
if privacyScreen == nil {
|
|
2407
2388
|
let newPrivacyScreen = UIImageView()
|
|
@@ -2583,3 +2564,23 @@ extension CapgoInAppBrowserPlugin: ASWebAuthenticationPresentationContextProvidi
|
|
|
2583
2564
|
return self.bridge?.viewController?.view.window ?? ASPresentationAnchor()
|
|
2584
2565
|
}
|
|
2585
2566
|
}
|
|
2567
|
+
|
|
2568
|
+
extension CapgoInAppBrowserPlugin: SFSafariViewControllerDelegate {
|
|
2569
|
+
public func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
|
|
2570
|
+
guard safariViewController != nil else {
|
|
2571
|
+
return
|
|
2572
|
+
}
|
|
2573
|
+
let url = safariOpenedUrl ?? ""
|
|
2574
|
+
safariViewController = nil
|
|
2575
|
+
safariOpenedUrl = nil
|
|
2576
|
+
notifyListeners("closeEvent", data: ["url": url])
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
public func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
|
|
2580
|
+
if didLoadSuccessfully {
|
|
2581
|
+
notifyListeners("browserPageLoaded", data: [:])
|
|
2582
|
+
} else {
|
|
2583
|
+
notifyListeners("pageLoadError", data: [:])
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
}
|