import SwiftUI enum AboutLinks { static let repository = URL(string: "https://knotless.dev/geesawra.industries/old-fella")! static let appLicense = URL(string: "https://knotless.dev/geesawra.industries/old-fella/blob/main/LICENSE")! static let atProtoKitLicense = URL(string: "https://github.com/MasterJ93/ATProtoKit/blob/0.34.1/LICENSE.md")! static let emojiKitLicense = URL(string: "https://github.com/danielsaidi/EmojiKit/blob/3.1.0/LICENSE")! static let swiftLogLicense = URL(string: "https://github.com/apple/swift-log/blob/1.16.2/LICENSE.txt")! static let swiftLogNotice = URL(string: "https://github.com/apple/swift-log/blob/1.16.2/NOTICE.txt")! } #if DEBUG #Preview("Open source licenses") { NavigationStack { OpenSourceLicensesView() } } #endif struct OpenSourceLicensesView: View { var body: some View { List { Section("Old Fella") { Link("MIT License", destination: AboutLinks.appLicense) Text("Copyright (c) 2026 Old Fella contributors") } Section("ATProtoKit") { Link("MIT License", destination: AboutLinks.atProtoKitLicense) Text("Copyright (c) 2026 Christopher Jr Riley") } Section("Atkinson Hyperlegible Next") { Text("Copyright 2020-2024 The Atkinson Hyperlegible Next Project Authors") Link( "SIL Open Font License 1.1", destination: URL( string: "https://github.com/googlefonts/atkinson-hyperlegible-next/blob/main/OFL.txt")!) } Section("EmojiKit") { Link("MIT License", destination: AboutLinks.emojiKitLicense) Text("Copyright (c) 2023-2026 Daniel Saidi") } Section("Iosevka") { Text("Copyright (c) 2015-2026 Renzhi Li") Link( "SIL Open Font License 1.1", destination: URL(string: "https://github.com/be5invis/Iosevka/blob/v34.9.1/LICENSE.md")!) } Section("Paper Mono") { Text("Copyright 2025 The Paper-Mono.Git Project Authors") Link( "SIL Open Font License 1.1", destination: URL(string: "https://github.com/paper-design/paper-mono/blob/main/OFL.txt")!) } Section("swift-log") { Link("Apache License 2.0", destination: AboutLinks.swiftLogLicense) Link("Notice", destination: AboutLinks.swiftLogNotice) Text("Copyright 2018, 2019 The SwiftLog Project") } } .appNavigationTitle("Open Source Licenses") } } #if DEBUG #Preview("Settings") { PreviewHost { _ in SettingsView() } } #endif struct SettingsView: View { @AppStorage("appFont") private var appFont = AppFont.system.rawValue @AppStorage("hideAvatars") private var hideAvatars = false @AppStorage("handlesOnly") private var handlesOnly = false @Environment(AppModel.self) private var model @Environment(\.dismiss) private var dismiss @State private var confirmsSignOut = false @State private var showsFonts = false @State private var showsProfileEditor = false @AppStorage("openLinksInApp") private var openLinksInApp = true @AppStorage("hideQuotedPosts") private var hideQuotedPosts = false @AppStorage("hideReplyContexts") private var hideReplyContexts = false @AppStorage("hidePictures") private var hidePictures = false @AppStorage("showGIFsInline") private var showGIFsInline = true @AppStorage("remindMissingAltText") private var remindMissingAltText = true @AppStorage("padVisibleColumnCount") private var padVisibleColumnCount = 2 var showsDoneButton = false var body: some View { @Bindable var model = model NavigationStack { List { if let account = model.account { Section { accountRow(account) } } Section { Toggle("Show avatars", isOn: $hideAvatars.negated) .accessibilityIdentifier("showAvatars") Toggle("Show display names", isOn: $handlesOnly.negated) .accessibilityIdentifier("showDisplayNames") Toggle("Show pictures", isOn: $hidePictures.negated) .accessibilityIdentifier("showPictures") Toggle("Show GIFs inline", isOn: $showGIFsInline) .accessibilityIdentifier("showGIFsInline") Toggle("Show quoted posts", isOn: $hideQuotedPosts.negated) .accessibilityIdentifier("showQuotedPosts") Toggle("Show reply context", isOn: $hideReplyContexts.negated) .accessibilityIdentifier("showReplyContexts") Toggle("Filter replies by following", isOn: $model.induceADHD.negated) .accessibilityIdentifier("filterReplies") } header: { Text("Distractions") } footer: { Text( "Hidden pictures open in the image viewer. Hidden GIFs have a button to play them. " + "Turn off reply filtering to show replies regardless of who you follow." ) .appFont(.footnote) .accessibilityIdentifier("distractionsDescription") } Section("Appearance") { Button { showsFonts = true } label: { HStack { Text("Font").foregroundStyle(.primary) Spacer() Text((AppFont(rawValue: appFont) ?? .system).title) .font((AppFont(rawValue: appFont) ?? .system).font(.body)) Image(systemName: "chevron.up.chevron.down") .font(.caption.weight(.semibold)) } .appFont(.body) } .accessibilityLabel("Font") .accessibilityValue((AppFont(rawValue: appFont) ?? .system).title) .accessibilityIdentifier("appFont") } Section("Posts") { Toggle("Remind me to add alt text", isOn: $remindMissingAltText) .accessibilityIdentifier("remindMissingAltText") } if UIDevice.current.userInterfaceIdiom == .pad { Section("Layout") { Picker("Columns", selection: $padVisibleColumnCount) { Text("2").tag(2) Text("3").tag(3) Text("4").tag(4) } .pickerStyle(.segmented) .accessibilityIdentifier("padVisibleColumnCount") } } Section("Links") { Toggle("Open links in Old Fella", isOn: $openLinksInApp) .accessibilityIdentifier("openLinksInApp") } Section("About") { NavigationLink("Open Source Licenses") { OpenSourceLicensesView() } .accessibilityIdentifier("openSourceLicenses") Link("Source Repository", destination: AboutLinks.repository) .accessibilityIdentifier("sourceRepository") } if model.account != nil { Section { Button("Sign out", systemImage: "rectangle.portrait.and.arrow.right", role: .destructive) { confirmsSignOut = true } .accessibilityIdentifier("settingsSignOutButton") } } buildDetails } .sheet(isPresented: $showsFonts) { NavigationStack { List(AppFont.allCases) { font in Button { appFont = font.rawValue showsFonts = false } label: { HStack { Text(font.title).font(font.font(.body)) Spacer() if font.rawValue == appFont { Image(systemName: "checkmark") } } .foregroundStyle(.primary) } .accessibilityAddTraits(font.rawValue == appFont ? .isSelected : []) } .appNavigationTitle("Font") .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { showsFonts = false } } } } } .sheet(isPresented: $showsProfileEditor) { ProfileEditorView() } .appNavigationTitle("Settings") .toolbar { if showsDoneButton { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } .accessibilityIdentifier("settingsDoneButton") } } } .confirmationDialog("Sign out of Bluesky?", isPresented: $confirmsSignOut, titleVisibility: .visible) { Button("Sign out", role: .destructive) { Task { await model.signOut() } } .accessibilityIdentifier("settingsConfirmSignOutButton") Button("Cancel", role: .cancel) {} } message: { Text("You can sign in again at any time.") } } } private var buildDetails: some View { let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String let fullCommit = Bundle.main.object(forInfoDictionaryKey: "OldFellaGitCommit") as? String ?? "" let commit = fullCommit.isEmpty ? nil : String(fullCommit.prefix(7)) return Section { buildDetail("Version", value: version, identifier: "settingsVersion") buildDetail("Git commit", value: commit, identifier: "settingsGitCommit") } } private func buildDetail(_ label: LocalizedStringKey, value: String?, identifier: String) -> some View { let value = value ?? String(localized: "Unknown") return LabeledContent(label, value: value) .accessibilityElement(children: .ignore) .accessibilityLabel(Text(label)) .accessibilityValue(Text(verbatim: value)) .accessibilityIdentifier(identifier) } private func accountRow(_ account: Account) -> some View { let showsDisplayName = !handlesOnly && account.displayName.caseInsensitiveCompare(account.handle) != .orderedSame let handle = "@\(account.handle)" return Button { showsProfileEditor = true } label: { HStack(spacing: 12) { AccountAvatar(account: account, size: 48) VStack(alignment: .leading, spacing: 3) { if showsDisplayName { Text(account.displayName).appFont(.headline) } Text(handle) .appFont(showsDisplayName ? .subheadline : .headline) .foregroundStyle(showsDisplayName ? .secondary : .primary) } Spacer(minLength: 8) Image(systemName: "chevron.right") .font(.footnote.weight(.semibold)) .foregroundStyle(.secondary) .accessibilityHidden(true) } .padding(.vertical, 6) .contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityLabel(showsDisplayName ? "\(account.displayName), \(handle)" : handle) .accessibilityHint("Opens the profile editor") .accessibilityIdentifier("settingsEditProfile") } } extension Binding where Value == Bool { fileprivate var negated: Binding { Binding(get: { !wrappedValue }, set: { wrappedValue = !$0 }) } }