Inkspring / app · inkspring.ai / native-mac / iPhone / MobileSettings.swift
| 1 | import SwiftUI |
| 2 | |
| 3 | struct MobileSettingsView: View { |
| 4 | @Binding var theme: StudioTheme |
| 5 | let library: MobileLibrary |
| 6 | let openSetup: () -> Void |
| 7 | |
| 8 | @Environment(\.studioPalette) private var palette |
| 9 | @Environment(\.scenePhase) private var scenePhase |
| 10 | @State private var generationStatus: String? |
| 11 | @Environment(\.mobileWideLayout) private var wideLayout |
| 12 | |
| 13 | private var settingsBackground: Color { |
| 14 | palette.theme == .light ? Color(.sRGB, red: 237.0 / 255, green: 240.0 / 255, blue: 243.0 / 255) : palette.canvas |
| 15 | } |
| 16 | |
| 17 | var body: some View { |
| 18 | NavigationStack { |
| 19 | Form { |
| 20 | Section { |
| 21 | ForEach([StudioTheme.paper, .graphite, .light, .system]) { choice in |
| 22 | themeRow(choice) |
| 23 | } |
| 24 | } header: { |
| 25 | Text("Appearance").foregroundStyle(palette.muted) |
| 26 | } |
| 27 | .listRowBackground(palette.card) |
| 28 | |
| 29 | Section { |
| 30 | Button(action: openSetup) { supportRow("Getting started", icon: "desktopcomputer", external: false) } |
| 31 | .accessibilityIdentifier("settings.gettingStarted") |
| 32 | }.listRowBackground(palette.card) |
| 33 | |
| 34 | syncSection |
| 35 | |
| 36 | Section { |
| 37 | if let code = library.syncErrorCode { |
| 38 | LabeledContent("Error code", value: code) |
| 39 | .textSelection(.enabled) |
| 40 | } |
| 41 | ShareLink(item: syncDiagnostics) { |
| 42 | supportRow("Share Sync Diagnostics", icon: "square.and.arrow.up", external: false) |
| 43 | } |
| 44 | .accessibilityIdentifier("settings.shareSyncDiagnostics") |
| 45 | } header: { |
| 46 | Text("Diagnostics").foregroundStyle(palette.muted) |
| 47 | } footer: { |
| 48 | Text("Includes sync status and timestamps. Your drafts, notes, and account details are not included.") |
| 49 | .foregroundStyle(palette.muted) |
| 50 | } |
| 51 | .listRowBackground(palette.card) |
| 52 | |
| 53 | Section { |
| 54 | Link(destination: InkspringCommunity.websiteHelp) { |
| 55 | supportRow("Setup and Troubleshooting", icon: "book") |
| 56 | } |
| 57 | } header: { |
| 58 | Text("Support").foregroundStyle(palette.muted) |
| 59 | } footer: { |
| 60 | Text("Free personal help with Inkspring on Mac, iPhone, and iPad, including desktop setup and MCP connections.") |
| 61 | .foregroundStyle(palette.muted) |
| 62 | } |
| 63 | .listRowBackground(palette.card) |
| 64 | |
| 65 | Section { |
| 66 | ShareLink(item: InkspringCommunity.website) { |
| 67 | supportRow("Share Inkspring", icon: "square.and.arrow.up", external: false) |
| 68 | } |
| 69 | Link(destination: InkspringCommunity.feedback) { |
| 70 | supportRow("Send Feedback", icon: "bubble.left.and.bubble.right") |
| 71 | } |
| 72 | Link(destination: InkspringCommunity.apps) { |
| 73 | supportRow("More Free Apps from Project ATOM", icon: "arrow.up.forward.app") |
| 74 | } |
| 75 | } header: { |
| 76 | Text("Support Inkspring").foregroundStyle(palette.muted) |
| 77 | } |
| 78 | .listRowBackground(palette.card) |
| 79 | |
| 80 | Section { |
| 81 | HStack(alignment: .center, spacing: 14) { |
| 82 | Image("InkspringBrand") |
| 83 | .resizable().scaledToFit().frame(width: 52, height: 52) |
| 84 | .clipShape(.rect(cornerRadius: 12)) |
| 85 | .shadow(color: palette.colorScheme == .dark ? .white.opacity(0.14) : .black.opacity(0.12), radius: 6, y: 2) |
| 86 | .accessibilityHidden(true) |
| 87 | VStack(alignment: .leading, spacing: 4) { |
| 88 | Text("Inkspring").font(.headline).foregroundStyle(palette.text) |
| 89 | Text("Your private writing studio.") |
| 90 | .font(.subheadline).foregroundStyle(palette.muted) |
| 91 | } |
| 92 | } |
| 93 | .padding(.vertical, 6) |
| 94 | Text("Version \(appVersion) (\(appBuild))") |
| 95 | .foregroundStyle(palette.muted) |
| 96 | .accessibilityIdentifier("settingsAppVersion") |
| 97 | protomotaProductPill |
| 98 | } header: { |
| 99 | Text("About").foregroundStyle(palette.muted) |
| 100 | } |
| 101 | .listRowBackground(palette.card) |
| 102 | |
| 103 | Section("Community") { |
| 104 | Link(destination: InkspringCommunity.community) { |
| 105 | supportRow("Glimmer community", icon: "person.2") |
| 106 | } |
| 107 | } |
| 108 | .listRowBackground(palette.card) |
| 109 | |
| 110 | Section { |
| 111 | Label(generationStatus ?? "On-device idea generation is available.", |
| 112 | systemImage: "sparkles") |
| 113 | } header: { |
| 114 | Text("Apple Intelligence").foregroundStyle(palette.muted) |
| 115 | } |
| 116 | .listRowBackground(palette.card) |
| 117 | } |
| 118 | .scrollContentBackground(.hidden) |
| 119 | .frame(maxWidth: 700) |
| 120 | .mobileCanvas(background: settingsBackground) |
| 121 | .mobilePageTitle("Settings", wide: wideLayout, background: settingsBackground) |
| 122 | .toolbar(wideLayout ? .hidden : .visible, for: .tabBar) |
| 123 | } |
| 124 | .onAppear { generationStatus = MobileIdeasView.generationAvailabilityMessage } |
| 125 | .onChange(of: scenePhase) { _, phase in |
| 126 | if phase == .active { generationStatus = MobileIdeasView.generationAvailabilityMessage } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | private func supportRow(_ title: String, icon: String, external: Bool = true) -> some View { |
| 131 | HStack { |
| 132 | Label { |
| 133 | Text(title).foregroundStyle(palette.text) |
| 134 | } icon: { |
| 135 | Image(systemName: icon).foregroundStyle(palette.iconAccent) |
| 136 | } |
| 137 | Spacer(minLength: 12) |
| 138 | if external { |
| 139 | StudioExternalArrow() |
| 140 | } |
| 141 | } |
| 142 | .frame(maxWidth: .infinity, minHeight: 36, alignment: .leading) |
| 143 | .contentShape(Rectangle()) |
| 144 | } |
| 145 | |
| 146 | private var protomotaProductPill: some View { |
| 147 | Link(destination: URL(string: "https://projectatom.ai/")!) { |
| 148 | HStack(spacing: 8) { |
| 149 | Image("ProjectAtomLogo") |
| 150 | .renderingMode(.original) |
| 151 | .resizable() |
| 152 | .scaledToFit() |
| 153 | .frame(width: 22, height: 22) |
| 154 | .clipShape(.rect(cornerRadius: 6)) |
| 155 | .accessibilityHidden(true) |
| 156 | Text("A Project ATOM app") |
| 157 | .font(.subheadline.weight(.semibold)) |
| 158 | Image(systemName: "arrow.up.right") |
| 159 | .font(.caption.weight(.medium)) |
| 160 | .accessibilityHidden(true) |
| 161 | } |
| 162 | .padding(.leading, 10) |
| 163 | .padding(.trailing, 16) |
| 164 | .frame(minHeight: 44) |
| 165 | .foregroundStyle(.white) |
| 166 | .background(.black, in: Capsule()) |
| 167 | .overlay { Capsule().strokeBorder(.white.opacity(0.14)) } |
| 168 | .contentShape(Capsule()) |
| 169 | } |
| 170 | .buttonStyle(.plain) |
| 171 | .accessibilityIdentifier("settings.protomotaProduct") |
| 172 | } |
| 173 | |
| 174 | private var appVersion: String { |
| 175 | Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "1.0.0" |
| 176 | } |
| 177 | |
| 178 | private var appBuild: String { |
| 179 | Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "—" |
| 180 | } |
| 181 | |
| 182 | private var syncDiagnostics: String { |
| 183 | var lines = [ |
| 184 | "Inkspring \(appVersion) (\(appBuild))", |
| 185 | "Apple Account: \(library.accountStatus)", |
| 186 | "Mac workspace: \(workspaceStatus)", |
| 187 | "Last check: \(timestamp(library.lastCheck))", |
| 188 | "Last iCloud response: \(timestamp(library.lastCloudContact))", |
| 189 | "Mac snapshot: \(timestamp(library.snapshot?.updatedAt))" |
| 190 | ] |
| 191 | if let status = library.newsletterSyncSummary { lines.append("Newsletter sync: \(status)") } |
| 192 | if let code = library.syncErrorCode { lines.append("Error code: \(code)") } |
| 193 | return lines.joined(separator: "\n") |
| 194 | } |
| 195 | |
| 196 | private var syncSection: some View { |
| 197 | Section { |
| 198 | LabeledContent("Apple Account", value: library.accountStatus) |
| 199 | .accessibilityIdentifier("settings.libraryStatus") |
| 200 | LabeledContent("Mac workspace", value: workspaceStatus) |
| 201 | if let status = library.newsletterSyncSummary { |
| 202 | LabeledContent("Newsletter sync", value: status) |
| 203 | .accessibilityIdentifier("settings.newsletterSync") |
| 204 | } |
| 205 | LabeledContent("Last check", value: timestamp(library.lastCheck)) |
| 206 | LabeledContent("Last iCloud response", value: timestamp(library.lastCloudContact)) |
| 207 | if let snapshot = library.snapshot { |
| 208 | LabeledContent("Mac snapshot", value: timestamp(snapshot.updatedAt)) |
| 209 | } |
| 210 | if let error = library.error { |
| 211 | Text(error).foregroundStyle(palette.muted) |
| 212 | } else if library.remoteWorkspaceFound == false { |
| 213 | Text("iCloud has no workspace from your Mac yet. Open Inkspring on your Mac and check Settings → Storage & backups.") |
| 214 | .foregroundStyle(palette.muted) |
| 215 | } |
| 216 | Button { |
| 217 | Task { await library.refresh() } |
| 218 | } label: { |
| 219 | if library.busy { |
| 220 | ProgressView { |
| 221 | Text("Checking iCloud…").foregroundStyle(palette.text) |
| 222 | } |
| 223 | } else { |
| 224 | Label { |
| 225 | Text("Check Now").foregroundStyle(palette.text) |
| 226 | } icon: { |
| 227 | Image(systemName: "arrow.clockwise").foregroundStyle(palette.iconAccent) |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | .disabled(library.busy) |
| 232 | .accessibilityIdentifier("settings.checkSync") |
| 233 | } header: { |
| 234 | Text("iCloud Sync").foregroundStyle(palette.muted) |
| 235 | } |
| 236 | .listRowBackground(palette.card) |
| 237 | } |
| 238 | |
| 239 | private var workspaceStatus: String { |
| 240 | switch library.remoteWorkspaceFound { |
| 241 | case true?: "Found" |
| 242 | case false?: "Waiting for Mac" |
| 243 | case nil: "Not checked" |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | private func timestamp(_ date: Date?) -> String { |
| 248 | date?.formatted(date: .abbreviated, time: .standard) ?? "—" |
| 249 | } |
| 250 | |
| 251 | private func themeRow(_ choice: StudioTheme) -> some View { |
| 252 | Button { |
| 253 | theme = choice |
| 254 | } label: { |
| 255 | HStack(spacing: 13) { |
| 256 | themePreview(choice) |
| 257 | .accessibilityHidden(true) |
| 258 | Text(choice.title) |
| 259 | .font(.body.weight(.medium)) |
| 260 | .foregroundStyle(palette.text) |
| 261 | Spacer(minLength: 8) |
| 262 | if theme == choice { |
| 263 | Image(systemName: "checkmark.circle.fill") |
| 264 | .foregroundStyle(palette.iconAccent) |
| 265 | .accessibilityHidden(true) |
| 266 | } |
| 267 | } |
| 268 | .frame(minHeight: 44) |
| 269 | .contentShape(Rectangle()) |
| 270 | } |
| 271 | .buttonStyle(.plain) |
| 272 | .accessibilityAddTraits(theme == choice ? .isSelected : []) |
| 273 | .accessibilityIdentifier("theme.\(choice.rawValue)") |
| 274 | } |
| 275 | |
| 276 | @ViewBuilder private func themePreview(_ choice: StudioTheme) -> some View { |
| 277 | if choice == .system { |
| 278 | Image(systemName: "circle.lefthalf.filled") |
| 279 | .foregroundStyle(palette.text) |
| 280 | .frame(width: 58, height: 35) |
| 281 | .studioSurface(6, fill: palette.well) |
| 282 | } else { |
| 283 | let swatch = StudioPalette(theme: choice) |
| 284 | VStack(alignment: .leading, spacing: 4) { |
| 285 | Capsule().fill(swatch.iconAccent).frame(width: 19, height: 3) |
| 286 | RoundedRectangle(cornerRadius: 3) |
| 287 | .fill(swatch.card) |
| 288 | .overlay { |
| 289 | RoundedRectangle(cornerRadius: 3).strokeBorder(swatch.line) |
| 290 | } |
| 291 | } |
| 292 | .padding(6) |
| 293 | .frame(width: 58, height: 35) |
| 294 | .background(swatch.canvas, in: .rect(cornerRadius: 6)) |
| 295 | .overlay { RoundedRectangle(cornerRadius: 6).strokeBorder(swatch.line) } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | extension View { |
| 301 | func mobileCanvas(background: Color? = nil) -> some View { |
| 302 | modifier(MobileCanvas(background: background)) |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | private struct MobileCanvas: ViewModifier { |
| 307 | @Environment(\.studioPalette) private var palette |
| 308 | let background: Color? |
| 309 | |
| 310 | func body(content: Content) -> some View { |
| 311 | content |
| 312 | .frame(maxWidth: .infinity, maxHeight: .infinity) |
| 313 | .background { (background ?? palette.canvas).ignoresSafeArea() } |
| 314 | } |
| 315 | } |