// HIDDEN (CONTRACT-2 HIDDEN, the owner 26 Nov): his categories he keeps out of sight, and every title in any of them.// Outside, the core leaves them out of every answer; the phone never filters. You › Hidden, the last row of You, asks// the phone's own lock (DeviceLock, as Sites asks it) each time it opens, then the core's unlock (`cinemas.unlock`);// inside it is a small home (Carry on, each hidden category, a search over hidden titles alone) whose reads say// `hidden: true`. Leaving Hidden or the app shuts it at once (`cinemas.lock`). With no screen lock it opens and says// so honestly, with Set a screen lock (Sites' scheme, Cinemas' words).//// HIDE FROM SCREEN (the owner, 27 Nov): hidden is from the SCREEN, not from assistants: a hidden category and its titles// do not show in Cinemas until he opens You › Hidden behind the phone's lock. Reachable in every build. A hidden title// playing never names itself or shows its poster on the lock screen, Control Centre or a TV (FilmPlayback.nowPlaying).//// A category is hidden from its menu on Home or in You › Your categories ("Hide this category", then the Hide sheet's// honest line once); inside Hidden its menu says Stop hiding. Both come back with Undo.#if os(iOS)importCottonKitimportSwiftUIextensionCinemasModel {/// Whether Hidden can be reached: in every build (HIDE FROM SCREEN, the owner 27 Nov: what he wanted all along is/// hide from the screen, and he thought it was built). Kept as one switch so a walk can still ask where it stands.var hiddenReachable: Bool { true }/// Hidden's own place is showing: You, with Hidden first on its stack.var inHiddenPlace: Bool { tab == .you && paths[.you]?.first == .hidden }/// Whether a read here says `hidden: true`: only inside Hidden, once it is open.var hiddenReads: Bool { hidden.open && inHiddenPlace }/// You › Hidden: the phone's own lock first, every time it opens (or, with none, said so), then the core's unlock/// (`cinemas.unlock`), which the core gives only on that word and shuts on `cinemas.lock`.func openHidden() async {var isSet = DeviceLock.isSetvar passed: Bool? #if COTTON_DEV// A walk on a simulator (never the real build): `-cinemas-skip-lock` stands for a lock that passed,// `-cinemas-no-lock` for a phone with none.let arguments = ProcessInfo.processInfo.argumentsif arguments.contains("-cinemas-skip-lock") { isSet = true; passed = true }if arguments.contains("-cinemas-no-lock") { isSet = false } #endifif isSet {if passed == nil { passed = awaitDeviceLock.ask(CinemasWords.line("stream.hidden_unlock")) }guard passed == trueelse { return } }switchawait source.unlock(noLock: !isSet) {case .read(true): hidden.open = true hidden.noLock = !isSetFilmPlayback.hiddenChanged() tab = .you paths[.you] = [.hidden]case .read(false): say(CinemasWords.line("stream.hidden_locked"))case .refused(let line): say(line) } }/// Hidden's place shown or left: left, it shuts at once (`cinemas.lock`), and opens again only behind the lock.func hiddenShown(_ shown: Bool) {if !shown { lockHidden() } }/// Shut: the app left the screen, or he left Hidden. The core's unlock is shut, what was read inside is let go,/// and the screens stacked over Hidden close with it.func lockHidden() {let was = hidden.open hidden.open = falseif paths[.you]?.first == .hidden { paths[.you] = []if tab == .you { sheet = nil } }guard was else { return }// A hidden title playing on: the lock screen no longer names it.FilmPlayback.hiddenChanged()let source = self.sourceTask { _ = await source.lock() } changed() }/// Hide a category, or stop hiding it; the core's words, with the Undo it handed back, run exactly as handed (a/// Hide's carries a one-use token, so its Undo works on Home with Hidden shut).func hide(_ group: String, hidden: Bool) async {switchawait source.hide(group, hidden: hidden) {case .read(let done): changed()guard done.unchanged != trueelse { return }let source = self.sourcelet undo: (@Sendable () async -> Void)? = done.undo.map { handed in { @Sendable [weakself] inswitchawait source.undo(handed) {case .read(let undone):awaitself?.changed()iflet line = undone.line { awaitself?.say(line) }case .refused(let line):awaitself?.say(line) } } } say(done.line ?? CinemasWords.line("stream.done"), undo: undo)case .refused(let line): UINotificationFeedbackGenerator().notificationOccurred(.warning) say(line) } }}extensionCinemasModel {/// A hidden category the Bin holds, restored from inside Hidden (`cinemas.restore`): the core's words, then read again.func restoreNamed(_ act: CinemasNamedAct) async {switchawait source.named(act, id: nil) {case .read(let said): changed() say(said ?? CinemasWords.line("stream.done"))case .refused(let line): UINotificationFeedbackGenerator().notificationOccurred(.warning) say(line) } }}/// Hidden's state on the model.structCinemasHiddenState {/// The phone's lock passed (or the phone has none) and the core unlocked: Hidden shows.varopen = false/// The phone has no screen lock: Hidden opens, and says so.var noLock = false}// MARK: - The Hide sheet/// "Hide Rainy Sundays?": the honest line, once, then Hide or Cancel.structCinemasHideSheet: View {let model: CinemasModellet group: Stringlet name: Stringvar body: someView {ScrollView { VStack(alignment: .leading, spacing: 16) {Text(CinemasWords.line("stream.hide_title", ["group": name])) .font(CinemasType.title(28)) .foregroundStyle(CinemasInk.ink) .fixedSize(horizontal: false, vertical: true) .accessibilityAddTraits(.isHeader)Text(CinemasWords.line("stream.hide_line")) .font(CinemasType.body) .foregroundStyle(CinemasInk.quiet) .fixedSize(horizontal: false, vertical: true)CinemasButton(label: CinemasWords.line("stream.hide_act"), icon: "eye.slash") { model.sheet = nilTask { await model.hide(group, hidden: true) } } .accessibilityIdentifier("cinemas-hide-confirm")CinemasButton(label: CinemasWords.line("stream.group_cancel"), style: .outline) { model.sheet = nil } .accessibilityIdentifier("cinemas-hide-cancel") } .padding(.horizontal, CinemasInk.side) .padding(.top, 28) .padding(.bottom, 20) } .scrollBounceBehavior(.basedOnSize) .accessibilityIdentifier("cinemas-hide-sheet") }}// MARK: - You › Hidden/// Hidden's own small home: the honest line when the phone has no lock, a search over hidden titles alone, then the/// core's rows (Carry on, each hidden category), each with Stop hiding in its menu.structCinemasHiddenScreen: View {let model: CinemasModellet grow: Namespace.ID @State privatevar place: CinemasRead<CinemasHiddenPlace>? @State privatevar q = "" @State privatevar found: CinemasFound? @Environment(\.scenePhase) privatevar phasevar body: someView {ScrollView { VStack(alignment: .leading, spacing: 18) {CinemasPageTitle(text: CinemasWords.line("stream.hidden_place")) .padding(.horizontal, CinemasInk.side)switch place {case .read(let place)? where place.locked:// The core's unlock ran out: its words, and the lock asked again.CinemasButton(label: place.unlock ?? CinemasWords.line("stream.hidden_unlock"), icon: "lock") {Task { await model.openHidden() } } .padding(.horizontal, CinemasInk.side) .accessibilityIdentifier("cinemas-hidden-unlock")case .read(let place)?:iflet noLock = place.noLock { noLockCard(noLock, set: place.setLock) } search(place.searchHint ?? CinemasWords.line("stream.hidden_search_hint"))if !q.trimmingCharacters(in: .whitespaces).isEmpty { results } elseif place.rows.isEmpty {Text(place.empty ?? CinemasWords.line("stream.hidden_empty")) .font(CinemasType.body) .foregroundStyle(CinemasInk.quiet) .fixedSize(horizontal: false, vertical: true) .padding(.horizontal, CinemasInk.side) .accessibilityIdentifier("cinemas-hidden-empty") } else {ForEach(place.rows) { row inif row.act?.method == CottonMethod.cinemasBin {CinemasPlaceRow(title: row.title, count: row.count) { model.push(.hiddenBin) } .accessibilityIdentifier("cinemas-hidden-bin") } else {CinemasPosterRow(model: model, row: row, sizes: CinemasSizes(width: model.width), grow: grow) } } }case .refused(let line)?:CinemasRefused(line: line) { Task { await read() } }casenil:ProgressView().tint(CinemasInk.accent).frame(maxWidth: .infinity) } } .padding(.bottom, 24) } .background(CinemasInk.ground.ignoresSafeArea())// Nothing of Hidden in the app switcher's picture: covered as soon as the app is not in front. .overlay { if phase != .active { CinemasInk.ground.ignoresSafeArea() } } .task(id: model.generation) { await read() } .task(id: "\(model.generation)/\(q)") { await look() } .accessibilityIdentifier("cinemas-hidden") }privatefunc read() async {guard model.hidden.openelse { return } place = await model.source.hiddenPlace() }privatefunc look() async {let words = q.trimmingCharacters(in: .whitespaces)guard !words.isEmpty, model.hidden.openelse { found = nil; return }try? awaitTask.sleep(for: .milliseconds(180))guard !Task.isCancelled else { return } found = await model.source.search(words, hidden: true).answer }privatefunc noLockCard(_ line: String, set: String?) -> someView { VStack(alignment: .leading, spacing: 12) {Label {Text(line).font(CinemasType.body).foregroundStyle(CinemasInk.ink).fixedSize(horizontal: false, vertical: true) } icon: {Image(systemName: "lock.open").foregroundStyle(CinemasInk.accent) }iflet set {CinemasButton(label: set, style: .outline, height: 44) { DeviceLock.openSettings() } .accessibilityIdentifier("cinemas-hidden-set-lock") } } .padding(16) .background(RoundedRectangle(cornerRadius: 14, style: .continuous).fill(CinemasInk.raised)) .padding(.horizontal, CinemasInk.side) .accessibilityElement(children: .contain) .accessibilityIdentifier("cinemas-hidden-no-lock") }privatefunc search(_ hint: String) -> someView { HStack(spacing: 10) {Image(systemName: "magnifyingglass").foregroundStyle(CinemasInk.quiet).accessibilityHidden(true)TextField(text: $q, prompt: Text(hint).foregroundStyle(CinemasInk.faint)) { Text(hint) } .font(CinemasType.list) .foregroundStyle(CinemasInk.ink) .tint(CinemasInk.accent) .submitLabel(.search) .autocorrectionDisabled() .accessibilityIdentifier("cinemas-hidden-search") } .padding(.horizontal, 14) .frame(minHeight: 48) .background(RoundedRectangle(cornerRadius: 12, style: .continuous).fill(CinemasInk.raised)) .padding(.horizontal, CinemasInk.side) } @ViewBuilder privatevar results: someView {iflet found { VStack(alignment: .leading, spacing: 0) {ForEach(found.items) { item inButton { model.open(item, from: "hidden-search") } label: { HStack(spacing: 12) {CinemasPicture(key: item.poster, title: item.title, seed: item.id, art: item.art) .frame(width: 44, height: 66) .clipShape(RoundedRectangle(cornerRadius: 6, style: .continuous))Text(item.title).font(CinemasType.list).foregroundStyle(CinemasInk.ink).multilineTextAlignment(.leading)Spacer(minLength: 0) } .padding(.vertical, 8) .contentShape(Rectangle()) } .buttonStyle(CinemasPress()) .accessibilityIdentifier("cinemas-hidden-found-\(item.id)") }ForEach(found.groups) { group inButton { model.push(.row(id: "group:\(group.id)", title: group.name)) } label: {Label(group.name, systemImage: "square.stack") .font(CinemasType.list).foregroundStyle(CinemasInk.ink) .frame(maxWidth: .infinity, minHeight: 48, alignment: .leading) .contentShape(Rectangle()) } .buttonStyle(CinemasPress()) } } .padding(.horizontal, CinemasInk.side) .accessibilityElement(children: .contain) .accessibilityIdentifier("cinemas-hidden-results") } }}#endif