commit 8d48116b5b3d9032a11e4aaf2adc60e997395f28
parent abf6031196d61268bb218bbdd0c2794d5060c2f5
Author: FIGBERT <figbert@figbert.com>
Date: Thu, 8 Sep 2022 22:14:20 -0700
Add home button to toolbar
Diffstat:
3 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/Shared/BrowserFunctions.swift b/Shared/BrowserFunctions.swift
@@ -14,8 +14,8 @@ class BrowserData: ObservableObject {
@Published var history: [Date: URL] = [:]
- @Published var tabs: [UUID: SwiftGemini.GeminiResponse] = [:]
- @Published var currentTab: UUID? = nil
+ @Published var tabs: [UUID: SwiftGemini.GeminiResponse?] = [:]
+ @Published var currentTab: UUID? = nil // tabs.isEmpty => nil
@Published var currentView: GemenonView = .Capsule
@Published var views: [GemenonView] = [.Capsule, .History]
@@ -24,6 +24,17 @@ class BrowserData: ObservableObject {
@Published var engine = SwiftGemini.GeminiRequestor()
}
+extension BrowserData {
+ func goToStartPage() {
+ guard self.currentTab != nil else { return }
+ self.tabs[self.currentTab!] = nil
+ self.url = ""
+ }
+ func showStartPage() -> Bool {
+ return self.tabs.isEmpty || self.tabs[self.currentTab!] == nil
+ }
+}
+
enum GemenonView {
case Capsule
case History
diff --git a/Shared/CapsuleView.swift b/Shared/CapsuleView.swift
@@ -17,9 +17,9 @@ struct CapsuleView: View {
ScrollView {
HStack {
Spacer()
- if data.tabs[data.currentTab!]?.body?.gemtext != nil {
+ if data.tabs[data.currentTab!]??.body?.gemtext != nil {
VStack(alignment: .leading, spacing: 10) {
- renderGemtext((data.tabs[data.currentTab!]?.body?.gemtext)!, url: (data.tabs[data.currentTab!]?.url)!)
+ renderGemtext((data.tabs[data.currentTab!]??.body?.gemtext)!, url: (data.tabs[data.currentTab!]??.url)!)
}
}
Spacer()
diff --git a/Shared/ContentView.swift b/Shared/ContentView.swift
@@ -26,7 +26,7 @@ struct ContentView: View {
switch s {
case .Capsule:
if data.tabs.isEmpty {
- Label("Start Page", systemImage: "house")
+ Label("Start Page", systemImage: "laptopcomputer")
} else {
Label("\(data.tabs.count) Tab\(data.tabs.count > 1 ? "s" : "")", systemImage: "laptopcomputer")
}
@@ -75,6 +75,13 @@ struct ContentView: View {
}
}
}
+ ToolbarItem(placement: .navigation) {
+ Button(action: {
+ data.goToStartPage()
+ }) {
+ Image(systemName: "house")
+ }
+ }
}
.handlesExternalEvents(preferring: ["gemini://*"], allowing: ["*"])
.onOpenURL(perform: { url in