Adds reader mode shortcut (cmd+shift+R)
This commit is contained in:
@@ -159,4 +159,8 @@ extension BrowserViewController: ShortcutResponder
|
||||
func toggleDarkMode(_ sender: Any?) {
|
||||
self.darkModeEnabled = !self.darkModeEnabled
|
||||
}
|
||||
|
||||
func openInReaderMode(_ sender: Any?) {
|
||||
showReaderWindow()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -295,32 +295,8 @@ class BrowserViewController: UIViewController
|
||||
|
||||
// Reader mode
|
||||
documentControls.readabilityView.addAction(UIAction { [unowned self] _ in
|
||||
tab.bridge.parseDocumentForReaderMode { string in
|
||||
DispatchQueue.main.async {
|
||||
documentControls.dismiss(animated: true, completion: nil)
|
||||
|
||||
if self.traitCollection.userInterfaceIdiom == .phone {
|
||||
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)
|
||||
self.present(navigationController, animated: true, completion: nil)
|
||||
} else {
|
||||
let userActivity = NSUserActivity(activityType: SessionActivityType.ReaderWindow.rawValue)
|
||||
userActivity.title = self.tab.title
|
||||
userActivity.userInfo = [
|
||||
ReaderUserActivityKeys.baseURL.rawValue : self.tab.bridge.webView.url ?? NSNull(),
|
||||
ReaderUserActivityKeys.htmlString.rawValue : string,
|
||||
]
|
||||
let requestOptions = UIWindowScene.ActivationRequestOptions()
|
||||
requestOptions.preferredPresentationStyle = .prominent
|
||||
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: userActivity, options: requestOptions)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
documentControls.dismiss(animated: true, completion: nil)
|
||||
showReaderWindow()
|
||||
}, for: .touchUpInside)
|
||||
|
||||
// Archive
|
||||
@@ -459,6 +435,32 @@ class BrowserViewController: UIViewController
|
||||
#endif
|
||||
}
|
||||
|
||||
internal func showReaderWindow() {
|
||||
tab.bridge.parseDocumentForReaderMode { string in
|
||||
DispatchQueue.main.async {
|
||||
if self.traitCollection.userInterfaceIdiom == .phone {
|
||||
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)
|
||||
self.present(navigationController, animated: true, completion: nil)
|
||||
} else {
|
||||
let userActivity = NSUserActivity(activityType: SessionActivityType.ReaderWindow.rawValue)
|
||||
userActivity.title = self.tab.title
|
||||
userActivity.userInfo = [
|
||||
ReaderUserActivityKeys.baseURL.rawValue : self.tab.bridge.webView.url ?? NSNull(),
|
||||
ReaderUserActivityKeys.htmlString.rawValue : string,
|
||||
]
|
||||
let requestOptions = UIWindowScene.ActivationRequestOptions()
|
||||
requestOptions.preferredPresentationStyle = .prominent
|
||||
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: userActivity, options: requestOptions)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal func updateLoadProgress(forWebView webView: WKWebView) {
|
||||
if let loadError = tab.loadError {
|
||||
toolbarController.urlBar.loadProgress = .error(error: loadError)
|
||||
|
||||
@@ -47,6 +47,9 @@ protocol ShortcutResponder: AnyObject {
|
||||
|
||||
@objc
|
||||
optional func toggleDarkMode(_ sender: Any?)
|
||||
|
||||
@objc
|
||||
optional func openInReaderMode(_ sender: Any?)
|
||||
}
|
||||
|
||||
fileprivate extension Array {
|
||||
@@ -88,6 +91,13 @@ public class KeyboardShortcuts {
|
||||
action: #selector(ShortcutResponder.focusURLBar)
|
||||
),
|
||||
|
||||
// Open in Reader
|
||||
UIKeyCommand(
|
||||
modifiers: [ .command, .shift ], input: "R",
|
||||
title: "Open in Reader Mode…",
|
||||
action: #selector(ShortcutResponder.openInReaderMode)
|
||||
),
|
||||
|
||||
// Tabs
|
||||
UIMenu(options: .displayInline, children: [
|
||||
// Create Tab
|
||||
|
||||
@@ -49,12 +49,15 @@ class ReaderViewController: UIViewController
|
||||
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(self.didTapDoneButton))
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
bridge.webView.becomeFirstResponder()
|
||||
}
|
||||
|
||||
private func updateDarkModeButton() {
|
||||
darkModeButton.image = DarkModeControls.buttonImage(forDarkModeState: darkModeEnabled)
|
||||
}
|
||||
|
||||
@objc
|
||||
private func didTapDoneButton(_ sender: Any?) {
|
||||
private func close() {
|
||||
if traitCollection.userInterfaceIdiom == .phone {
|
||||
dismiss(animated: true, completion: nil)
|
||||
} else {
|
||||
@@ -64,6 +67,16 @@ class ReaderViewController: UIViewController
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
private func didTapDoneButton(_ sender: Any?) {
|
||||
close()
|
||||
}
|
||||
|
||||
@objc
|
||||
private func closeTab(_ sender: Any?) {
|
||||
close()
|
||||
}
|
||||
|
||||
@objc
|
||||
private func didTapDarkModeButton(_ sender: Any?) {
|
||||
darkModeEnabled = !darkModeEnabled
|
||||
|
||||
Reference in New Issue
Block a user