// A link handed to Sites (`cottonsites://open?url=…&from=post`, Comms' and Post's Open in Sites), held until Sites' list// is up. On a cold launch the scene hands the link over while only the splash stands (the core still opening), so a// handler on SitesRoot would never see it; the app's top level holds it here and SitesRoot takes it once ready.importFoundationimportObservation@MainActor @ObservablepublicfinalclassSitesLinkInbox {publicstaticlet shared = SitesLinkInbox()/// A link handed over and not yet taken: the page to open and who handed it.structHeld: Equatable {var url: Stringvar from: String? }private(set) var held: Held?/// The last link taken, and when: the same hand-over reaching a second handler is not opened twice. @ObservationIgnored privatevar taken: (link: Held, at: Date)?/// Holds `link` when it is a Sites open link; true when it was one (whoever handles links stops there). @discardableResultpublicfunc hold(_ link: URL) -> Bool {guardSitesRoot.applies, let parsed = Self.parse(link) else { returnfalse } keep(parsed)returntrue }func keep(_ link: Held) {if held == link { return }iflet taken, taken.link == link, Date().timeIntervalSince(taken.at) < 2 { return } held = link }/// The held link, once: SitesRoot opens the chooser on it.func take() -> Held? {guardlet link = held else { returnnil } held = nil taken = (link, Date())return link }staticfunc parse(_ link: URL) -> Held? {guardlet parts = URLComponents(url: link, resolvingAgainstBaseURL: false), parts.host == "open",let url = parts.queryItems?.first(where: { $0.name == "url" })?.value, !url.isEmpty else { returnnil }returnHeld(url: url, from: parts.queryItems?.first(where: { $0.name == "from" })?.value) }}