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

@@ -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)

View File

@@ -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

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
}