Use gemini:// as default protocol for typed URLs

This commit is contained in:
Shadowfacts 2020-09-28 15:27:19 -04:00
parent b174a26d1c
commit cea2076244
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 20 additions and 12 deletions

View File

@ -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)