#if os(iOS)import OSLogimport UIKit/// THE PHONE'S HALF OF CLIPS: on coming to the front, what was copied in/// another app since is kept as a clip.////// iOS tells an app nothing while it is away, so the front is the moment./// Judged in the order that reads the least: the change count (nothing new,/// nothing read); the item's TYPES (a concealed or transient item is never/// read); and only then the text, which the core refuses when it is/// secret-shaped (a key, a card, a one-time code — `engine::clips`). Every/// skip is logged, because nothing on screen says a copy was passed over./// Under Settings › Cotton › Paste from Other Apps = Ask the read shows the/// system's alert; the Clips list's Paste button never does.@MainActorfinalclassPhoneClipboard {staticlet shared = PhoneClipboard()privatevar keeper: ClipKeeper?privatevar seen: Int?privatestaticlet log = Logger(subsystem: "com.cottondb.clips", category: "phone")/// Keep the copy made since the last look, into the personal database/// (`personal`: made once, on the first look — the app's own core is the/// personal database's for the life of the process).func foreground(personal: () -> any Records, thisDevice: () async -> String?, board: UIPasteboard = .general) async {let keeper = self.keeper ?? ClipKeeper(store: personal())self.keeper = keeper// Off until the person turns it on on this phone's own page (owner,// 14 Oct 2026): under Ask the read below raises iOS's paste alert.guardawait keeper.deviceAllows("clips_on_open", device: await thisDevice(), otherwise: false) else {returnSelf.log.notice("skipped: this phone's clips_on_open is off or unread") }let count = board.changeCountguard count != seen else { returnSelf.log.notice("skipped: nothing copied since the last look") } seen = countguard board.hasStrings || board.hasURLs else { returnSelf.log.notice("skipped: the copy holds no text") }let types = Set(board.types)guard !ClipCapture.refuses(types: types) else { returnSelf.log.notice("skipped: the copy is marked concealed or transient") }guardlet text = board.string else { returnSelf.log.notice("skipped: the text was not given (paste declined)") }let kept = await keeper.keep(CopiedText(text: text, types: types, sourceDevice: UIDevice.current.name))Self.log.notice("\(kept ? "kept the copy" : "skipped: refused, a duplicate, or no Clips table yet", privacy: .public)") }}#endif