commit 147de9e3c35598ee78fdc50c5b0d911290cba28b parent 1eebf5974079770e86b7edb1a0c7059470f5c8c3 Author: FIGBERT <figbert@figbert.com> Date: Sat, 3 Sep 2022 22:13:15 -0700 Add search and gemini scheme fallback Diffstat:
M | Shared/ContentView.swift | | | 22 | +++++++++++++++++++++- |
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/Shared/ContentView.swift b/Shared/ContentView.swift @@ -44,7 +44,27 @@ struct ContentView: View { .autocorrectionDisabled(true) .onSubmit { Task { - response = try! await engine.request(URL(string: url)!) + if let url = URL(string: url) { + if var components = URLComponents(url: url, resolvingAgainstBaseURL: false) { + if components.scheme?.isEmpty ?? true { + if components.host?.isEmpty ?? true { + let index = components.path.firstIndex(of: "/") ?? components.path.endIndex + components.host = String(components.path[..<index]) + components.path = String(components.path[index...]) + } + components.scheme = "gemini" + } + if let url = components.url { + response = try! await engine.request(url) + } + } + } else { + var components = URLComponents(string: "gemini://geminispace.info/search") + components?.query = url + if let url = components?.url { + response = try! await engine.request(url) + } + } } } }