Use gemini:// as default protocol for typed URLs
This commit is contained in:
parent
b174a26d1c
commit
cea2076244
|
@ -24,13 +24,29 @@ public class NavigationManager: NSObject, ObservableObject {
|
|||
}
|
||||
|
||||
public func changeURL(_ url: URL) {
|
||||
guard url.scheme == "gemini" else {
|
||||
delegate?.loadNonGeminiURL(url)
|
||||
return
|
||||
var components = URLComponents(url: url, resolvingAgainstBaseURL: false)!
|
||||
if let scheme = url.scheme {
|
||||
if scheme != "gemini" {
|
||||
delegate?.loadNonGeminiURL(url)
|
||||
return
|
||||
}
|
||||
if components.port == 1965 {
|
||||
components.port = nil
|
||||
}
|
||||
} else {
|
||||
components.scheme = "gemini"
|
||||
}
|
||||
|
||||
// Foundation parses bare hosts (e.g. `example.com`) as having no host and a path of `example.com`
|
||||
if components.host == nil {
|
||||
components.host = components.path
|
||||
components.path = "/"
|
||||
}
|
||||
|
||||
let url = components.url!
|
||||
|
||||
backStack.append(currentURL)
|
||||
currentURL = cannonicalizeURL(url)
|
||||
currentURL = url
|
||||
forwardStack = []
|
||||
}
|
||||
|
||||
|
@ -39,14 +55,6 @@ public class NavigationManager: NSObject, ObservableObject {
|
|||
currentURL = url
|
||||
}
|
||||
|
||||
private func cannonicalizeURL(_ url: URL) -> URL {
|
||||
var components = URLComponents(url: url, resolvingAgainstBaseURL: false)!
|
||||
if components.scheme == "gemini" && components.port == 1965 {
|
||||
components.port = nil
|
||||
}
|
||||
return components.url!
|
||||
}
|
||||
|
||||
@objc public func back() {
|
||||
guard !backStack.isEmpty else { return }
|
||||
forwardStack.insert(currentURL, at: 0)
|
||||
|
|
Loading…
Reference in New Issue