Skip to content

Commit

Permalink
Merge pull request #6 from openremote/feature/clear_web_history_stack
Browse files Browse the repository at this point in the history
Added functionality to clear the webView history so a new root is set
  • Loading branch information
Miggets7 authored Jun 10, 2024
2 parents 23f04c9 + f0fad8e commit b3ae6d5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions ORLib/ORLib/UI/ORViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ open class ORViewcontroller : UIViewController {
}

func configureAccess() {
if let currentWebView = myWebView {
currentWebView.removeFromSuperview()
}
if let currentWebProgressBar = webProgressBar {
currentWebProgressBar.removeFromSuperview()
}

let webCfg:WKWebViewConfiguration = WKWebViewConfiguration()
let userController:WKUserContentController = WKUserContentController()

Expand Down Expand Up @@ -140,6 +147,16 @@ open class ORViewcontroller : UIViewController {
webProgressBar?.heightAnchor.constraint(equalToConstant: 2).isActive = true
}

func clearWebBackForwardList() {
if let webView = myWebView {
if let currentUrl = webView.url {
// the backForwardList of WKWebView is readonly, so need to create a new webview and set the currentUrl
configureAccess()
loadURL(url: currentUrl)
}
}
}

public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
if let webView = myWebView {
Expand Down Expand Up @@ -365,6 +382,9 @@ extension ORViewcontroller: WKScriptMessageHandler {
}
}
}
case "CLEAR_WEB_HISTORY":
clearWebBackForwardList()
break
default:
print("Unknown message type: \(type )")
}
Expand Down

0 comments on commit b3ae6d5

Please sign in to comment.