Add preference to turn off link icons
This commit is contained in:
parent
6a8c5b56fe
commit
8183e6986a
|
@ -12,6 +12,7 @@ import GeminiProtocol
|
|||
import GeminiFormat
|
||||
import GeminiRenderer
|
||||
import SafariServices
|
||||
import Combine
|
||||
|
||||
class BrowserWebViewController: UIViewController {
|
||||
|
||||
|
@ -32,6 +33,8 @@ class BrowserWebViewController: UIViewController {
|
|||
private var loaded = false
|
||||
private var loadedFallback = false
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
private var errorStack: UIStackView!
|
||||
private var errorMessageLabel: UILabel!
|
||||
private var activityIndicator: UIActivityIndicatorView!
|
||||
|
@ -51,25 +54,7 @@ class BrowserWebViewController: UIViewController {
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
let documentURL = self.url
|
||||
renderer.linkPrefix = { (url: URL) -> String in
|
||||
let symbolClass: String
|
||||
if url.scheme == "gemini" {
|
||||
if url.host == documentURL.host {
|
||||
symbolClass = "arrow-right"
|
||||
} else {
|
||||
symbolClass = "link"
|
||||
}
|
||||
} else if url.scheme == "http" || url.scheme == "https" {
|
||||
symbolClass = "safari"
|
||||
} else if url.scheme == "mailto" {
|
||||
symbolClass = "envelope"
|
||||
} else {
|
||||
symbolClass = "arrow-up-left-square"
|
||||
}
|
||||
return "<span class=\"symbol \(symbolClass)\" aria-hidden=\"true\"></span>"
|
||||
|
||||
}
|
||||
configureRenderer()
|
||||
|
||||
view.backgroundColor = .systemBackground
|
||||
|
||||
|
@ -122,6 +107,14 @@ class BrowserWebViewController: UIViewController {
|
|||
activityIndicator.centerXAnchor.constraint(equalTo: view.centerXAnchor),
|
||||
activityIndicator.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
||||
])
|
||||
|
||||
Preferences.shared.$showLinkIcons
|
||||
.sink { [weak self] newVal in
|
||||
guard let self = self, let doc = self.document else { return }
|
||||
self.configureRenderer(showLinkIcons: newVal)
|
||||
self.renderDocument(doc)
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
|
@ -130,6 +123,31 @@ class BrowserWebViewController: UIViewController {
|
|||
loadDocument()
|
||||
}
|
||||
|
||||
private func configureRenderer(showLinkIcons: Bool = Preferences.shared.showLinkIcons) {
|
||||
if showLinkIcons {
|
||||
let documentURL = self.url
|
||||
renderer.linkPrefix = { (url: URL) -> String in
|
||||
let symbolClass: String
|
||||
if url.scheme == "gemini" {
|
||||
if url.host == documentURL.host {
|
||||
symbolClass = "arrow-right"
|
||||
} else {
|
||||
symbolClass = "link"
|
||||
}
|
||||
} else if url.scheme == "http" || url.scheme == "https" {
|
||||
symbolClass = "safari"
|
||||
} else if url.scheme == "mailto" {
|
||||
symbolClass = "envelope"
|
||||
} else {
|
||||
symbolClass = "arrow-up-left-square"
|
||||
}
|
||||
return "<span class=\"symbol \(symbolClass)\" aria-hidden=\"true\"></span>"
|
||||
}
|
||||
} else {
|
||||
renderer.linkPrefix = nil
|
||||
}
|
||||
}
|
||||
|
||||
func reload() {
|
||||
loaded = false
|
||||
loadedFallback = false
|
||||
|
|
|
@ -35,6 +35,9 @@ class Preferences: Codable, ObservableObject {
|
|||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
theme = try container.decode(UIUserInterfaceStyle.self, forKey: .theme)
|
||||
if let stored = try container.decodeIfPresent(Bool.self, forKey: .showLinkIcons) {
|
||||
showLinkIcons = stored
|
||||
}
|
||||
|
||||
useInAppSafari = try container.decode(Bool.self, forKey: .useInAppSafari)
|
||||
useReaderMode = try container.decode(Bool.self, forKey: .useReaderMode)
|
||||
|
@ -44,18 +47,21 @@ class Preferences: Codable, ObservableObject {
|
|||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
try container.encode(theme, forKey: .theme)
|
||||
try container.encode(showLinkIcons, forKey: .showLinkIcons)
|
||||
|
||||
try container.encode(useInAppSafari, forKey: .useInAppSafari)
|
||||
try container.encode(useReaderMode, forKey: .useReaderMode)
|
||||
}
|
||||
|
||||
@Published var theme = UIUserInterfaceStyle.unspecified
|
||||
@Published var showLinkIcons = true
|
||||
|
||||
@Published var useInAppSafari = false
|
||||
@Published var useReaderMode = false
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case theme
|
||||
case showLinkIcons
|
||||
|
||||
case useInAppSafari
|
||||
case useReaderMode
|
||||
|
|
|
@ -45,6 +45,8 @@ struct PreferencesView: View {
|
|||
Text("Always Light").tag(UIUserInterfaceStyle.light)
|
||||
Text("Always Dark").tag(UIUserInterfaceStyle.dark)
|
||||
}
|
||||
|
||||
Toggle("Show Link Icons", isOn: $preferences.showLinkIcons)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue