diff --git a/App/Browser View/BrowserViewController.swift b/App/Browser View/BrowserViewController.swift index e85287d..3ace232 100644 --- a/App/Browser View/BrowserViewController.swift +++ b/App/Browser View/BrowserViewController.swift @@ -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() diff --git a/App/Tabs/Tab.swift b/App/Tabs/Tab.swift index bc38d96..dd1be7f 100644 --- a/App/Tabs/Tab.swift +++ b/App/Tabs/Tab.swift @@ -60,8 +60,8 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate }() public var identifier = UUID() + @Published public var favicon: UIImage? - public var favicon: UIImage? private var faviconHost: String? private var faviconRequest: AnyCancellable? diff --git a/App/Tabs/TabBarView.swift b/App/Tabs/TabBarView.swift index 1b59846..a25aa7d 100644 --- a/App/Tabs/TabBarView.swift +++ b/App/Tabs/TabBarView.swift @@ -37,6 +37,9 @@ class TabView: UIControl leftSeparator.backgroundColor = .secondarySystemFill rightSeparator.backgroundColor = .secondarySystemFill + imageView.contentMode = .scaleAspectFit + addSubview(imageView) + // Try just one for now leftSeparator.isHidden = true } @@ -53,9 +56,16 @@ class TabView: UIControl width: closeButtonSize.width, height: closeButtonSize.height ) + var xOffset = insetBounds.minX + imageView.frame = CGRect( + x: xOffset, y: insetBounds.minY, + width: insetBounds.height, height: insetBounds.height + ) + xOffset += imageView.frame.width + label.frame = CGRect( - x: insetBounds.minX, y: insetBounds.minY, - width: closeButton.frame.minX - closeButtonPadding, height: insetBounds.height + x: xOffset + 12.0, y: insetBounds.minY, + width: closeButton.frame.minX - closeButtonPadding - xOffset, height: insetBounds.height ) let separatorWidth = CGFloat(1.0) @@ -127,6 +137,8 @@ class TabBarView: UIView private let bottomSeparatorView = UIView(frame: .zero) + private let placeholderTabImage = UIImage(systemName: "network") + override func sizeThatFits(_ size: CGSize) -> CGSize { CGSize(width: size.width, height: Self.preferredHeight) } @@ -201,8 +213,8 @@ class TabBarView: UIView if let tabView = visibleTab(atIndex: index) { tabView.label.text = title - tabView.imageView.image = image tabView.identifier = identifier + tabView.imageView.image = image ?? placeholderTabImage } } diff --git a/SBrowser.xcodeproj/xcshareddata/xcschemes/App.xcscheme b/SBrowser.xcodeproj/xcshareddata/xcschemes/App.xcscheme index 6bec367..5a4b271 100644 --- a/SBrowser.xcodeproj/xcshareddata/xcschemes/App.xcscheme +++ b/SBrowser.xcodeproj/xcshareddata/xcschemes/App.xcscheme @@ -1,7 +1,7 @@ + version = "1.7"> @@ -40,8 +40,7 @@ debugDocumentVersioning = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES" - internalIOSLaunchStyle = "2" - viewDebuggingEnabled = "No"> + internalIOSLaunchStyle = "2">