import Foundation /// The core's `status` answer: what the popover draws. struct CoreStatus: Decodable, Sendable, Equatable { var signedIn: Bool var signedOut: Bool var host: String? var phone: String? var lastPushAt: String? var sources: [SourceStatus] /// This Mac's vault key, once a pass has looked: none before the first. var vault: VaultLine? /// Why this Mac was signed out, for the sign-in screen: the core's words. var signInNote: String? /// The words of the button that asks a signed-in phone to approve this Mac. var askButton: String? /// The panel as the person sees it, decided by the core (`crates/cotton-mac/src/panel.rs`). var panel: Panel? struct Panel: Decodable, Sendable, Equatable { /// signIn | step | working var screen: String var heading: String? var line: String? var headline: Headline? var rows: [Row]? var account: Account /// The source pages' words, as the lines hold them (`{address}` and the like filled here). var page: [String: String]? struct Headline: Decodable, Sendable, Equatable { var line: String var sub: String? var needs: Bool var progress: Fraction? } struct Fraction: Decodable, Sendable, Equatable { var done: Int var total: Int } struct Row: Decodable, Sendable, Equatable, Identifiable { var source: String var title: String /// ok | bringing | paused | problem | add | unavailable var kind: String var line: String var act: String? var paused: Bool /// Bring everything in again is asked or under way: the page says so until that run ends. var again: Bool? /// Mail's walk through the whole mailbox, while it goes on: "Older mail: back to March 2015 · 41,200 of 98,000". var history: String? var id: String { source } } struct Account: Decodable, Sendable, Equatable { var who: String? var signOut: String var updates: String var quit: String var quitLine: String? var quitAnyway: String? var cancel: String? var launchLine: String? } func word(_ key: String, _ fills: [String: String] = [:]) -> String { var said = page?[key] ?? "" for (name, value) in fills { said = said.replacingOccurrences(of: "{\(name)}", with: value) } return said } } struct VaultLine: Decodable, Sendable, Equatable { /// waiting (published, not approved yet) | open | trouble var state: String /// What the phone's Keys › Devices shows for this Mac, to match by eye. var fingerprint: String? /// The core's one sentence. var detail: String /// While not let in: the button that asks a signed-in phone, right here. var ask: String? /// While not let in: the button that signs this Mac out. var signOut: String? } } struct SourceStatus: Decodable, Sendable, Equatable { var source: String var schedule: String /// idle | running | paused | needs | error var phase: String var probe: Probe var progress: Progress? var lastBrought: Int var lastBroughtAt: String? var lastRunAt: String? var total: Int var error: String? struct Probe: Decodable, Sendable, Equatable { var ready: Bool var need: Need? var detail: String? } struct Need: Decodable, Sendable, Equatable { /// fullDiskAccess | pair | credentials var kind: String /// pair: the pairing under way, "code" or "qr"; none until one is picked. var by: String? var code: String? var qr: String? /// pair: WhatsApp's passkey step once it asks for one — asking (in /// Chrome), retry, sent, confirm, linking. var passkey: String? /// pair, passkey "confirm": the code the phone shows too. var confirm: String? } struct Progress: Decodable, Sendable, Equatable { var sent: Int var uploaded: Int var total: Int? } } /// The five sources, in row order. enum Source: String, CaseIterable, Sendable, Identifiable { case whatsapp, mail, photos, calls, texts var id: String { rawValue } var title: String { switch self { case .whatsapp: "WhatsApp" case .mail: "Mail" case .photos: "Photos" case .calls: "Calls" case .texts: "Texts" } } /// What one row this source brings is called, singular and plural. var noun: (one: String, many: String) { switch self { case .whatsapp: ("message", "messages") case .mail: ("email", "emails") case .photos: ("photo", "photos") case .calls: ("call", "calls") case .texts: ("text", "texts") } } /// What the files a run puts are called. var fileNoun: (one: String, many: String) { switch self { case .whatsapp: ("picture", "pictures") case .photos: ("file", "files") case .mail, .calls: ("file", "files") case .texts: ("picture", "pictures") } } /// Whether the source keeps Mail-style credentials in the keychain. var takesCredentials: Bool { self == .mail } }