Feature: Adds open in background (Shift+Cmd)
This commit is contained in:
@@ -70,8 +70,9 @@ class Tab: NSObject, SBRProcessBundleBridgeDelegate
|
||||
public var allowedScriptOrigins = Set<String>()
|
||||
public var blockedScriptOrigins = Set<String>()
|
||||
|
||||
private var titleObservation: NSKeyValueObservation?
|
||||
private var urlObservation: NSKeyValueObservation?
|
||||
public var titleObservation: NSKeyValueObservation?
|
||||
public var urlObservation: NSKeyValueObservation?
|
||||
public var faviconObservation: AnyCancellable?
|
||||
|
||||
convenience init(policyManager: ResourcePolicyManager) {
|
||||
self.init(url: nil, policyManager: policyManager, webViewConfiguration: nil)
|
||||
|
||||
@@ -30,7 +30,7 @@ class TabBarViewController: UIViewController, TabBarViewDataSource, TabBarViewDe
|
||||
tabBarView.reloadTabs()
|
||||
|
||||
tabObserver = tabController.$tabs.sink(receiveValue: { [unowned self] (newTabs: [Tab]) in
|
||||
DispatchQueue.main.async { tabBarView.reloadTabs() }
|
||||
DispatchQueue.main.async { self.tabBarView.reloadTabs() }
|
||||
})
|
||||
|
||||
activeTabIndexObserver = tabController.$activeTabIndex.sink(receiveValue: { [unowned self] (activeIndex: Int) 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