import SwiftUI import CryptoKit import UniformTypeIdentifiers import AnalyticsKit import AnalyticsUI /// Sources & keys: connect Google Analytics and App Store Connect without an agent (design/DESIGN.md 3.2). /// Keys go to the Keychain only, never into the workspace or iCloud data. struct SourcesView: View { @Environment(AppModel.self) private var model var body: some View { VStack(alignment: .leading, spacing: 16) { ScreenHeading("Sources & keys", subtitle: "Where your numbers come from. Keys stay in your Keychain; your iPhone only gets the numbers.") GoogleCard() AppStoreCard() HStack(spacing: 10) { Text("App Store ratings").font(Tide.rowTitle).foregroundStyle(Tide.ink) Text("Public, no key needed").font(Tide.secondary).foregroundStyle(Tide.muted) Spacer() StatusPill("On", .ok) } .padding(.horizontal, 16) if !model.failures.isEmpty { ProblemsCard() } } } } // MARK: Google Analytics struct GoogleCard: View { @Environment(AppModel.self) private var model @State private var signingIn = false @State private var error: String? @State private var confirmSignOut = false @State private var choosingSites = false @State private var importingServiceAccount = false var body: some View { let _ = model.keysVersion let serviceAccount = GoogleServiceAccountKey.savedEmail let signedIn = Keychain.has(.googleRefreshToken) let expired = model.failures.values.contains { $0.contains("invalid_grant") || $0.contains("Sign in to Google") } TideCard("Google Analytics", icon: "chart.bar.xaxis", padding: 20) { if signingIn { StatusPill("Checking…", .info) } else if expired { StatusPill("Sign in again", .error) } else if serviceAccount != nil || signedIn { StatusPill("Connected", .ok) } else { StatusPill("Not connected", .neutral) } } content: { if let serviceAccount { para("Connected with the service account \(serviceAccount). \(tracked)") HStack(spacing: 8) { Button("Choose Sites…") { choosingSites = true }.buttonStyle(.tide(.secondary)) Button("Remove Key") { confirmSignOut = true }.buttonStyle(.tide(.quietDestructive)) } } else if signingIn { para("Finish signing in in your browser, then come back here.") Button {} label: { Label("Waiting for your browser…", systemImage: "hourglass") }.buttonStyle(.tide(.primary)).disabled(true) } else if expired { para("Google ended this sign-in, so your sites stopped updating. Sign in again to pick up where you left off.") Button("Sign In Again…") { signIn() }.buttonStyle(.tide(.primary)) } else if signedIn { para("Signed in with read-only access. \(tracked)") HStack(spacing: 8) { Button("Choose Sites…") { choosingSites = true }.buttonStyle(.tide(.secondary)) Button("Sign Out") { confirmSignOut = true }.buttonStyle(.tide(.quietDestructive)) } } else { para("Sign in with Google to read visitors, sessions and page views for your sites. Graphley only asks for read-only access.") HStack(spacing: 8) { Button("Sign In with Google…") { signIn() }.buttonStyle(.tide(.primary)) Button("Use a Service Account Key…") { importingServiceAccount = true }.buttonStyle(.tide(.quiet)) } } if let error { Label(error, systemImage: "exclamationmark.circle.fill").font(Tide.caption).foregroundStyle(Tide.downText) } } .confirmationDialog(serviceAccount != nil ? "Remove the service account key?" : "Sign out of Google?", isPresented: $confirmSignOut) { Button(serviceAccount != nil ? "Remove Key" : "Sign Out", role: .destructive) { if serviceAccount != nil { GoogleServiceAccountKey.remove() } else { Keychain.remove(.googleRefreshToken) } model.keysChanged() } Button("Cancel", role: .cancel) {} } message: { Text("Graphley will stop updating your sites. The numbers you already have stay.") } .sheet(isPresented: $choosingSites) { ChooseSitesSheet() } .fileImporter(isPresented: $importingServiceAccount, allowedContentTypes: [.json]) { result in error = nil do { let url = try result.get() let ok = url.startAccessingSecurityScopedResource(); defer { if ok { url.stopAccessingSecurityScopedResource() } } try GoogleServiceAccountKey.save(json: String(contentsOf: url, encoding: .utf8)) model.keysChanged() choosingSites = true } catch { self.error = "That file isn't a Google service account key. Download a JSON key from Google Cloud › IAM › Service accounts › Keys." } } .onAppear { if model.wantsSitePicker { model.wantsSitePicker = false; choosingSites = true } } } var tracked: String { let n = model.sites.count return n == 0 ? "No sites tracked yet." : "\(n) \(n == 1 ? "site" : "sites") tracked." } func para(_ text: String) -> some View { Text(text).font(Tide.text).foregroundStyle(Tide.ink2).fixedSize(horizontal: false, vertical: true) } func signIn() { signingIn = true; error = nil Task { do { try await GoogleSignIn().run() model.keysChanged() if model.sites.isEmpty { choosingSites = true } } catch { self.error = "Sign-in didn't finish. Try again, and choose Allow when Google asks." } signingIn = false } } } /// Pick which GA4 properties to track. New ones become sites; unchecked ones are archived (history kept). struct ChooseSitesSheet: View { @Environment(AppModel.self) private var model @Environment(\.dismiss) private var dismiss @State private var properties: [GoogleAnalytics.Property] = [] @State private var chosen: Set = [] @State private var loading = true @State private var error: String? var body: some View { VStack(alignment: .leading, spacing: 14) { VStack(alignment: .leading, spacing: 4) { Text("Choose sites to track").font(Tide.sans(17, .semibold)).foregroundStyle(Tide.ink) Text("These are the Google Analytics properties your account can read.").font(Tide.secondary).foregroundStyle(Tide.muted) } Group { if loading { HStack { ProgressView().controlSize(.small); Text("Finding your properties…").font(Tide.secondary).foregroundStyle(Tide.muted) } .frame(maxWidth: .infinity, minHeight: 120) } else if let error { Text(error).font(Tide.secondary).foregroundStyle(Tide.downText).frame(maxWidth: .infinity, minHeight: 120, alignment: .leading) } else if properties.isEmpty { Text("This Google account can't read any Google Analytics properties yet.").font(Tide.secondary).foregroundStyle(Tide.muted) .frame(maxWidth: .infinity, minHeight: 120, alignment: .leading) } else { ScrollView { VStack(spacing: 0) { ForEach(Array(properties.enumerated()), id: \.element.id) { i, p in if i > 0 { RowDivider() } PropertyRow(property: p, isOn: Binding(get: { chosen.contains(p.id) }, set: { if $0 { chosen.insert(p.id) } else { chosen.remove(p.id) } })) } } } .frame(maxHeight: 360) } } HStack { Spacer() Button("Cancel") { dismiss() }.buttonStyle(.tide(.quiet)).keyboardShortcut(.cancelAction) Button(saveTitle) { save() }.buttonStyle(.tide(.primary)).keyboardShortcut(.defaultAction).disabled(loading || error != nil) } } .padding(20) .frame(width: 520) .background(Tide.surface) .task { await load() } } var current: Set { Set(model.sites.compactMap(\.ga4PropertyID)) } var saveTitle: String { chosen == current ? "Save" : "Track \(chosen.count) \(chosen.count == 1 ? "Site" : "Sites")" } func load() async { do { properties = try await GoogleAnalytics().properties().sorted { $0.name.localizedCaseInsensitiveCompare($1.name) == .orderedAscending } chosen = current } catch { self.error = "Couldn't reach Google. Check your internet connection and try again." } loading = false } func save() { let byID = Dictionary(properties.map { ($0.id, $0) }, uniquingKeysWith: { a, _ in a }) _ = try? model.store.update { ws in for i in ws.sites.indices { guard let pid = ws.sites[i].ga4PropertyID, byID[pid] != nil else { continue } ws.sites[i].archived = !chosen.contains(pid) } for pid in chosen where !ws.sites.contains(where: { $0.ga4PropertyID == pid }) { guard let p = byID[pid] else { continue } let used = Set(ws.sites.filter { !$0.archived }.map(\.colorIndex)) let color = (0..<7).first { !used.contains($0) } ?? ws.sites.count % 7 ws.sites.append(Site(id: Self.slug(p.name, taken: Set(ws.sites.map(\.id))), name: p.name, ga4PropertyID: pid, colorIndex: color)) } } model.reload() dismiss() Task { await model.refresh() } } static func slug(_ s: String, taken: Set) -> String { let base = s.lowercased().map { $0.isLetter || $0.isNumber ? String($0) : "-" }.joined().split(separator: "-").joined(separator: "-") var candidate = base.isEmpty ? "site" : base, n = 2 while taken.contains(candidate) { candidate = "\(base)-\(n)"; n += 1 } return candidate } } struct PropertyRow: View { let property: GoogleAnalytics.Property @Binding var isOn: Bool var body: some View { Button { isOn.toggle() } label: { HStack(spacing: 12) { ZStack { RoundedRectangle(cornerRadius: 4).fill(isOn ? Tide.fill : Tide.surface) RoundedRectangle(cornerRadius: 4).strokeBorder(isOn ? Tide.fill : Tide.control) if isOn { Image(systemName: "checkmark").font(.system(size: 10, weight: .bold)).foregroundStyle(Tide.accentInk) } } .frame(width: 16, height: 16) VStack(alignment: .leading, spacing: 2) { Text(property.name).font(Tide.rowTitle).foregroundStyle(Tide.ink) Text("Property \(property.id) · \(property.account)").font(Tide.code).foregroundStyle(Tide.muted) } Spacer() } .padding(.vertical, 8).contentShape(Rectangle()) } .buttonStyle(.plain) .accessibilityAddTraits(isOn ? .isSelected : []) } } // MARK: App Store Connect struct AppStoreCard: View { @Environment(AppModel.self) private var model @Environment(\.openURL) private var openURL @State private var replacing = false @State private var keyID = "" @State private var issuerID = "" @State private var vendor = "" @State private var key: KeyFile? @State private var keyIDHelp = "10 letters and numbers." @State private var showErrors = false @State private var saving = false @State private var failure: String? @State private var justSaved = false @State private var confirmRemove = false @State private var agentOpen = false struct KeyFile: Equatable { var name: String; var path: String; var pem: String } var body: some View { let _ = model.keysVersion let saved = AppStoreConnect.Credentials.saved let showForm = saved == nil || replacing TideCard("App Store Connect", icon: "arrow.down.app", padding: 20) { if saving { StatusPill("Checking…", .info) } else if failure != nil { StatusPill("Key not accepted", .error) } else if saved != nil { StatusPill("Key saved", .ok) } else { StatusPill("Not set up", .neutral) } } content: { if showForm { form(replacing: saved != nil) } else if let saved { savedView(saved) } } .confirmationDialog("Remove the App Store Connect key?", isPresented: $confirmRemove) { Button("Remove Key", role: .destructive) { AppStoreConnect.Credentials.remove(); justSaved = false; model.keysChanged() } Button("Cancel", role: .cancel) {} } message: { Text("Graphley will stop updating App Store downloads. The numbers you already have stay.") } } // Saved state: the IDs (not secret) and what to do next. The private key is never shown. @ViewBuilder func savedView(_ c: AppStoreConnect.Credentials) -> some View { Text("Key ID \(c.keyID) · Issuer \(c.issuerID.prefix(8))…\(c.issuerID.suffix(4)) · Vendor \(c.vendorNumber)") .font(Tide.code).foregroundStyle(Tide.ink2).textSelection(.enabled) if justSaved { HStack(spacing: 10) { Text("The key works. Downloads show up after the next refresh.").font(Tide.caption).foregroundStyle(Tide.up) Button("Refresh Now") { Task { await model.refresh() } }.buttonStyle(.tide(.secondary, size: .small)).disabled(model.refreshing) } } else if model.workspace.apps.isEmpty { HStack(spacing: 10) { Text("No apps added yet. Ask your agent to add them:").font(Tide.caption).foregroundStyle(Tide.muted) PromptChip("Add my App Store apps to Graphley and refresh.") } } else if let at = model.workspace.settings.lastRefreshAt, model.failures["App Store downloads"] == nil { Text("Updated downloads for \(model.workspace.apps.count) \(model.workspace.apps.count == 1 ? "app" : "apps") \(RefreshTime.describe(at)).") .font(Tide.caption).foregroundStyle(Tide.muted) } HStack(spacing: 8) { Button("Replace Key…") { keyID = c.keyID; issuerID = c.issuerID; vendor = c.vendorNumber; key = nil failure = nil; showErrors = false; replacing = true } .buttonStyle(.tide(.secondary)) Button("Remove Key") { confirmRemove = true }.buttonStyle(.tide(.quietDestructive)) } } @ViewBuilder func form(replacing: Bool) -> some View { HStack(spacing: 4) { Text("Add an App Store Connect API key with the Sales and Reports role, so Graphley can read daily downloads.") .font(Tide.text).foregroundStyle(Tide.ink2).fixedSize(horizontal: false, vertical: true) } Button { openURL(URL(string: "https://developer.apple.com/documentation/appstoreconnectapi/creating-api-keys-for-app-store-connect-api")!) } label: { HStack(spacing: 4) { Text("How to create a key"); Image(systemName: "arrow.up.right").font(.system(size: 10, weight: .semibold)) } } .buttonStyle(.tide(.quiet, size: .small)).padding(.leading, -10).padding(.top, -6) ViewThatFits(in: .horizontal) { HStack(alignment: .top, spacing: 16) { keyIDField.frame(width: 240); vendorField.frame(width: 240); Spacer(minLength: 0) } VStack(alignment: .leading, spacing: 14) { keyIDField; vendorField } } TideField("Issuer ID", text: $issuerID, placeholder: "57246542-96fe-1a63-e053-0824d011072a", help: "Above the list of keys in Users and Access › Integrations.", error: err(issuerError), monospaced: true) VStack(alignment: .leading, spacing: 6) { Text("Private key").font(Tide.fieldLabel).foregroundStyle(Tide.ink) FileDropWell(file: $key, error: showErrors && key == nil ? "Choose the AuthKey_….p8 file you downloaded from App Store Connect." : nil) { file in if keyID.isEmpty, let match = file.name.firstMatch(of: /AuthKey_([A-Z0-9]{10})\.p8/) { keyID = String(match.1); keyIDHelp = "Filled in from the file name." } } Text("Apple lets you download this file only once, so keep the original somewhere safe. Graphley keeps a copy in your Keychain.") .font(Tide.caption).foregroundStyle(Tide.muted).fixedSize(horizontal: false, vertical: true) } if let failure { Label(failure, systemImage: "exclamationmark.circle.fill").font(Tide.secondary).foregroundStyle(Tide.downText) .fixedSize(horizontal: false, vertical: true) } HStack(spacing: 8) { Spacer() if replacing { Button("Cancel") { self.replacing = false; failure = nil }.buttonStyle(.tide(.quiet)) } Button { save() } label: { if saving { Label("Checking with Apple…", systemImage: "hourglass") } else { Text("Save Key") } } .buttonStyle(.tide(.primary)) .disabled(saving) } RowDivider() TideDisclosure("Or let your agent do it", isOpen: $agentOpen) { Text("Paste this into Claude Code, Codex or another agent connected to Graphley. It includes what you've typed above.") .font(Tide.secondary).foregroundStyle(Tide.muted).fixedSize(horizontal: false, vertical: true) CopyBlock(agentPrompt(replacing: replacing), wraps: true) ToggleRow("Let agents set keys", detail: model.workspace.settings.agentsCanSetKeys ? "On. Turn it off again after your agent saves the key." : "Off. Your agent can't save keys until you turn this on.", isOn: Binding(get: { model.workspace.settings.agentsCanSetKeys }, set: { v in model.updateSettings { $0.agentsCanSetKeys = v } })) } } var keyIDField: some View { TideField("Key ID", text: Binding(get: { keyID }, set: { keyID = $0.uppercased().trimmingCharacters(in: .whitespacesAndNewlines) }), placeholder: "2X9R4HXF34", help: keyIDHelp, error: err(keyIDError), monospaced: true) } var vendorField: some View { TideField("Vendor number", text: Binding(get: { vendor }, set: { vendor = $0.trimmingCharacters(in: .whitespacesAndNewlines) }), placeholder: "85123456", help: "Payments and Financial Reports, top left.", error: err(vendorError), monospaced: true) } func err(_ message: String?) -> String? { showErrors ? message : nil } var keyIDError: String? { keyID.wholeMatch(of: /[A-Z0-9]{10}/) == nil ? "Key IDs are 10 letters and numbers, like 2X9R4HXF34." : nil } var issuerError: String? { let t = issuerID.trimmingCharacters(in: .whitespacesAndNewlines).lowercased() return t.wholeMatch(of: /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/) == nil ? "Issuer IDs look like 57246542-96fe-1a63-e053-0824d011072a." : nil } var vendorError: String? { vendor.isEmpty || !vendor.allSatisfy(\.isNumber) ? "Vendor numbers are digits only, like 85123456." : nil } func agentPrompt(replacing: Bool) -> String { let path = key?.path ?? "the AuthKey_….p8 file in my Downloads folder" var lines = [ "Save my App Store Connect API key in Graphley with its set_app_store_key tool.", "Key ID: \(keyID.isEmpty ? "" : keyID)", "Issuer ID: \(issuerID.isEmpty ? "" : issuerID.trimmingCharacters(in: .whitespaces).lowercased())", "Vendor number: \(vendor.isEmpty ? "" : vendor)", "The private key is \(path). The tool reads it from the GRAPHLEY_ASC_PRIVATE_KEY environment variable of Graphley's MCP server, so restart that server with the variable set to the file's contents. Don't show the key's contents in our chat." ] if replacing { lines.append("Replace the key that's already saved.") } return lines.joined(separator: "\n") } func save() { showErrors = true; failure = nil guard keyIDError == nil, issuerError == nil, vendorError == nil, let key else { return } let creds = AppStoreConnect.Credentials(keyID: keyID, issuerID: issuerID.trimmingCharacters(in: .whitespacesAndNewlines).lowercased(), vendorNumber: vendor, privateKey: key.pem) saving = true Task { do { try await AppStoreConnect().check(creds) try creds.save() self.key = nil; replacing = false; showErrors = false; justSaved = true model.keysChanged() } catch { failure = Self.message(for: error) } saving = false } } static func message(for error: Error) -> String { if case AnalyticsError.http(let code, let body) = error { if body.localizedCaseInsensitiveContains("vendor") { return "Apple doesn't recognize this vendor number. You'll find it in Payments and Financial Reports." } if code == 401 { return "Apple didn't accept this key. Check the Key ID and Issuer ID, and make sure the .p8 file belongs to this key." } if code == 403 { return "This key can't read sales reports. Create a key with the Sales and Reports role (Finance or Admin also work)." } } if error is URLError { return "Couldn't reach Apple. Check your internet connection and try again." } if error is CryptoKitError || "\(error)".contains("CryptoKit") { return "That file isn't an App Store Connect key. Choose the AuthKey_….p8 file you downloaded from App Store Connect." } return "Apple didn't accept this key. Check the four values and try again." } } /// Dashed well for the .p8: drop a file or choose one. Shows the file name, never its contents. struct FileDropWell: View { @Binding var file: AppStoreCard.KeyFile? var error: String? var onLoad: (AppStoreCard.KeyFile) -> Void @State private var targeted = false @State private var choosing = false @State private var readError: String? static let p8 = UTType(filenameExtension: "p8", conformingTo: .data) ?? .data var body: some View { let shownError = readError ?? error VStack(alignment: .leading, spacing: 6) { Group { if let file { HStack(spacing: 10) { Image(systemName: "doc.fill").font(.system(size: 16)).foregroundStyle(Tide.accent) VStack(alignment: .leading, spacing: 2) { Text(file.name).font(Tide.figure(13)).foregroundStyle(Tide.ink) Text("Ready to save. It goes to your Keychain.").font(Tide.caption).foregroundStyle(Tide.muted) } Spacer() Button("Replace…") { choosing = true }.buttonStyle(.tide(.quiet, size: .small)) Button { self.file = nil } label: { Label("Remove file", systemImage: "xmark") }.buttonStyle(.tideIcon).help("Remove file") } .padding(.horizontal, 14) } else { HStack(spacing: 8) { Image(systemName: "key.horizontal").font(.system(size: 18)).foregroundStyle(Tide.muted) Text(targeted ? "Release to add the key" : "Drop your .p8 key file here, or").font(Tide.sans(13)).foregroundStyle(Tide.ink2) if !targeted { Button("Choose File…") { choosing = true }.buttonStyle(.tide(.quiet, size: .small)) } } .frame(maxWidth: .infinity) } } .frame(maxWidth: .infinity, minHeight: 76) .background(targeted ? Tide.accentTint : file != nil ? Tide.surface : Tide.ground, in: RoundedRectangle(cornerRadius: 10)) .overlay { RoundedRectangle(cornerRadius: 10).strokeBorder( shownError != nil ? Tide.down : targeted ? Tide.accent : file != nil ? Tide.line : Tide.line2, style: StrokeStyle(lineWidth: file != nil && shownError == nil ? 1 : 1.5, dash: file == nil && !targeted && shownError == nil ? [5, 4] : [])) } .onDrop(of: [.fileURL], isTargeted: $targeted) { providers in guard let provider = providers.first else { return false } _ = provider.loadObject(ofClass: URL.self) { url, _ in guard let url else { return } Task { @MainActor in load(url) } } return true } .fileImporter(isPresented: $choosing, allowedContentTypes: [Self.p8, .data]) { result in if let url = try? result.get() { load(url) } } .accessibilityElement(children: .contain) .accessibilityLabel("Choose .p8 key file") if let shownError { Label(shownError, systemImage: "exclamationmark.circle.fill").font(Tide.caption).foregroundStyle(Tide.downText) .fixedSize(horizontal: false, vertical: true) } } } func load(_ url: URL) { let scoped = url.startAccessingSecurityScopedResource(); defer { if scoped { url.stopAccessingSecurityScopedResource() } } guard let data = try? Data(contentsOf: url), data.count < 4096, let pem = String(data: data, encoding: .utf8), pem.contains("-----BEGIN \("")PRIVATE KEY-----"), AppStoreConnect.Credentials.isValidPrivateKey(pem) else { readError = "That file isn't an App Store Connect key. Choose the AuthKey_….p8 file you downloaded from App Store Connect." return } readError = nil let f = AppStoreCard.KeyFile(name: url.lastPathComponent, path: (url.path as NSString).abbreviatingWithTildeInPath, pem: pem) file = f onLoad(f) } } // MARK: Problems /// Plain-language refresh problems, each with the button that fixes it. The raw error is under Details. struct ProblemsCard: View { @Environment(AppModel.self) private var model @State private var details = false var body: some View { let failures = model.failures.sorted { $0.key < $1.key } TideCard("Last refresh needs attention", padding: 20) { StatusPill("Needs attention", .attention) } content: { VStack(alignment: .leading, spacing: 0) { ForEach(Array(failures.enumerated()), id: \.element.key) { i, f in if i > 0 { RowDivider() } let explained = Self.explain(source: f.key, error: f.value) let message = explained.0, action = explained.1 HStack(alignment: .center, spacing: 12) { VStack(alignment: .leading, spacing: 2) { Text(f.key).font(Tide.rowTitle).foregroundStyle(Tide.ink) Text(message).font(Tide.secondary).foregroundStyle(Tide.ink2).fixedSize(horizontal: false, vertical: true) } Spacer() if let action { Button(action) { Task { await model.refresh() } }.buttonStyle(.tide(.secondary, size: .small)).disabled(model.refreshing) } } .padding(.vertical, 10) } } TideDisclosure("Details", isOpen: $details) { CopyBlock(failures.map { "\($0.key): \($0.value)" }.joined(separator: "\n"), wraps: true) } Text("Graphley refreshes every day at \(SettingsView.hourLabel(model.workspace.settings.refreshHour)). Change the time in Settings.") .font(Tide.caption).foregroundStyle(Tide.muted) } } static func explain(source: String, error: String) -> (String, String?) { let e = error.lowercased() let apple = source.hasPrefix("App Store") if source == "iCloud sync" { return ("Couldn't share with your iPhone. Make sure this Mac is signed in to iCloud.", nil) } if e.contains("invalid_grant") || e.contains("sign in to google") { return ("Google sign-in has ended. Sign in again above.", nil) } if e.contains("(401)") && apple { return ("Apple didn't accept the App Store Connect key. Replace it above.", nil) } if e.contains("(403)") && apple { return ("The App Store Connect key can't read sales reports.", nil) } if e.contains("(403)") { return ("This Google account can't read this property anymore.", nil) } if e.contains("(429)") || e.contains("(5") { return ("\(apple ? "Apple" : "Google") was busy. Graphley will try again at the next refresh.", "Retry") } if e.contains("offline") || e.contains("timed out") || e.contains("network") || e.contains("internet") { return ("Couldn't reach \(apple ? "Apple" : "Google"). Check your internet connection.", "Retry") } return ("Something went wrong reading \(source). Graphley will try again at the next refresh.", "Retry") } }