chore(ios): remaining patch-up

This commit is contained in:
jahorton 2022-06-24 09:48:30 +07:00
parent 71bd07d381
commit c8dbf3813e
2 changed files with 10 additions and 6 deletions

View file

@ -62,7 +62,12 @@ class BookmarksViewController: UIViewController, UITableViewDelegate, UITableVie
selector: #selector(BookmarksViewController.handleTextFieldTextChangedNotification(notification:)),
name: UITextField.textDidChangeNotification, object: textField)
textField.placeholder = "Title"
textField.text = self.webBrowser?.webView?.stringByEvaluatingJavaScript(from: "document.title")
self.webBrowser?.webView?.evaluateJavaScript("document.title") { val, _ in
if let str = val as? String {
textField.text = str
self.updateAddButtonEnableState()
}
}
textField.autocapitalizationType = .sentences
textField.font = UIFont.systemFont(ofSize: 17)
textField.keyboardType = .default
@ -75,7 +80,7 @@ class BookmarksViewController: UIViewController, UITableViewDelegate, UITableVie
selector: #selector(BookmarksViewController.handleTextFieldTextChangedNotification(notification:)),
name: UITextField.textDidChangeNotification, object: textField)
textField.placeholder = "URL"
textField.text = self.webBrowser?.webView?.request?.mainDocumentURL?.absoluteString
textField.text = self.webBrowser?.webView?.url?.absoluteString
textField.autocapitalizationType = .none
textField.font = UIFont.systemFont(ofSize: 17)
textField.keyboardType = UIKeyboardType.URL
@ -186,7 +191,7 @@ class BookmarksViewController: UIViewController, UITableViewDelegate, UITableVie
private func performAction(for indexPath: IndexPath) {
let bookmark = bookmarks[indexPath.section]
if let urlString = bookmark[bookmarkUrlKey], let url = URL(string: urlString) {
webBrowser?.webView?.loadRequest(URLRequest(url: url))
webBrowser?.webView?.load(URLRequest(url: url))
}
dismiss(animated: true, completion: nil)
}

View file

@ -52,7 +52,6 @@ class WebBrowserViewController: UIViewController, WKNavigationDelegate, UIAlertV
function: WebBrowserViewController.keyboardPickerDismissed)
webView.navigationDelegate = self
webView.scalesPageToFit = true
if #available(iOS 13.0, *) {
// Dark mode settings must be applied through this new property,
@ -203,7 +202,7 @@ class WebBrowserViewController: UIViewController, WKNavigationDelegate, UIAlertV
func webView(_ webView: WKWebView,
decidePolicyFor navigationAction: WKNavigationAction,
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) -> Void {
decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
let request = navigationAction.request
if request.url?.lastPathComponent.hasSuffix(".kmp") ?? false {
// Can't have the browser auto-download with no way to select a different page.
@ -292,7 +291,7 @@ class WebBrowserViewController: UIViewController, WKNavigationDelegate, UIAlertV
"style.type = 'text/css';" +
"style.innerHTML = '*{font-family:\"\(fontFamily)\" !important;}';" +
"document.getElementsByTagName('head')[0].appendChild(style);"
webView?.stringByEvaluatingJavaScript(from: jsStr)
webView.evaluateJavaScript(jsStr)
}
private func keyboardChanged(_ kb: InstallableKeyboard) {