Skip to content

Commit

Permalink
Redirects fix
Browse files Browse the repository at this point in the history
  • Loading branch information
flypaper0 committed Aug 30, 2023
1 parent 42e42d8 commit 68a6353
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class Web3InboxViewController: UIViewController {
}

@objc func refreshTapped() {
webView?.reload()
Web3Inbox.instance.reload()
}

@objc func getUrlPressed(_ sender: UIBarItem) {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Web3Inbox/Web3InboxClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public final class Web3InboxClient {
public func register(deviceToken: Data) async throws {
try await notifyClient.register(deviceToken: deviceToken)
}

public func reload() {
webviewSubscriber.reload(webView)
}
}

// MARK: - Privates
Expand Down
19 changes: 8 additions & 11 deletions Sources/Web3Inbox/WebView/WebViewRequestSubscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ final class WebViewRequestSubscriber: NSObject, WKScriptMessageHandler {
}
}
}

func reload(_ webView: WKWebView) {
webView.load(URLRequest(url: url))
}
}

extension WebViewRequestSubscriber: WKUIDelegate {
Expand All @@ -55,25 +59,18 @@ extension WebViewRequestSubscriber: WKUIDelegate {
func webView(_ webView: WKWebView, requestMediaCapturePermissionFor origin: WKSecurityOrigin, initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType, decisionHandler: @escaping (WKPermissionDecision) -> Void) {
decisionHandler(.grant)
}

#endif
}

extension WebViewRequestSubscriber: WKNavigationDelegate {

func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {

guard
let from = webView.url,
let to = navigationAction.request.url
else { return decisionHandler(.cancel) }

if from.absoluteString.contains("/login") || to.absoluteString.contains("/login") {
decisionHandler(.cancel)
webView.load(URLRequest(url: url))
} else {
if navigationAction.request.url == url {
decisionHandler(.allow)
} else {
decisionHandler(.cancel)
}
}
}

0 comments on commit 68a6353

Please sign in to comment.