gemenon

[ACTIVE] The Safari of the Gemini ecosystem
git clone git://git.figbert.com/gemenon.git
Log | Files | Refs

commit b0f0420d9763ff6d21a41755e1b1ecd82ee08afe
parent 8d48116b5b3d9032a11e4aaf2adc60e997395f28
Author: FIGBERT <figbert@figbert.com>
Date:   Fri,  9 Sep 2022 11:22:16 -0700

Move openURL to BrowserData extension

Diffstat:
MShared/BrowserFunctions.swift | 16++++++++++++++++
MShared/ContentView.swift | 19+++----------------
2 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/Shared/BrowserFunctions.swift b/Shared/BrowserFunctions.swift @@ -9,6 +9,7 @@ import Foundation import SwiftGemini import SwiftGemtext +@MainActor class BrowserData: ObservableObject { @Published var url: String = "" @@ -35,6 +36,21 @@ extension BrowserData { } } +extension BrowserData { + func openURL(_ url: URL) async { + var uuid = UUID() + let response = try! await self.engine.request(url) + if self.tabs.count == 1 { + uuid = self.tabs.keys.first! + } + self.tabs[uuid] = response + self.currentTab = uuid + self.history[Date.now] = url + self.currentView = .Capsule + self.url = url.absoluteString + } +} + enum GemenonView { case Capsule case History diff --git a/Shared/ContentView.swift b/Shared/ContentView.swift @@ -62,14 +62,14 @@ struct ContentView: View { components.scheme = "gemini" } if let url = components.url { - await openURL(url) + await data.openURL(url) } } } else { var components = URLComponents(string: "gemini://geminispace.info/search") components?.query = data.url if let url = components?.url { - await openURL(url) + await data.openURL(url) } } } @@ -85,22 +85,9 @@ struct ContentView: View { } .handlesExternalEvents(preferring: ["gemini://*"], allowing: ["*"]) .onOpenURL(perform: { url in - Task { await openURL(url) } + Task { await data.openURL(url) } }) } - - func openURL(_ url: URL) async { - var uuid = UUID() - let response = try! await data.engine.request(url) - if data.tabs.count == 1 { - uuid = data.tabs.keys.first! - } - data.tabs[uuid] = response - data.currentTab = uuid - data.history[Date.now] = url - data.currentView = .Capsule - data.url = url.absoluteString - } } struct ContentView_Previews: PreviewProvider {