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