Feature: Adds open in background (Shift+Cmd)

This commit is contained in:
James Magahern
2022-02-21 16:01:01 -08:00
parent 224a39b64f
commit f32c246e35
6 changed files with 86 additions and 32 deletions

View File

@@ -7,12 +7,18 @@
import Foundation
protocol TabControllerDelegate: AnyObject {
func tabController(_ controller: TabController, didUpdateTitle: String, forTab: Tab)
func tabController(_ controller: TabController, didUpdateFavicon: UIImage?, forTab: Tab)
}
class TabController
{
@Published var tabs: [Tab] = []
@Published var activeTabIndex: Int = 0
var policyManager = ResourcePolicyManager()
weak var controllerDelegate: TabControllerDelegate?
init() {
// TODO: load tabs from disk.
@@ -39,6 +45,20 @@ class TabController
tabs.append(tab)
}
// Title observation
tab.titleObservation = tab.webView.observe(\.title, changeHandler: { [weak tab, weak self] (webView, change) in
if let tab = tab, let self = self, let delegate = self.controllerDelegate {
delegate.tabController(self, didUpdateTitle: webView.title ?? "", forTab: tab)
}
})
// Favicon Observation
tab.faviconObservation = tab.$favicon.receive(on: RunLoop.main).sink { [weak tab, weak self] val in
if let tab = tab, let self = self, let delegate = self.controllerDelegate {
delegate.tabController(self, didUpdateFavicon: val, forTab: tab)
}
}
return tab
}