SPB Git

Repository Public

MobileSettingsView.swift 7.2 KB 122 lines swift

1import SwiftUI23struct MobileSettingsView: View {4    @Bindable var model: BrowserModel5    @Bindable var environment: MobileEnvironment6    @Environment(\.dismiss) private var dismiss7    @AppStorage("addressBarAtBottom") private var addressBarAtBottom = true8    @State private var confirmClearData = false910    private var services: BrowserServices { environment.services }1112    var body: some View {13        NavigationStack {14            Form {15                Section {16                    NavigationLink(isActive: $model.showsAccount) {17                        AccountView(services: services, syncEnabled: $environment.settings.syncEnabled).navigationTitle(L("Account")).navigationBarTitleDisplayMode(.inline)18                    } label: {19                        HStack(spacing: 12) {20                            Image(systemName: services.account.isSignedIn ? "person.crop.circle.fill.badge.checkmark" : "person.crop.circle").font(.title).foregroundStyle(SPTheme.accent)21                            VStack(alignment: .leading, spacing: 2) {22                                Text(services.account.session?.user.displayName ?? L("SP Browser account"))23                                Text(accountLine).font(.caption).foregroundStyle(.secondary)24                            }25                        }26                    }27                    .accessibilityIdentifier("settings-account")28                    Toggle(L("Synchronize this device"), isOn: $environment.settings.syncEnabled)29                }3031                Section(L("Search")) {32                    Picker(L("Search engine"), selection: $environment.settings.searchEngineID) {33                        ForEach(environment.settings.allSearchEngines()) { Text($0.name).tag($0.id) }34                    }35                    let prefs = Binding(get: { services.searchPreferences }, set: { services.searchPreferences = $0 })36                    Picker(L("Language of results"), selection: prefs.language) {37                        ForEach(SearchPreferences.languages, id: \.code) { Text($0.code.isEmpty ? L("Any language") : $0.name).tag($0.code) }38                    }39                    Picker(L("Region"), selection: prefs.region) {40                        ForEach(SearchPreferences.regions, id: \.self) { Text(SearchPreferences.regionName($0)).tag($0) }41                    }42                    Toggle(L("Safe search"), isOn: prefs.safeSearch)43                    Toggle(L("AI summary above results"), isOn: prefs.showSummary)44                    Toggle(L("Keep search history"), isOn: prefs.keepSearchHistory)45                    Button(L("Clear Search History"), role: .destructive) { services.clearSearchData(); model.toast = L("Search history cleared") }46                }4748                Section(L("Appearance")) {49                    Picker(L("Theme"), selection: $environment.settings.appearance) {50                        Text(L("System")).tag(AppearanceMode.system)51                        Text(L("Light")).tag(AppearanceMode.light)52                        Text(L("Dark")).tag(AppearanceMode.dark)53                    }54                    Picker(L("Address bar"), selection: $addressBarAtBottom) {55                        Text(L("Bottom")).tag(true)56                        Text(L("Top")).tag(false)57                    }58                    .accessibilityIdentifier("address-bar-position")59                    VStack(alignment: .leading, spacing: 8) {60                        Text(L("Start page ambience"))61                        ScrollView(.horizontal, showsIndicators: false) {62                            HStack(spacing: 12) {63                                ForEach(AmbientTheme.allCases) { theme in64                                    Button { AuraHaptics.play(.selection); environment.settings.startPage.ambient = theme } label: {65                                        AmbientThemeSwatch(theme: theme, isSelected: environment.settings.startPage.ambient == theme)66                                    }67                                    .buttonStyle(AuraPressStyle(scale: 0.95))68                                    .accessibilityIdentifier("ambient-" + theme.rawValue)69                                }70                            }71                            .padding(.vertical, 2)72                        }73                        Text(environment.settings.startPage.ambient.summary).font(.caption).foregroundStyle(.secondary)74                    }75                    .padding(.vertical, 4)76                    Toggle(L("Animate the background"), isOn: $environment.settings.ambientMotionEnabled)77                    Toggle(L("Focus Trail"), isOn: $environment.settings.focusTrailEnabled)78                    Toggle(L("Hide browser notices in Focus Mode"), isOn: $environment.settings.focusHidesDistractions)79                    Toggle(L("Record my path (Flow)"), isOn: $environment.settings.flowEnabled)80                }8182                Section(L("Browsing")) {83                    Toggle(L("Reopen tabs at launch"), isOn: $environment.settings.restoreSessionOnLaunch)84                    Toggle(L("Upgrade connections to HTTPS"), isOn: $environment.settings.upgradeToHTTPS)85                    Toggle(L("Suggest from history"), isOn: $environment.settings.suggestFromHistory)86                    Toggle(L("Suggest from bookmarks"), isOn: $environment.settings.suggestFromBookmarks)87                }8889                Section(L("Privacy")) {90                    Button(L("Clear History…")) { dismiss(); model.library = .history }91                    Button(L("Clear Cookies and Website Data…"), role: .destructive) { confirmClearData = true }92                    Text(L("SP Browser sends no telemetry. Private tabs keep nothing and are never synchronized."))93                        .font(.caption).foregroundStyle(.secondary)94                }9596                Section {97                    LabeledContent(L("Version"), value: "\(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "") (\(Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? ""))")98                }99            }100            .navigationTitle(L("Settings"))101            .navigationBarTitleDisplayMode(.inline)102            .toolbar { ToolbarItem(placement: .confirmationAction) { Button(L("Done")) { dismiss() }.accessibilityIdentifier("settings-done") } }103            .confirmationDialog(L("Clear cookies and website data?"), isPresented: $confirmClearData, titleVisibility: .visible) {104                Button(L("Clear"), role: .destructive) { Task { await environment.clearWebsiteData(); model.toast = L("Website data cleared") } }105                Button(L("Cancel"), role: .cancel) {}106            } message: { Text(L("You will be signed out of websites.")) }107        }108    }109110    private var accountLine: String {111        guard services.account.isSignedIn else { return L("Sign in to synchronize your devices") }112        switch services.sync.phase {113        case .off: return L("Synchronization is off")114        case .waitingForKey: return L("Waiting for approval")115        case .offline: return L("Offline — will retry")116        case .syncing: return L("Synchronizing…")117        case .failed(let message): return message118        default: return L("Synchronized, end-to-end encrypted")119        }120    }121}122
Files main
Menu

Theme