Feature: Adds open in background (Shift+Cmd)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user