Feature: Adds open in background (Shift+Cmd)
This commit is contained in:
@@ -26,14 +26,13 @@ class BrowserViewController: UIViewController
|
||||
|
||||
override var canBecomeFirstResponder: Bool { true }
|
||||
|
||||
private var titleObservation: NSKeyValueObservation?
|
||||
private var loadingObservation: NSKeyValueObservation?
|
||||
private var backButtonObservation: NSKeyValueObservation?
|
||||
private var forwardButtonObservation: NSKeyValueObservation?
|
||||
private var hasSecureContentObservation: NSKeyValueObservation?
|
||||
private var activeTabObservation: AnyCancellable?
|
||||
private var faviconObservation: AnyCancellable?
|
||||
|
||||
internal var shiftKeyHeld: Bool = false
|
||||
internal var commandKeyHeld: Bool = false
|
||||
internal var windowButtonHeld: Bool {
|
||||
get { toolbarController.newTabButton.isTracking }
|
||||
@@ -65,6 +64,8 @@ class BrowserViewController: UIViewController
|
||||
self.tabBarViewController = TabBarViewController(tabController: tabController)
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
|
||||
self.tabController.controllerDelegate = self
|
||||
|
||||
addChild(toolbarController)
|
||||
addChild(findOnPageController)
|
||||
addChild(tabBarViewController)
|
||||
@@ -168,11 +169,11 @@ class BrowserViewController: UIViewController
|
||||
alert.dismiss(animated: true, completion: nil)
|
||||
}))
|
||||
|
||||
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in
|
||||
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { [unowned self] _ in
|
||||
alert.dismiss(animated: true, completion: nil)
|
||||
|
||||
// Clears out the error state
|
||||
toolbarController.urlBar.loadProgress = .complete
|
||||
self.toolbarController.urlBar.loadProgress = .complete
|
||||
}))
|
||||
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
@@ -247,13 +248,13 @@ class BrowserViewController: UIViewController
|
||||
DispatchQueue.main.async {
|
||||
documentControls.dismiss(animated: true, completion: nil)
|
||||
|
||||
let readableViewController = ReaderViewController(readableHTMLString: string, baseURL: tab.bridge.webView.url)
|
||||
readableViewController.title = tab.bridge.webView.title
|
||||
readableViewController.darkModeEnabled = tab.bridge.darkModeEnabled
|
||||
let readableViewController = ReaderViewController(readableHTMLString: string, baseURL: self.tab.bridge.webView.url)
|
||||
readableViewController.title = self.tab.bridge.webView.title
|
||||
readableViewController.darkModeEnabled = self.tab.bridge.darkModeEnabled
|
||||
readableViewController.delegate = self
|
||||
|
||||
let navigationController = UINavigationController(rootViewController: readableViewController)
|
||||
present(navigationController, animated: true, completion: nil)
|
||||
self.present(navigationController, animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
}, for: .touchUpInside)
|
||||
@@ -310,12 +311,16 @@ class BrowserViewController: UIViewController
|
||||
}
|
||||
|
||||
// Show tab bar view?
|
||||
browserView.tabBarViewVisible = tabController.tabs.count > 1
|
||||
self.updateTabBarVisibility()
|
||||
})
|
||||
|
||||
self.view = browserView
|
||||
}
|
||||
|
||||
internal func updateTabBarVisibility() {
|
||||
browserView.tabBarViewVisible = tabController.tabs.count > 1
|
||||
}
|
||||
|
||||
internal func showShareSheetForCurrentURL(fromViewController: UIViewController?) {
|
||||
guard let url = self.webView.url else { return }
|
||||
|
||||
@@ -455,9 +460,6 @@ class BrowserViewController: UIViewController
|
||||
|
||||
// Title observer
|
||||
updateTitleAndURL(forWebView: webView)
|
||||
titleObservation = webView.observe(\.title, changeHandler: { [unowned self] (webView, observedChange) in
|
||||
self.updateTitleAndURL(forWebView: webView)
|
||||
})
|
||||
|
||||
// Back/forward observer
|
||||
toolbarController.backButton.isEnabled = webView.canGoBack
|
||||
@@ -476,12 +478,6 @@ class BrowserViewController: UIViewController
|
||||
browserView.titlebarView.showsSecurityIndicator = webView.hasOnlySecureContent
|
||||
})
|
||||
|
||||
// Favicon observation
|
||||
faviconObservation = tab.$favicon.receive(on: DispatchQueue.main)
|
||||
.sink { [unowned self] _ in
|
||||
updateTitleAndURL(forWebView: webView)
|
||||
}
|
||||
|
||||
// Script blocker button
|
||||
updateScriptBlockerButton()
|
||||
|
||||
@@ -527,13 +523,26 @@ class BrowserViewController: UIViewController
|
||||
iconView.isEnabled = (webView.url != nil)
|
||||
}
|
||||
|
||||
public func createNewTab(withURL url: URL?) {
|
||||
@discardableResult
|
||||
public func createNewTab(withURL url: URL?, loadInBackground: Bool = false) -> Tab {
|
||||
let newTab = tabController.createNewTab(url: url)
|
||||
self.tab = newTab
|
||||
|
||||
if url == nil && traitCollection.userInterfaceIdiom == .mac {
|
||||
self.toolbarController.urlBar.textField.becomeFirstResponder()
|
||||
if !loadInBackground {
|
||||
self.tab = newTab
|
||||
|
||||
if url == nil && traitCollection.userInterfaceIdiom == .mac {
|
||||
self.toolbarController.urlBar.textField.becomeFirstResponder()
|
||||
}
|
||||
} else {
|
||||
// Send this message to get it to load NOW, instead of waiting for it to show up
|
||||
// in the view hierarchy.
|
||||
tab.webView.didMoveToWindow()
|
||||
|
||||
// Update tab bar now
|
||||
updateTabBarVisibility()
|
||||
}
|
||||
|
||||
return newTab
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,3 +670,19 @@ extension BrowserViewController: MFMailComposeViewControllerDelegate
|
||||
controller.dismiss(animated: true, completion: nil)
|
||||
}
|
||||
}
|
||||
|
||||
extension BrowserViewController: TabControllerDelegate
|
||||
{
|
||||
func tabController(_ controller: TabController, didUpdateTitle: String, forTab tab: Tab) {
|
||||
updateTitleAndURL(forWebView: tab.webView)
|
||||
|
||||
// Fetch favicon in background, if applicable
|
||||
if tab.favicon == nil, let url = tab.webView.url {
|
||||
tab.updateFaviconForURL(url)
|
||||
}
|
||||
}
|
||||
|
||||
func tabController(_ controller: TabController, didUpdateFavicon: UIImage?, forTab tab: Tab) {
|
||||
updateTitleAndURL(forWebView: tab.webView)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user