Graphley / app · graphley.ai / Apps / iPhone / ConnectMac.swift
| 1 | import SwiftUI |
| 2 | import UIKit |
| 3 | import AnalyticsKit |
| 4 | import AnalyticsUI |
| 5 | |
| 6 | /// First run on iPhone and iPad, before any numbers arrive: how to connect Graphley for Mac, the same |
| 7 | /// "set up your Mac" pattern as Inkspring's and OpenTalon's companion apps, with this device's iCloud status. |
| 8 | struct ConnectMacGuide: View { |
| 9 | @Environment(PhoneModel.self) private var model |
| 10 | /// Opens iCloud Sync settings (a tab on iPhone, a sidebar row on iPad). |
| 11 | let openSettings: () -> Void |
| 12 | |
| 13 | static let downloadURL = URL(string: "https://graphley.ai/download")! |
| 14 | private var device: String { UIDevice.current.userInterfaceIdiom == .pad ? "iPad" : "iPhone" } |
| 15 | |
| 16 | var body: some View { |
| 17 | VStack(alignment: .leading, spacing: 20) { |
| 18 | VStack(alignment: .leading, spacing: 12) { |
| 19 | TideMark(size: 64).accessibilityHidden(true) |
| 20 | Text("Connect Graphley for Mac").font(Tide.screenTitle).foregroundStyle(Tide.ink) |
| 21 | .accessibilityAddTraits(.isHeader) |
| 22 | Text("Graphley for Mac fetches your Google Analytics and App Store numbers. This \(device) shows them through your private iCloud.") |
| 23 | .font(Tide.text).foregroundStyle(Tide.muted).fixedSize(horizontal: false, vertical: true) |
| 24 | } |
| 25 | TideCard("Set up your Mac", icon: "desktopcomputer") { |
| 26 | VStack(alignment: .leading, spacing: 18) { |
| 27 | step(1, "Get Graphley for Mac", "Download the free app from graphley.ai, open it and add a site or app.") |
| 28 | Link(destination: Self.downloadURL) { |
| 29 | Label("Get Graphley for Mac", systemImage: "arrow.down.circle") |
| 30 | } |
| 31 | .buttonStyle(.tide(.primary)) |
| 32 | .padding(.leading, 42) |
| 33 | .accessibilityIdentifier("connect.macDownload") |
| 34 | step(2, "Turn on sharing", "In Graphley on your Mac, open Settings and turn on Share with iPhone and iPad through iCloud.") |
| 35 | step(3, "Use the same Apple Account", "Sign in to iCloud with the same Apple Account on your Mac and this \(device). Your numbers appear here after the Mac's next refresh.") |
| 36 | } |
| 37 | } |
| 38 | TideCard("iCloud on this \(device)", icon: "icloud") { |
| 39 | VStack(alignment: .leading, spacing: 10) { |
| 40 | CloudSyncRow("Apple Account", model.cloud.accountStatus) |
| 41 | CloudSyncRow("Numbers from your Mac", CloudSyncText.snapshotStatus(model.cloud)) |
| 42 | if let error = model.cloud.error { |
| 43 | Text(error).font(Tide.secondary).foregroundStyle(Tide.muted).fixedSize(horizontal: false, vertical: true) |
| 44 | } |
| 45 | ViewThatFits(in: .horizontal) { |
| 46 | HStack(spacing: 8) { buttons } |
| 47 | VStack(alignment: .leading, spacing: 8) { buttons } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | Text("Graphley has no account and no server. Your keys stay in your Mac's Keychain.") |
| 52 | .font(Tide.caption).foregroundStyle(Tide.muted) |
| 53 | } |
| 54 | .frame(maxWidth: 560, alignment: .leading) |
| 55 | .accessibilityIdentifier("connectMac") |
| 56 | } |
| 57 | |
| 58 | @ViewBuilder private var buttons: some View { |
| 59 | Button { Task { await model.load() } } label: { |
| 60 | Label(model.loading ? "Checking iCloud…" : "Check Now", systemImage: "arrow.clockwise") |
| 61 | } |
| 62 | .buttonStyle(.tide(.secondary)).disabled(model.loading) |
| 63 | Button("iCloud Sync Settings", action: openSettings).buttonStyle(.tide(.quiet)) |
| 64 | } |
| 65 | |
| 66 | private func step(_ number: Int, _ title: String, _ detail: String) -> some View { |
| 67 | HStack(alignment: .top, spacing: 12) { |
| 68 | Text("\(number)").font(Tide.sans(15, .semibold)).foregroundStyle(Tide.accent) |
| 69 | .frame(width: 30, height: 30).background(Tide.accent.opacity(0.12), in: Circle()) |
| 70 | .accessibilityHidden(true) |
| 71 | VStack(alignment: .leading, spacing: 4) { |
| 72 | Text(title).font(Tide.rowTitle).foregroundStyle(Tide.ink) |
| 73 | Text(detail).font(Tide.secondary).foregroundStyle(Tide.muted).fixedSize(horizontal: false, vertical: true) |
| 74 | } |
| 75 | } |
| 76 | .accessibilityElement(children: .combine) |
| 77 | } |
| 78 | } |