TabView: Favicons in tab bar

This commit is contained in:
James Magahern
2021-02-15 19:21:48 -08:00
parent d62fa42f57
commit 41289bf790
4 changed files with 33 additions and 13 deletions

View File

@@ -35,6 +35,7 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
private var backButtonObservation: NSKeyValueObservation?
private var forwardButtonObservation: NSKeyValueObservation?
private var activeTabObservation: AnyCancellable?
private var faviconObservation: AnyCancellable?
private var loadError: Error?
@@ -276,12 +277,14 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
}
private func updateTitleAndURL(forWebView webView: WKWebView) {
browserView.titlebarView.setTitle(webView.title ?? "")
if let urlString = webView.url?.absoluteString {
toolbarController.urlBar.textField.text = urlString
} else {
toolbarController.urlBar.textField.text = ""
if webView == browserView.webView {
browserView.titlebarView.setTitle(webView.title ?? "")
if let urlString = webView.url?.absoluteString {
toolbarController.urlBar.textField.text = urlString
} else {
toolbarController.urlBar.textField.text = ""
}
}
// Figure out which tab this corresponds to
@@ -336,6 +339,12 @@ class BrowserViewController: UIViewController, WKNavigationDelegate, WKUIDelegat
toolbarController.forwardButton.isEnabled = webView.canGoForward
})
// Favicon observation
faviconObservation = tab.$favicon.receive(on: DispatchQueue.main)
.sink { [unowned self] _ in
updateTitleAndURL(forWebView: webView)
}
// Script blocker button
updateScriptBlockerButton()