Cotton code
88 lines · 3.5 KB · SwiftRaw
// A server's refusal of this phone, drawn ABOVE the app rather than instead// of it.//// `device_not_approved` and `device_bad_signature` are the server's answer// about this device's key — a roster or key mismatch, the case of a Mac// re-paired under a new key. They used to replace every screen with// `ServerRefusalScreen`, and the person's full copy — theirs, whole, on this// phone — sat unreadable behind it for as long as the server said no. With a// replica open the refusal is this banner: the title, what still works and// what is held, while everything under it reads as it always did, every write answers the// refusal's sentence (the core's `write_refusal`, `WriteGate` on this side),// and the mailboxes wait (`BootModel.holdsDrains`).//// **A revocation is not drawn here.** `device_revoked` is the owner's// deliberate removal — a lost phone is the case — and that phone keeps the// full-screen refusal with its erase: `READ_ONLY_REFUSALS` in// `CottonKit/BootGate.swift` is the rule, `BootModel.readOnly` is what this// is drawn off. The slip is `ServerRefusalScreen`'s pink torn paper at the// width of a banner.import CottonKitimport SwiftUIpublic struct ReadOnlyBanner: View {    private let refusal: ServerRefusal    @Environment(\.theme) private var theme    public init(refusal: ServerRefusal) {        self.refusal = refusal    }    public var body: some View {        Paper(dye: .pink, edge: .torn, seed: "read-only-\(refusal.code)", tilt: false, inset: 16) {            VStack(alignment: .leading, spacing: 8) {                Text(refusal.title)                    .paperTitle(17)                    .fixedSize(horizontal: false, vertical: true)                    .accessibilityIdentifier("read-only-title")                Text(CottonStrings.readOnlyBody)                    .paperRed(12.5)                    .fixedSize(horizontal: false, vertical: true)                    .accessibilityIdentifier("read-only-body")                Text(CottonStrings.readOnlyHeld)                    .paperRed(12.5)                    .fixedSize(horizontal: false, vertical: true)                    .accessibilityIdentifier("read-only-held")            }        }        .padding(.horizontal, ChromeKnobs.chromeSettingsMargin)        .padding(.top, 6)        .padding(.bottom, 8)        .accessibilityIdentifier("read-only-banner")    }}extension View {    /// The banner above this view when a refusal stands, and this view alone    /// when none does. A top inset rather than an overlay, so the content    /// under it moves down and nothing is covered — a banner is a line the    /// person reads past, never a wall.    public func readOnlyBanner(_ refusal: ServerRefusal?) -> some View {        safeAreaInset(edge: .top, spacing: 0) {            if let refusal {                ReadOnlyStanding(refusal: refusal)            }        }    }}/// The read-only card: Vault's look inside Cotton Vault, paper elsewhere.struct ReadOnlyStanding: View {    let refusal: ServerRefusal    @Environment(\.vaultLook) private var vaultLook    var body: some View {        #if os(iOS)        if let look = vaultLook { VaultReadOnlyCard(refusal: refusal, look: look) } else { ReadOnlyBanner(refusal: refusal) }        #else        ReadOnlyBanner(refusal: refusal)        #endif    }}extension EnvironmentValues {    /// The sentence every write is refused with while this device reads    /// only (`WriteGate`), or nil while it writes.    @Entry var writeRefusal: String? = nil}