feat: added settings
1ddd72a7
3 file(s) · +76 −8
| 23 | 23 | ||
| 24 | 24 | /// The color used for toolbar buttons (navigation, menu, etc.) |
|
| 25 | 25 | @Published var toolbarButtonColor: Color = .blue |
|
| 26 | + | ||
| 27 | + | /// The home page URL that the browser navigates to on launch and when pressing Home |
|
| 28 | + | @AppStorage("homePage") var homePage: String = "gemini://geminiprotocol.net/" |
|
| 26 | 29 | } |
|
| 27 | 30 | ||
| 28 | 31 | // MARK: - Environment Key |
| 28 | 28 | } |
|
| 29 | 29 | ||
| 30 | 30 | struct ContentView: View { |
|
| 31 | - | private let homeSite = "gemini://geminiprotocol.net/" |
|
| 32 | - | ||
| 33 | 31 | @Environment(\.themeSettings) private var themeSettings |
|
| 34 | 32 | @State private var urlText = "" |
|
| 35 | 33 | @State private var responseText = "" |
|
| 56 | 54 | // Bookmarks |
|
| 57 | 55 | @State private var bookmarkManager = BookmarkManager() |
|
| 58 | 56 | @State private var showBookmarks = false |
|
| 57 | + | ||
| 58 | + | // Settings |
|
| 59 | + | @State private var showSettings = false |
|
| 59 | 60 | ||
| 60 | 61 | private let maxRedirects = 5 |
|
| 61 | 62 | ||
| 122 | 123 | .glassEffect(.regular, in: .capsule) |
|
| 123 | 124 | ||
| 124 | 125 | Menu { |
|
| 126 | + | ||
| 125 | 127 | Button { |
|
| 126 | - | navigateTo(homeSite) |
|
| 128 | + | showSettings = true |
|
| 127 | 129 | } label: { |
|
| 128 | - | Label("Home", systemImage: "house") |
|
| 130 | + | Label("Settings", systemImage: "gear") |
|
| 129 | 131 | } |
|
| 130 | - | ||
| 132 | + | ||
| 131 | 133 | Divider() |
|
| 132 | 134 | ||
| 133 | 135 | Button { |
|
| 136 | + | showBookmarks = true |
|
| 137 | + | } label: { |
|
| 138 | + | Label("Bookmarks", systemImage: "book") |
|
| 139 | + | } |
|
| 140 | + | ||
| 141 | + | Button { |
|
| 134 | 142 | addCurrentPageToBookmarks() |
|
| 135 | 143 | } label: { |
|
| 136 | 144 | if bookmarkManager.isBookmarked(url: urlText) { |
|
| 141 | 149 | } |
|
| 142 | 150 | .disabled(urlText.isEmpty || bookmarkManager.isBookmarked(url: urlText)) |
|
| 143 | 151 | ||
| 152 | + | Divider() |
|
| 153 | + | ||
| 144 | 154 | Button { |
|
| 145 | - | showBookmarks = true |
|
| 155 | + | navigateTo(themeSettings.homePage) |
|
| 146 | 156 | } label: { |
|
| 147 | - | Label("Bookmarks", systemImage: "book") |
|
| 157 | + | Label("Home", systemImage: "house") |
|
| 148 | 158 | } |
|
| 149 | 159 | } label: { |
|
| 150 | 160 | Image(systemName: "ellipsis.circle") |
|
| 162 | 172 | } |
|
| 163 | 173 | } |
|
| 164 | 174 | .onAppear { |
|
| 165 | - | navigateTo(homeSite) |
|
| 175 | + | navigateTo(themeSettings.homePage) |
|
| 166 | 176 | } |
|
| 167 | 177 | .alert("Input Required", isPresented: $showInputPrompt) { |
|
| 168 | 178 | if inputIsSensitive { |
|
| 192 | 202 | showBookmarks = false |
|
| 193 | 203 | navigateTo(bookmark.url) |
|
| 194 | 204 | } |
|
| 205 | + | } |
|
| 206 | + | .sheet(isPresented: $showSettings) { |
|
| 207 | + | SettingsView() |
|
| 195 | 208 | } |
|
| 196 | 209 | } |
|
| 197 | 210 | ||
| 1 | + | // |
|
| 2 | + | // SettingsView.swift |
|
| 3 | + | // Titan |
|
| 4 | + | // |
|
| 5 | + | ||
| 6 | + | import SwiftUI |
|
| 7 | + | ||
| 8 | + | struct SettingsView: View { |
|
| 9 | + | @Environment(\.themeSettings) private var themeSettings |
|
| 10 | + | @Environment(\.dismiss) private var dismiss |
|
| 11 | + | ||
| 12 | + | @State private var homePageText: String = "" |
|
| 13 | + | ||
| 14 | + | var body: some View { |
|
| 15 | + | NavigationStack { |
|
| 16 | + | Form { |
|
| 17 | + | Section { |
|
| 18 | + | TextField("Home Page URL", text: $homePageText) |
|
| 19 | + | .autocapitalization(.none) |
|
| 20 | + | .disableAutocorrection(true) |
|
| 21 | + | .keyboardType(.URL) |
|
| 22 | + | } header: { |
|
| 23 | + | Text("Home Page") |
|
| 24 | + | } footer: { |
|
| 25 | + | Text("The page that loads when you open the app or tap the Home button.") |
|
| 26 | + | } |
|
| 27 | + | } |
|
| 28 | + | .navigationTitle("Settings") |
|
| 29 | + | .navigationBarTitleDisplayMode(.inline) |
|
| 30 | + | .toolbar { |
|
| 31 | + | ToolbarItem(placement: .cancellationAction) { |
|
| 32 | + | Button("Cancel") { |
|
| 33 | + | dismiss() |
|
| 34 | + | } |
|
| 35 | + | } |
|
| 36 | + | ToolbarItem(placement: .confirmationAction) { |
|
| 37 | + | Button("Save") { |
|
| 38 | + | themeSettings.homePage = homePageText |
|
| 39 | + | dismiss() |
|
| 40 | + | } |
|
| 41 | + | } |
|
| 42 | + | } |
|
| 43 | + | .onAppear { |
|
| 44 | + | homePageText = themeSettings.homePage |
|
| 45 | + | } |
|
| 46 | + | } |
|
| 47 | + | } |
|
| 48 | + | } |
|
| 49 | + | ||
| 50 | + | #Preview { |
|
| 51 | + | SettingsView() |
|
| 52 | + | } |