fix(swift-ios): simplify settings

This commit is contained in:
Theo Browne committed 2026-08-09 20:55:47 -07:00
1 parent 0f5a1c1049
commit 82a8ab6df1
1 file changed
+457 -128
@@ -7,6 +7,8 @@ public struct SettingsView: View {
@State private var isSaving = false
@State private var showingDisconnect = false
@State private var showingAddEnvironment = false
@State private var showingDevices = false
@State private var showingT3Connect = false
@State private var removalTarget: FeatureEnvironment?
@State private var saveErrorMessage: String?
@@ -17,28 +19,26 @@ public struct SettingsView: View {
public var body: some View {
NavigationStack {
Form {
connectionSection
t3ConnectSection
agentSection
preferencesSection
aboutSection
}
.scrollContentBackground(.hidden)
.background(T3Colors.background)
.navigationTitle("Settings")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Cancel") { dismiss() }
}
ToolbarItem(placement: .confirmationAction) {
Button(isSaving ? "Saving…" : "Save") {
save()
VStack(spacing: 0) {
settingsHeader
Divider()
.overlay(T3Colors.border)
ScrollView {
LazyVStack(alignment: .leading, spacing: 28) {
connectionSection
t3ConnectSection
agentSection
preferencesSection
aboutSection
}
.disabled(isSaving || settings == model.snapshot.settings)
.padding(.vertical, 18)
}
.scrollDismissesKeyboard(.interactively)
}
.background(T3Colors.background)
.toolbar(.hidden, for: .navigationBar)
.confirmationDialog(
"Disconnect from this server?",
isPresented: $showingDisconnect,
@@ -94,6 +94,30 @@ public struct SettingsView: View {
}
)
}
.sheet(isPresented: $showingDevices) {
NavigationStack {
DevicesView(manager: deviceManager)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Done") { showingDevices = false }
}
}
}
.presentationDragIndicator(.visible)
}
.sheet(isPresented: $showingT3Connect) {
if let capability = model.client as? any T3ConnectCapable {
NavigationStack {
T3ConnectView(capability: capability)
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Done") { showingT3Connect = false }
}
}
}
.presentationDragIndicator(.visible)
}
}
.onAppear {
model.setConnectionManagementPresented(true)
}
@@ -101,156 +125,317 @@ public struct SettingsView: View {
model.setConnectionManagementPresented(false)
}
}
.presentationDragIndicator(.visible)
}
private var settingsHeader: some View {
HStack(spacing: 12) {
Button("Cancel") { dismiss() }
.frame(width: 72, alignment: .leading)
.foregroundStyle(T3Colors.accent)
Spacer(minLength: 0)
Text("Settings")
.font(T3Typography.navigationTitle)
.foregroundStyle(T3Colors.textPrimary)
Spacer(minLength: 0)
Button(isSaving ? "Saving…" : "Save") {
save()
}
.fontWeight(.semibold)
.frame(width: 72, alignment: .trailing)
.foregroundStyle(canSave ? T3Colors.accent : T3Colors.textTertiary)
.disabled(!canSave)
}
.font(T3Typography.control)
.padding(.horizontal, 20)
.frame(minHeight: 54)
}
private var connectionSection: some View {
Section("Connections") {
HStack(spacing: 12) {
Image(systemName: connectionSymbol)
.foregroundStyle(connectionColor)
.frame(width: 22)
VStack(alignment: .leading, spacing: 2) {
Text(model.snapshot.connection.environmentName ?? "T3 server")
.font(T3Typography.homeTitle)
Text(connectionDescription)
.font(T3Typography.supporting)
.foregroundStyle(T3Colors.textSecondary)
.lineLimit(1)
}
Spacer()
Text(connectionStatus)
.font(T3Typography.supportingStrong)
.foregroundStyle(connectionColor)
}
.accessibilityElement(children: .combine)
NavigationLink {
DevicesView(manager: deviceManager)
} label: {
Label("Devices and sessions", systemImage: "laptopcomputer.and.iphone")
}
ForEach(model.snapshot.environments) { environment in
Button {
guard !environment.isActive else { return }
Task { await model.activateEnvironment(environment.id) }
} label: {
HStack(spacing: 12) {
Image(systemName: "desktopcomputer")
.foregroundStyle(.secondary)
.frame(width: 22)
VStack(alignment: .leading, spacing: 2) {
Text(environment.name)
.font(T3Typography.threadBody)
.foregroundStyle(.primary)
Text(environment.endpoint)
.font(T3Typography.supporting)
.foregroundStyle(T3Colors.textSecondary)
.lineLimit(1)
SettingsSection(title: "Connections") {
VStack(spacing: 0) {
if model.snapshot.environments.isEmpty {
connectionFallbackRow
} else {
ForEach(Array(model.snapshot.environments.enumerated()), id: \.element.id) {
index, environment in
if index > 0 {
settingsDivider
}
Spacer()
let status = environmentStatus(for: environment)
Label(status.title, systemImage: status.symbol)
.font(T3Typography.supportingStrong)
.foregroundStyle(status.color)
environmentRow(environment)
}
}
.swipeActions {
Button(role: .destructive) {
removalTarget = environment
} label: {
Label("Remove", systemImage: "trash")
}
.disabled(environment.isActive)
}
.contextMenu {
Button(role: .destructive) {
removalTarget = environment
} label: {
Label("Remove saved server", systemImage: "trash")
}
.disabled(environment.isActive)
}
}
Button {
showingAddEnvironment = true
} label: {
Label("Add another server", systemImage: "plus")
}
settingsDivider
Button("Disconnect", role: .destructive) {
showingDisconnect = true
Button {
showingDevices = true
} label: {
SettingsNavigationRow(
title: "Devices and sessions",
systemImage: "laptopcomputer.and.iphone"
)
}
.buttonStyle(.plain)
settingsDivider
Button {
showingAddEnvironment = true
} label: {
SettingsActionRow(
title: "Add server",
systemImage: "plus"
)
}
.buttonStyle(.plain)
settingsDivider
Button(role: .destructive) {
showingDisconnect = true
} label: {
SettingsActionRow(
title: "Disconnect current server",
systemImage: "rectangle.portrait.and.arrow.right",
color: T3Colors.danger
)
}
.buttonStyle(.plain)
}
}
}
private var agentSection: some View {
Section("Default agent") {
ProviderModelPicker(
providers: model.snapshot.providers,
selection: $settings.defaultSelection
)
if let provider = selectedProvider, let selectedModel {
LabeledContent("Provider", value: provider.name)
if let detail = selectedModel.detail {
SettingsSection(title: "Default agent") {
VStack(spacing: 0) {
ProviderModelPicker(
providers: model.snapshot.providers,
selection: $settings.defaultSelection
)
.padding(.horizontal, 20)
.frame(minHeight: 58)
if let provider = selectedProvider {
settingsDivider
SettingsValueRow(title: "Provider", value: provider.name)
}
if let detail = selectedModel?.detail {
settingsDivider
Text(detail)
.font(T3Typography.supporting)
.foregroundStyle(T3Colors.textSecondary)
.padding(.horizontal, 20)
.padding(.vertical, 12)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
}
private var t3ConnectSection: some View {
Section("T3 Connect") {
if let capability = model.client as? any T3ConnectCapable {
NavigationLink {
T3ConnectView(capability: capability)
SettingsSection(
title: "T3 Connect",
footer: "Optional account sync for relay-managed environments."
) {
if model.client is any T3ConnectCapable {
Button {
showingT3Connect = true
} label: {
Label("Cloud environments", systemImage: "cloud")
SettingsNavigationRow(
title: "Cloud environments",
systemImage: "cloud"
)
}
.buttonStyle(.plain)
} else {
LabeledContent {
Text("Unavailable")
.foregroundStyle(T3Colors.textTertiary)
} label: {
Label("Cloud environments", systemImage: "cloud.slash")
}
SettingsValueRow(
title: "Cloud environments",
value: "Unavailable",
systemImage: "cloud.slash"
)
}
Text("Optional account sync for relay-managed environments.")
.font(T3Typography.supporting)
.foregroundStyle(T3Colors.textSecondary)
}
}
private var preferencesSection: some View {
Section("Preferences") {
Picker("Theme", selection: $settings.appearance) {
Text("System").tag(FeatureAppearance.system)
Text("Light").tag(FeatureAppearance.light)
Text("Dark").tag(FeatureAppearance.dark)
SettingsSection(title: "Preferences") {
VStack(spacing: 0) {
HStack(spacing: 12) {
SettingsRowIcon(systemName: "circle.lefthalf.filled")
Text("Theme")
.font(T3Typography.threadBody)
Spacer(minLength: 12)
Picker("Theme", selection: $settings.appearance) {
Text("System").tag(FeatureAppearance.system)
Text("Light").tag(FeatureAppearance.light)
Text("Dark").tag(FeatureAppearance.dark)
}
.labelsHidden()
.pickerStyle(.menu)
.tint(T3Colors.textSecondary)
}
.padding(.horizontal, 20)
.frame(minHeight: 52)
settingsDivider
SettingsToggleRow(
title: "Haptics",
systemImage: "iphone.radiowaves.left.and.right",
isOn: $settings.hapticsEnabled
)
settingsDivider
SettingsToggleRow(
title: "Notifications",
systemImage: "bell",
isOn: $settings.notificationsEnabled
)
settingsDivider
SettingsToggleRow(
title: "Live Activities",
systemImage: "waveform.path.ecg.rectangle",
isOn: $settings.liveActivitiesEnabled
)
}
Toggle("Haptics", isOn: $settings.hapticsEnabled)
Toggle("Notifications", isOn: $settings.notificationsEnabled)
Toggle("Live Activities", isOn: $settings.liveActivitiesEnabled)
}
}
private var aboutSection: some View {
Section("About") {
LabeledContent("App", value: appDisplayName)
LabeledContent("Platform", value: "Native SwiftUI")
Link("Open source", destination: URL(string: "https://github.com/pingdotgg/t3code")!)
SettingsSection(title: "About") {
VStack(spacing: 0) {
SettingsValueRow(title: "App", value: appDisplayName)
settingsDivider
SettingsValueRow(title: "Platform", value: "Native SwiftUI")
settingsDivider
Link(destination: URL(string: "https://github.com/pingdotgg/t3code")!) {
SettingsNavigationRow(
title: "Open source",
systemImage: "chevron.left.forwardslash.chevron.right",
trailingSystemImage: "arrow.up.right"
)
}
.buttonStyle(.plain)
}
}
}
private var connectionFallbackRow: some View {
HStack(spacing: 12) {
SettingsRowIcon(systemName: connectionSymbol, color: connectionColor)
VStack(alignment: .leading, spacing: 2) {
Text(model.snapshot.connection.environmentName ?? "T3 server")
.font(T3Typography.homeTitle)
.foregroundStyle(T3Colors.textPrimary)
Text(connectionDescription)
.font(T3Typography.supporting)
.foregroundStyle(T3Colors.textSecondary)
.lineLimit(1)
}
Spacer(minLength: 8)
Text(connectionStatus)
.font(T3Typography.supportingStrong)
.foregroundStyle(connectionColor)
}
.padding(.horizontal, 20)
.frame(minHeight: 58)
.accessibilityElement(children: .combine)
}
private func environmentRow(_ environment: FeatureEnvironment) -> some View {
Button {
guard !environment.isActive else { return }
Task { await model.activateEnvironment(environment.id) }
} label: {
HStack(spacing: 12) {
let status = environmentStatus(for: environment)
let activeIsConnected = environment.isActive
&& model.snapshot.connection.state == .connected
SettingsRowIcon(
systemName: activeIsConnected ? "checkmark.circle.fill" : "desktopcomputer",
color: activeIsConnected ? T3Colors.success : T3Colors.textTertiary
)
VStack(alignment: .leading, spacing: 2) {
Text(environment.name)
.font(T3Typography.homeTitle)
.foregroundStyle(T3Colors.textPrimary)
.lineLimit(1)
Text(environment.endpoint)
.font(T3Typography.supporting)
.foregroundStyle(T3Colors.textSecondary)
.lineLimit(1)
.truncationMode(.middle)
}
Spacer(minLength: 8)
Label(status.title, systemImage: status.symbol)
.labelStyle(SettingsStatusLabelStyle())
.font(T3Typography.supportingStrong)
.foregroundStyle(status.color)
}
.padding(.leading, 20)
.padding(.trailing, environment.isActive ? 20 : 56)
.frame(minHeight: 62)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityElement(children: .combine)
.accessibilityHint(environment.isActive ? "Current server" : "Switch to this server")
.overlay(alignment: .trailing) {
if !environment.isActive {
Menu {
Button(role: .destructive) {
removalTarget = environment
} label: {
Label("Remove saved server", systemImage: "trash")
}
} label: {
Image(systemName: "ellipsis")
.font(T3Typography.control)
.foregroundStyle(T3Colors.textTertiary)
.frame(width: T3Metrics.minimumTapTarget, height: 62)
.contentShape(Rectangle())
}
.padding(.trailing, 8)
.accessibilityLabel("Actions for \(environment.name)")
}
}
.contextMenu {
if !environment.isActive {
Button(role: .destructive) {
removalTarget = environment
} label: {
Label("Remove saved server", systemImage: "trash")
}
}
}
}
private var settingsDivider: some View {
Divider()
.overlay(T3Colors.separator)
.padding(.leading, 54)
.padding(.trailing, 20)
}
private var appDisplayName: String {
Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String
?? "T3 Code SwiftUI"
}
private var canSave: Bool {
!isSaving && settings != model.snapshot.settings
}
private var deviceManager: any FeatureDeviceManaging {
(model.client as? any FeatureDeviceManaging) ?? EmptyFeatureDeviceManager.shared
}
@@ -295,13 +480,13 @@ public struct SettingsView: View {
switch state {
case .connected where environment.isActive:
return EnvironmentStatusPresentation(
title: "Live",
title: "Active",
symbol: "dot.radiowaves.left.and.right",
color: T3Colors.accent
)
case .connected:
return EnvironmentStatusPresentation(
title: "Available",
title: "Ready",
symbol: "network",
color: T3Colors.textSecondary
)
@@ -346,3 +531,147 @@ private struct EnvironmentStatusPresentation {
let symbol: String
let color: Color
}
private struct SettingsSection<Content: View>: View {
let title: String
let footer: String?
let content: Content
init(
title: String,
footer: String? = nil,
@ViewBuilder content: () -> Content
) {
self.title = title
self.footer = footer
self.content = content()
}
var body: some View {
VStack(alignment: .leading, spacing: 8) {
Text(title)
.font(T3Typography.supportingStrong)
.foregroundStyle(T3Colors.textSecondary)
.padding(.horizontal, 20)
content
if let footer {
Text(footer)
.font(T3Typography.supporting)
.foregroundStyle(T3Colors.textTertiary)
.padding(.horizontal, 20)
.padding(.top, 2)
}
}
}
}
private struct SettingsRowIcon: View {
let systemName: String
var color: Color = T3Colors.accent
var body: some View {
Image(systemName: systemName)
.font(.system(size: 17, weight: .medium))
.foregroundStyle(color)
.frame(width: 22, height: 22)
.accessibilityHidden(true)
}
}
private struct SettingsNavigationRow: View {
let title: String
let systemImage: String
var trailingSystemImage = "chevron.right"
var body: some View {
HStack(spacing: 12) {
SettingsRowIcon(systemName: systemImage)
Text(title)
.font(T3Typography.threadBody)
.foregroundStyle(T3Colors.textPrimary)
Spacer(minLength: 8)
Image(systemName: trailingSystemImage)
.font(T3Typography.supportingStrong)
.foregroundStyle(T3Colors.textTertiary)
.accessibilityHidden(true)
}
.padding(.horizontal, 20)
.frame(minHeight: 52)
.contentShape(Rectangle())
}
}
private struct SettingsActionRow: View {
let title: String
let systemImage: String
var color: Color = T3Colors.accent
var body: some View {
HStack(spacing: 12) {
SettingsRowIcon(systemName: systemImage, color: color)
Text(title)
.font(T3Typography.threadBody)
.foregroundStyle(color)
Spacer(minLength: 8)
}
.padding(.horizontal, 20)
.frame(minHeight: 52)
.contentShape(Rectangle())
}
}
private struct SettingsValueRow: View {
let title: String
let value: String
var systemImage: String? = nil
var body: some View {
HStack(spacing: 12) {
if let systemImage {
SettingsRowIcon(systemName: systemImage)
}
Text(title)
.font(T3Typography.threadBody)
.foregroundStyle(T3Colors.textPrimary)
Spacer(minLength: 12)
Text(value)
.font(T3Typography.threadBody)
.foregroundStyle(T3Colors.textSecondary)
.lineLimit(1)
}
.padding(.horizontal, 20)
.frame(minHeight: 52)
.accessibilityElement(children: .combine)
}
}
private struct SettingsToggleRow: View {
let title: String
let systemImage: String
@Binding var isOn: Bool
var body: some View {
Toggle(isOn: $isOn) {
HStack(spacing: 12) {
SettingsRowIcon(systemName: systemImage)
Text(title)
.font(T3Typography.threadBody)
.foregroundStyle(T3Colors.textPrimary)
}
}
.tint(T3Colors.accent)
.padding(.horizontal, 20)
.frame(minHeight: 52)
}
}
private struct SettingsStatusLabelStyle: LabelStyle {
func makeBody(configuration: Configuration) -> some View {
HStack(spacing: 4) {
configuration.icon
configuration.title
}
}
}