Cotton code
85 lines · 3.6 KB · SwiftRaw
// What this machine is CALLED, which is a fact about the system and not about// any screen that names it.//// One app, two hosts, and every screen draws on both — so a screen that writes// out "this phone" is writing a sentence that is false half the time it is// read. The Mac walk photographed the first one: `/settings`' opening section// is headed "This phone" on the Mac, above the Mac's own device name (walk// finding 21).//// **The branch is HERE rather than in the screen**: `ScreenPlatformSweepTests` fails any// file under `Screens/` that says `#if os(macOS)`, because a screen answering// "what is this on a Mac" is the first of two designs. `Platform/` is where the// app keeps what the two systems call the same thing by different names.//// CottonHost has its own "This Mac" words (`ThisMac/ThisMacStrings.swift`) for// the server-administration window, which is macOS-only and never runs on the// phone. This is the pair the SHARED screens say.// **Every gate screen names the machine it runs on** (29 Sep 2026: the// Removed screen and the join wait screen on a Mac said "This phone was// removed" and "Erase Cotton from this iPhone"). The boot and Join sentences// in `Strings+Boot.swift` take their noun from here, or — where the Mac's// sentence is a different sentence, not the same one with another noun — are// written out for each machine through `sentence(phone:mac:)`.// `GateScreensNameTheirMachineTests` reads every one of them as the Mac and as// the phone.import Foundation/// The name of the machine the app is running on.public enum HostNoun {    /// The two machines the app runs on.    public enum Machine: Sendable, Equatable, CaseIterable {        case phone        case mac        /// The machine this build was compiled for.        public static var compiled: Machine {            #if os(macOS)            return .mac            #else            return .phone            #endif        }    }    /// The machine the words are for. Always `Machine.compiled` in the app;    /// a test reads the OTHER machine's sentences by binding it for a scope    /// (`HostNoun.$machine.withValue(.phone) { … }`), which is how the Mac's    /// test run holds the phone's words too.    @TaskLocal public static var machine: Machine = .compiled    /// One sentence per machine, for the places where the Mac's sentence is    /// not the phone's with a different noun — a phone asks "your Mac", and    /// a Mac asking "your Mac" would be talking about itself.    public static func sentence(phone: @autoclosure () -> String, mac: @autoclosure () -> String) -> String {        switch machine {        case .phone: return phone()        case .mac: return mac()        }    }    /// Sentence-leading, as a heading: "This Mac" / "This phone".    public static var titleCase: String {        ShellLines.onThisHost("machines", "host.title")    }    /// Mid-sentence: "…stops syncing on this Mac" / "…on this phone".    public static var lowerCase: String {        ShellLines.onThisHost("machines", "host.lower")    }    /// The machine ALONE, with no "this": the Settings group that holds what    /// belongs to the app on this kind of machine rather than to the database —    /// "Phone" / "Mac".    public static var bare: String {        ShellLines.onThisHost("machines", "host.bare")    }    /// The product, by its own name: "iPhone" / "Mac". What a device is    /// called when it has no name of its own, and what Erase names.    public static var product: String {        ShellLines.onThisHost("machines", "host.product")    }}