Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
iOS shell: long choices as a list, and a fixed top bar over the settings
v0lumehief7d5e463bfd
diff --git a/frontend-ios/README.md b/frontend-ios/README.mdindex 2a6ed668..f41fab72 100644--- a/frontend-ios/README.md+++ b/frontend-ios/README.md@@ -52,6 +52,8 @@ The caller returns changed values through `games`. The views keep no second copy| Part | What it does | Mirrors || --- | --- | --- || `GameCatalogue` | Scans `Games/<title ID>/`: `game.manifest.json` (schema 1, `GameManifest`), `launcher.json` (`LauncherProfile`, `docs/launcher.schema.json`, also read from `<framework>/<manifest.launcher>`), the manifest's `.framework` folder, optional `banner.<ext>` and `icon.<ext>`. A bundle that cannot be read stays in the list as broken with a readable reason (manifest missing, damaged or of another schema, framework missing, settings list damaged, folder and title ID disagree). | `docs/launcher-c-plan.md`, Manifest and Discovery |+| `GameCatalogue` (frameworks) | In the shell app the games are the embedded frameworks: `scan(root:)` also reads every `<Name>.framework` folder (pass `Bundle.main.privateFrameworksURL`). A framework without `game.manifest.json` is skipped silently. Otherwise the entry's ID is the manifest's `title_id` (the folder name without `.framework` when the manifest cannot be read), and `directory` and `frameworkURL` are the framework folder. `launcher.json` comes from `<manifest.launcher>`, else the framework's top level, and `banner.<ext>` and `icon.<ext>` from inside the framework. A manifest whose `framework` differs from the folder name is broken (Game files damaged). Of two frameworks with one title ID the first by name is kept and the second is broken, listed under its folder name. `CatalogueEntry.frameworkURL` is a stored property set by both readers. | `docs/launcher-c-plan.md`, Manifest |+| `EngineLaunchPlan` | A pure value from a `LaunchableGame`, the app's `Resources` and `Documents` folders and the text of `Documents/env.txt`: the environment the real launcher applies with `setenv` (`DM_PROFILE`, `DM_ROMFS`, `DM_SAVE`, `DM_TEMP`, `DM_NVN_SHMAP`, `DM_MSL_DIR`, `DM_PSO_BUNDLE`, `DM_AOC_DIR`, `DM_CHEATS`, `DM_FONT_DIR`, `DM_SAVE_SYNC`, `DM_LAUNCHER=0`, the player's settings, then env file keys that nothing else set, listed in `DM_ENV_FILE_KEYS`), the `dm_main` arguments (`dmhost`, `<framework>/dm`, the manifest's modules), the framework executable, the image marker, the log URL and the save and temp folders, which only `createFolders()` creates. `parseEnvFile(_:)` reads the `KEY=VALUE` lines. | `boot_env` in `dm/ios/Sources/main.m`, `docs/launcher-c-plan.md`, Environment at game start || `GameStateResolver` | Broken first, then needs app update (the manifest's `chain` differs from `HostEnvironment.chain`, or `min_os` is above the running OS), then needs game data, else playable. | the plan's playable, needsData, needsFramework and broken || `DataLocator` | The picked location first, then `Documents/games/<title ID>/`, each accepted only with a non-empty `romfs.img` or the manifest's `romfs_marker` (also under `romfs/`). A picked folder that lost its data falls through to the app folder. | `romfs_locate` in `dm/ios/Sources/main.m`, patch 0003's layout || `GameSettingsStore` | One `UserDefaults` suite per game (`dev.nx2apple.shell.game.<title ID>`), keys `launcher.<VAR>` holding strings. Only a value that differs from the tested default is stored, a saved value the game no longer offers reads as the default, and Reset forgets every saved choice. `SettingsPresenter` draws sections in the list's order and hides sub-settings (`needs`). | `dm/ios/Sources/LauncherSettings.swift` |@@ -92,6 +94,8 @@ Only the available size decides, never the device model, idiom or orientation (`Settings appear only when asked for (the settings button, X on a controller) and close with Back, B or a tap outside. They are one view in one place for every layout, with the game's banner as their header, so the selected game, open settings and both scroll positions survive a fold, a rotation or a Stage Manager resize.+Choice rows with 2 to 4 short labels that fit their equal segment (`ChoicePresentation.resolve`, by option count, label length, row width and Dynamic Type) are segmented. Every other choice is a compact row (label, current value, chevron) that opens a list in the shell's own card: D-pad moves, A picks and closes, B closes without a change, touch and keyboard work the same, the current value carries a checkmark. The settings keep a non-scrolling top bar with an opaque backing that holds Library, so scrolled content never shows under it.+Controller first: the D-pad and stick move a cream focus ring, A activates, B backs out, X opens settings, Y opens controllers. In Cover Flow, left and right move the carousel by one card and the focused card is always the middle one. A hardware keyboard works the same way: arrows, Return, Escape, O for settings and Y for controllers. Touch hides the focus ring and the controller hints until the next press. In Cover Flow the centred card is the button: a tap does what the game needs, a tap on a side card brings it to the middle, a long press opens its settings.Manrope and its SIL OFL licence are bundled and registered at runtime, with the system font as fallback. Reduce Motion turns the Cover Flow tilt and the slides into plain crossfades. Shell strings are in `Resources/Localizable.xcstrings`.diff --git a/frontend-ios/Sources/ShellDemo/SampleData.swift b/frontend-ios/Sources/ShellDemo/SampleData.swiftindex 8ecfb15d..381733f1 100644--- a/frontend-ios/Sources/ShellDemo/SampleData.swift+++ b/frontend-ios/Sources/ShellDemo/SampleData.swift@@ -31,7 +31,8 @@ func demoText(_ key: String.LocalizationValue) -> String {GameDetail(game: tile, sections: [SettingSection(id: "game", title: demoText("Game"), rows: [SettingRow(id: "DM_OPERATION_MODE", label: demoText("Play mode"), note: demoText("The game's display and performance profile."), kind: .choice([SettingOption("handheld", demoText("Handheld")), SettingOption("docked", demoText("Docked"))]), value: "handheld"),- SettingRow(id: "DM_SHOW_FPS", label: demoText("Show frame rate"), kind: .toggle(on: "1", off: "0"), value: "0")+ SettingRow(id: "DM_SHOW_FPS", label: demoText("Show frame rate"), kind: .toggle(on: "1", off: "0"), value: "0"),+ SettingRow(id: "DM_LANGUAGE", label: demoText("Language"), kind: .choice([SettingOption("en-US", demoText("American English")), SettingOption("en-GB", demoText("British English")), SettingOption("ja", demoText("Japanese")), SettingOption("fr", demoText("French")), SettingOption("de", demoText("German")), SettingOption("es-419", demoText("Latin American Spanish")), SettingOption("es", demoText("Spanish")), SettingOption("it", demoText("Italian")), SettingOption("nl", demoText("Dutch")), SettingOption("fr-CA", demoText("Canadian French")), SettingOption("ru", demoText("Russian")), SettingOption("ko", demoText("Korean")), SettingOption("zh-Hant", demoText("Traditional Chinese")), SettingOption("zh-Hans", demoText("Simplified Chinese")), SettingOption("pt-BR", demoText("Brazilian Portuguese"))]), value: "en-US")]),SettingSection(id: "controls", title: demoText("Controls"), rows: [SettingRow(id: "DM_PAD_MERGE", label: demoText("All controllers are player 1"), note: demoText("Use more than one controller for the same player."), kind: .toggle(on: "1", off: "0"), value: "0")diff --git a/frontend-ios/Sources/ShellUI/ChoicePicker.swift b/frontend-ios/Sources/ShellUI/ChoicePicker.swiftnew file mode 100644index 00000000..476a5b2b--- /dev/null+++ b/frontend-ios/Sources/ShellUI/ChoicePicker.swift@@ -0,0 +1,189 @@+import SwiftUI++/// How a choice row presents its options. Segmented cells work for a few short labels. Everything else is a compact+/// row that opens a list, so a long list never turns the settings into a wall of buttons.+enum ChoicePresentation: Equatable {+ case segmented+ case list++ /// More options than this never share a row of segments.+ static let maxSegments = 4+ /// Estimates for Manrope at the segment's 13.5 pt (bold, the widest case) and the cell's side padding.+ static let characterWidth: CGFloat = 7.6+ static let cellPadding: CGFloat = 28+ /// The track around the cells (3 pt each side) and the gap between cells.+ static let trackPadding: CGFloat = 6+ static let cellGap: CGFloat = 2++ /// The rule: segmented when there are 2 to `maxSegments` options and every label fits its equal segment on one+ /// line at `width` (the row's width, nil while unknown) and `textScale` (Dynamic Type, 1 at the default size).+ /// With no width yet only the count decides, and the view still falls back when the real layout does not fit.+ static func resolve(labels: [String], width: CGFloat?, textScale: CGFloat = 1) -> ChoicePresentation {+ guard labels.count >= 2, labels.count <= maxSegments else { return .list }+ guard let width else { return .segmented }+ let count = CGFloat(labels.count)+ let segment = (width - trackPadding - cellGap * (count - 1)) / count+ let widest = labels.map { CGFloat($0.count) * characterWidth * textScale + cellPadding }.max() ?? 0+ return widest <= segment ? .segmented : .list+ }++ /// Dynamic Type's growth of text, close to the system's body scale.+ static func textScale(_ size: DynamicTypeSize) -> CGFloat {+ switch size {+ case .xSmall: 0.82+ case .small: 0.88+ case .medium: 0.94+ case .large: 1+ case .xLarge: 1.12+ case .xxLarge: 1.23+ case .xxxLarge: 1.35+ case .accessibility1: 1.6+ case .accessibility2: 1.9+ case .accessibility3: 2.2+ case .accessibility4: 2.6+ case .accessibility5: 3.0+ @unknown default: 1+ }+ }+}++/// A choice the player is picking from a list: which row of which game, and its options.+struct ChoiceRequest: Equatable {+ let gameID: String+ let row: SettingRow+ var options: [SettingOption] {+ if case .choice(let options) = row.kind { options } else { [] }+ }+}++private struct ShellPickChoiceKey: EnvironmentKey {+ nonisolated(unsafe) static let defaultValue: ((ChoiceRequest) -> Void)? = nil+}+extension EnvironmentValues {+ /// Opens the list for a choice row. The library provides it.+ var shellPickChoice: ((ChoiceRequest) -> Void)? {+ get { self[ShellPickChoiceKey.self] }+ set { self[ShellPickChoiceKey.self] = newValue }+ }+}++/// The list of a choice's options with a checkmark on the current one. A card in the shell's style over the dimmed+/// settings. D-pad and keys move through `pick.<option>` targets, A or Return picks, B or Escape closes.+struct ChoicePickerView: View {+ let request: ChoiceRequest+ let pick: (String) -> Void+ let close: () -> Void+ @Environment(\.accessibilityReduceMotion) private var reduceMotion+ @Environment(\.shellFocus) private var focus++ var body: some View {+ ViewThatFits(in: .vertical) {+ content(scrolls: false)+ content(scrolls: true)+ }+ .frame(maxWidth: 460)+ .background(Color(red: 0.075, green: 0.075, blue: 0.082), in: RoundedRectangle(cornerRadius: 26))+ .overlay(RoundedRectangle(cornerRadius: 26).strokeBorder(.white.opacity(0.10)))+ .shadow(color: .black.opacity(0.5), radius: 40)+ .accessibilityElement(children: .contain)+ .accessibilityAddTraits(.isModal)+ .accessibilityIdentifier("choice.picker")+ }++ private func content(scrolls: Bool) -> some View {+ VStack(alignment: .leading, spacing: 0) {+ HStack(alignment: .center, spacing: 12) {+ VStack(alignment: .leading, spacing: 2) {+ Text(request.row.label).shellType(ShellType.flowTitle(20)).lineLimit(2)+ .accessibilityAddTraits(.isHeader).accessibilityIdentifier("choice.title")+ if !request.row.note.isEmpty {+ Text(request.row.note).shellType(ShellType.note).foregroundStyle(.white.opacity(0.5)).lineLimit(2)+ }+ }+ Spacer(minLength: 8)+ Button(action: close) {+ Image(systemName: "xmark").font(.system(size: 14, weight: .semibold)).frame(width: 44, height: 44)+ .background(.white.opacity(0.08), in: Circle()).contentShape(Circle())+ }+ .buttonStyle(.plain)+ .accessibilityLabel(ShellStrings.text("Close"))+ .accessibilityIdentifier("choice.close")+ .shellTarget("pick.close", radius: 22, action: close)+ }+ .padding(.horizontal, 20).padding(.top, 14).padding(.bottom, 8)+ Rectangle().fill(ShellPalette.hairline).frame(height: 1)+ if scrolls {+ ScrollViewReader { proxy in+ ScrollView { list }+ .scrollIndicators(.hidden)+ .onAppear { proxy.scrollTo("pick.\(request.row.value)", anchor: .center) }+ .onChange(of: focus.id) { _, id in+ guard let id, id.hasPrefix("pick.") else { return }+ withAnimation(reduceMotion ? nil : .easeOut(duration: 0.15)) {+ proxy.scrollTo(id, anchor: id == "pick.close" ? .top : .center)+ }+ }+ }+ } else {+ list+ }+ }+ }++ private var list: some View {+ VStack(spacing: 4) {+ ForEach(request.options) { option in+ let chosen = request.row.value == option.id+ Button { pick(option.id) } label: {+ HStack(spacing: 12) {+ Text(option.label).shellText(15, chosen ? .bold : .medium).fixedSize(horizontal: false, vertical: true)+ Spacer(minLength: 8)+ if chosen { Image(systemName: "checkmark").font(.system(size: 14, weight: .bold)).accessibilityHidden(true) }+ }+ .padding(.horizontal, 14).padding(.vertical, 8).frame(minHeight: 44)+ .foregroundStyle(chosen ? ShellPalette.cream : .white.opacity(0.8))+ .background(.white.opacity(chosen ? 0.09 : 0.0), in: RoundedRectangle(cornerRadius: 10))+ .contentShape(RoundedRectangle(cornerRadius: 10))+ }+ .buttonStyle(.plain)+ .accessibilityLabel(option.label)+ .accessibilityAddTraits(chosen ? .isSelected : [])+ .accessibilityIdentifier("choice.option.\(option.id)")+ .shellTarget("pick.\(option.id)", radius: 10) { pick(option.id) }+ }+ }+ .padding(10)+ }+}++/// The compact choice row: the label on the left, the current value and a chevron on the right.+struct ChoiceValueRow: View {+ let row: SettingRow+ let valueLabel: String+ let open: () -> Void+ var body: some View {+ Button(action: open) {+ HStack(alignment: .center, spacing: 12) {+ VStack(alignment: .leading, spacing: 4) {+ Text(row.label).shellType(ShellType.settingLabel).fixedSize(horizontal: false, vertical: true)+ if !row.note.isEmpty {+ Text(row.note).shellType(ShellType.note).foregroundStyle(.white.opacity(0.5)).fixedSize(horizontal: false, vertical: true)+ }+ }+ Spacer(minLength: 8)+ Text(valueLabel).shellText(14.5, .semibold).foregroundStyle(ShellPalette.cream)+ .multilineTextAlignment(.trailing).fixedSize(horizontal: false, vertical: true)+ Image(systemName: "chevron.right").font(.system(size: 13, weight: .bold)).foregroundStyle(.white.opacity(0.4))+ .accessibilityHidden(true)+ }+ .padding(.horizontal, 14).padding(.vertical, 8).frame(minHeight: 48)+ .background(.white.opacity(0.055), in: RoundedRectangle(cornerRadius: 11))+ .overlay(RoundedRectangle(cornerRadius: 11).strokeBorder(.white.opacity(0.08)))+ .contentShape(RoundedRectangle(cornerRadius: 11))+ }+ .buttonStyle(.plain)+ .accessibilityLabel(row.label)+ .accessibilityValue(valueLabel)+ .accessibilityHint(ShellStrings.text("Opens the list of choices"))+ }+}diff --git a/frontend-ios/Sources/ShellUI/GameDetailView.swift b/frontend-ios/Sources/ShellUI/GameDetailView.swiftindex 7aa172d2..0f522ba0 100644--- a/frontend-ios/Sources/ShellUI/GameDetailView.swift+++ b/frontend-ios/Sources/ShellUI/GameDetailView.swift@@ -145,6 +145,9 @@ private struct SettingControl: View, Equatable {let change: (String) -> Voidnonisolated static func == (lhs: Self, rhs: Self) -> Bool { lhs.gameID == rhs.gameID && lhs.row == rhs.row }@Environment(\.dynamicTypeSize) private var typeSize+ @Environment(\.shellPickChoice) private var pickChoice+ /// The row's width, once measured, for the segmented-or-list rule.+ @State private var width: CGFloat?var body: some View {VStack(alignment: .leading, spacing: 12) {switch row.kind {@@ -153,16 +156,17 @@ private struct SettingControl: View, Equatable {.toggleStyle(CreamToggleStyle()).shellTarget("set.row.\(row.id)", enabled: row.enabled) { change(row.value == on ? off : on) }case .choice(let options):- label- // Equal segments across the card. When the labels do not fit one row: two rows of equal cells, then a list.- if typeSize.isAccessibilitySize {- list(options)- } else {+ let labels = options.map(\.label)+ let scale = ChoicePresentation.textScale(typeSize)+ switch ChoicePresentation.resolve(labels: labels, width: width, textScale: scale) {+ case .segmented:+ // Equal segments across the card. If the real layout still cannot hold them, the compact row.ViewThatFits(in: .horizontal) {- segmented([options])- segmented(stride(from: 0, to: options.count, by: 2).map { Array(options[$0..<min($0 + 2, options.count)]) })- list(options)+ VStack(alignment: .leading, spacing: 12) { label; segmented([options]) }+ valueRow(options)}+ case .list:+ valueRow(options)}case .range(let min, let max, let step, let unit):HStack(alignment: .firstTextBaseline) {@@ -181,6 +185,7 @@ private struct SettingControl: View, Equatable {}}}.frame(maxWidth: .infinity, alignment: .leading)+ .onGeometryChange(for: CGFloat.self, of: { $0.size.width }) { new in if width.map({ abs($0 - new) > 0.5 }) ?? true { width = new } }.disabled(!row.enabled).opacity(row.enabled ? 1 : 0.45).accessibilityIdentifier("setting.\(row.id)")}@@ -216,27 +221,12 @@ private struct SettingControl: View, Equatable {.background(.white.opacity(0.055), in: RoundedRectangle(cornerRadius: 11)).overlay(RoundedRectangle(cornerRadius: 11).strokeBorder(.white.opacity(0.08)))}- private func list(_ options: [SettingOption]) -> some View {- VStack(alignment: .leading, spacing: 4) {- ForEach(options) { option in- let chosen = row.value == option.id- Button { change(option.id) } label: {- HStack {- Text(option.label).shellText(14, chosen ? .bold : .medium)- Spacer()- if chosen { Image(systemName: "checkmark").font(.system(size: 13, weight: .bold)) }- }- .padding(.horizontal, 14).frame(minHeight: 44)- .foregroundStyle(chosen ? ShellPalette.cream : .white.opacity(0.75))- .background(.white.opacity(chosen ? 0.08 : 0.03), in: RoundedRectangle(cornerRadius: 9))- .contentShape(RoundedRectangle(cornerRadius: 9))- }- .buttonStyle(.plain)- .accessibilityLabel(row.label + ", " + option.label)- .accessibilityAddTraits(chosen ? .isSelected : [])- .shellTarget("set.row.\(row.id).\(option.id)", enabled: row.enabled, radius: 9) { change(option.id) }- }+ /// Many or long options: label and current value in one compact row that opens the list.+ private func valueRow(_ options: [SettingOption]) -> some View {+ ChoiceValueRow(row: row, valueLabel: options.first { $0.id == row.value }?.label ?? row.value) {+ pickChoice?(ChoiceRequest(gameID: gameID, row: row))}+ .shellTarget("set.row.\(row.id)", enabled: row.enabled, radius: 11) { pickChoice?(ChoiceRequest(gameID: gameID, row: row)) }}private func rangeButton(_ symbol: String, min: Double, max: Double, delta: Double) -> some View {let action = { change(String(Swift.min(max, Swift.max(min, (Double(row.value) ?? min) + delta)))) }diff --git a/frontend-ios/Sources/ShellUI/LibraryView.swift b/frontend-ios/Sources/ShellUI/LibraryView.swiftindex ee46343f..88caeb91 100644--- a/frontend-ios/Sources/ShellUI/LibraryView.swift+++ b/frontend-ios/Sources/ShellUI/LibraryView.swift@@ -38,6 +38,8 @@ public struct LibraryView: View {@State private var controllersOpen: Bool/// The game whose How to fix or How to update explanation is open.@State private var helpGameID: String?+ /// The choice whose option list is open.+ @State private var choice: ChoiceRequest?@State private var focus: FocusAppearance@State private var targets = FocusTargetBuffer()@State private var settingsPosition = ScrollPosition()@@ -119,7 +121,7 @@ public struct LibraryView: View {.opacity(settingsOpen ? 1 : 0).frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing).allowsHitTesting(settingsOpen)- .accessibilityHidden(!settingsOpen)+ .accessibilityHidden(!settingsOpen || choice != nil).accessibilityAddTraits(settingsOpen ? .isModal : []).transformPreference(FocusTargets.self) { if !settingsOpen { $0.removeAll() } }}@@ -137,6 +139,15 @@ public struct LibraryView: View {.accessibilityAddTraits(.isModal).transition(.opacity.combined(with: .scale(scale: 0.96)))}+ if let choice {+ Color.black.opacity(0.55).ignoresSafeArea().accessibilityHidden(true)+ .onTapGesture { closeChoice() }+ .transition(.opacity)+ ChoicePickerView(request: choice, pick: pickChoice, close: closeChoice)+ .padding(.horizontal, 16).padding(.vertical, 12)+ .frame(maxWidth: .infinity, maxHeight: .infinity)+ .transition(.opacity.combined(with: .scale(scale: 0.96)))+ }if controllersOpen {Color.black.opacity(0.55).ignoresSafeArea().accessibilityHidden(true).onTapGesture { back() }@@ -154,7 +165,8 @@ public struct LibraryView: View {values = values.filter { target inif controllersOpen { return target.id.hasPrefix("ctl.") }if helpGameID != nil { return target.id.hasPrefix("help.") }- return !target.id.hasPrefix("ctl.") && !target.id.hasPrefix("help.")+ if choice != nil { return target.id.hasPrefix("pick.") }+ return !target.id.hasPrefix("ctl.") && !target.id.hasPrefix("help.") && !target.id.hasPrefix("pick.")}}.coordinateSpace(name: "shell")@@ -166,6 +178,8 @@ public struct LibraryView: View {.animation(reduceMotion ? nil : .smooth(duration: 0.3), value: settingsOpen).animation(reduceMotion ? nil : .smooth(duration: 0.3), value: controllersOpen).animation(reduceMotion ? nil : .smooth(duration: 0.25), value: helpGameID)+ .animation(reduceMotion ? nil : .smooth(duration: 0.25), value: choice)+ .environment(\.shellPickChoice, { request in openChoice(request) }).environment(\.shellShowHelp, { game in openHelp(game.id) }).environment(\.shellFocus, focus).environment(\.shellInputDevice, device)@@ -211,18 +225,22 @@ public struct LibraryView: View {/// the primary action and the setting groups. A panel or the whole screen, the same view. Full screen, the banner/// runs under the status bar and the settings scroll under the home indicator, while Back keeps its inset.private func settingsPane(_ selected: GameDetail, floating: Bool, width: CGFloat, insets: EdgeInsets) -> some View {- ZStack(alignment: .topLeading) {+ // The bar holds Back and never scrolls: an opaque page-coloured band from the top edge of the screen (under the+ // status bar) to below the button, so the content scrolls beneath it and never shows through.+ let barHeight = insets.top + Self.barContentHeight+ return ZStack(alignment: .top) {ScrollViewReader { proxy inScrollView {VStack(alignment: .leading, spacing: 0) {PaneBanner(game: selected.game, width: width + insets.leading + insets.trailing,- leading: insets.leading, trailing: insets.trailing, topInset: insets.top).id("set.top")+ leading: insets.leading, trailing: insets.trailing, topInset: 0).id("set.top")GameDetailView(detail: selected, actions: actions, showsPrimaryAction: true, showsHeader: false).padding(.horizontal, 24).padding(.top, 18).padding(.bottom, 32 + insets.bottom)// A phone on its side: a readable column, not rows stretched across the whole width..frame(maxWidth: 640, alignment: .leading).padding(.leading, insets.leading).padding(.trailing, insets.trailing)}+ .padding(.top, barHeight).frame(maxWidth: .infinity, alignment: .leading)}.scrollPosition($settingsPosition)@@ -231,21 +249,32 @@ public struct LibraryView: View {.onChange(of: focus.id) { _, id inguard let id, id.hasPrefix("set.") else { return }withAnimation(reduceMotion ? nil : .easeOut(duration: 0.18)) {- proxy.scrollTo(id == "set.back" ? "set.top" : id, anchor: id == "set.back" ? .top : .center)+ proxy.scrollTo(id, anchor: id == "set.back" ? .top : .center)}}}- Button(action: closeSettings) {- if typeSize.isAccessibilitySize { Image(systemName: "chevron.left").frame(minWidth: 24) }- else { Label(ShellStrings.text("Library"), systemImage: "chevron.left") }+ HStack(spacing: 0) {+ Button(action: closeSettings) {+ if typeSize.isAccessibilitySize { Image(systemName: "chevron.left").frame(minWidth: 24) }+ else { Label(ShellStrings.text("Library"), systemImage: "chevron.left") }+ }+ .buttonStyle(ChipButtonStyle())+ .accessibilityLabel(ShellStrings.text("Library"))+ .accessibilityIdentifier("library.back")+ .shellTarget("set.back", radius: 22, action: closeSettings)+ Spacer(minLength: 0)+ }+ .padding(.leading, 16 + insets.leading).padding(.trailing, 16 + insets.trailing)+ .frame(height: Self.barContentHeight, alignment: .center)+ .background(alignment: .top) {+ ShellPalette.background.overlay(alignment: .bottom) { Rectangle().fill(ShellPalette.hairline).frame(height: 1) }+ .ignoresSafeArea(edges: [.top, .horizontal])}- .buttonStyle(ChipButtonStyle())- .accessibilityLabel(ShellStrings.text("Library"))- .accessibilityIdentifier("library.back")- .shellTarget("set.back", radius: 22, action: closeSettings)- .padding(.leading, 16).padding(.top, 6)+ .accessibilityElement(children: .contain)}}+ /// The settings' top bar below the status bar: the Back button and its margins.+ private static let barContentHeight: CGFloat = 56// MARK: Actions and focus@@ -284,8 +313,26 @@ public struct LibraryView: View {private func openControllers() { noteTouch(); controllersOpen = true; focus.id = "ctl.close" }private func openHelp(_ id: String) { returnFocus = focus.id; helpGameID = id; focus.id = "help.done" }private func closeHelp() { helpGameID = nil; focus.id = returnFocus }+ private func openChoice(_ request: ChoiceRequest) {+ noteTouch()+ returnFocus = focus.id+ choice = request+ focus.id = "pick.\(request.row.value)"+ }+ private func closeChoice() {+ guard let request = choice else { return }+ choice = nil+ focus.id = "set.row.\(request.row.id)"+ }+ private func pickChoice(_ value: String) {+ noteTouch()+ guard let request = choice else { return }+ if value != request.row.value { actions.onChange(request.gameID, request.row.id, value) }+ closeChoice()+ }private func back() {- if helpGameID != nil { closeHelp() }+ if choice != nil { closeChoice() }+ else if helpGameID != nil { closeHelp() }else if controllersOpen { controllersOpen = false; focus.id = "lib.controllers" }else if settingsOpen { closeSettings() }else { actions.onBack() }@@ -325,6 +372,7 @@ public struct LibraryView: View {if let id = focus.id, id.hasPrefix("lib.tile.") { select(String(id.dropFirst("lib.tile.".count))) }}private var defaultFocus: String? {+ if let choice { return "pick.\(choice.row.value)" }if helpGameID != nil { return "help.done" }if controllersOpen { return "ctl.close" }if settingsOpen { return "set.back" }diff --git a/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift b/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swiftindex 8b06a88d..808fcd3c 100644--- a/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift+++ b/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift@@ -210,6 +210,28 @@ final class Clock: @unchecked Sendable { var date: Date; init(_ d: Date) { date#expect(game.cloudSavesURL == nil && model.notice == nil)}+ /// What the player changes in the settings (the views' onChange) is what the engine gets: the launcher's environment, and the+ /// engine launch plan built from it, which the shell sets before the engine reads anything (front_hud_env, dm_profile, hle_oe).+ @Test func aChangedSettingReachesTheEngineEnvironment() async throws {+ let box = try Sandbox()+ try box.giveAppData()+ let launcher = RecordingLauncher()+ let model = ShellHostModel(config: box.config(), launcher: launcher)+ model.actions.onChange(Fixtures.orbit, "DM_SHOW_FPS", "1")+ model.actions.onChange(Fixtures.orbit, "DM_OPMODE", "0")+ await model.playNow(Fixtures.orbit)+ let game = try #require(launcher.launched.first)+ #expect(game.environment["DM_SHOW_FPS"] == "1" && game.environment["DM_OPMODE"] == "0")+ let plan = EngineLaunchPlan.make(game: game, appResources: box.root.appendingPathComponent("App"), documents: box.root.appendingPathComponent("Documents"),+ envFileText: "DM_SHOW_FPS=0\nDM_OTHER=7\n")+ #expect(plan.environment["DM_SHOW_FPS"] == "1", "the player's choice wins over an env file")+ #expect(plan.environment["DM_OPMODE"] == "0" && plan.environment["DM_OTHER"] == "7")+ // A second model (the next start of the app) reads the same suite+ let again = RecordingLauncher()+ await ShellHostModel(config: box.config(), launcher: again).playNow(Fixtures.orbit)+ #expect(again.launched.first?.environment["DM_SHOW_FPS"] == "1")+ }+@Test func theStubShowsThatLaunchingIsNotAvailable() async throws {let box = try Sandbox()try box.giveAppData()diff --git a/frontend-ios/Tests/ShellUITests/LayoutTests.swift b/frontend-ios/Tests/ShellUITests/LayoutTests.swiftindex b7b4a9ba..65f91280 100644--- a/frontend-ios/Tests/ShellUITests/LayoutTests.swift+++ b/frontend-ios/Tests/ShellUITests/LayoutTests.swift@@ -57,3 +57,45 @@ final class LayoutTests: XCTestCase {XCTAssertEqual(CardSnap.card(target: -50, velocity: -0.8, stride: stride, count: 7, start: 0), 0)}}++final class ChoicePresentationTests: XCTestCase {+ private func resolve(_ labels: [String], _ width: CGFloat?, scale: CGFloat = 1) -> ChoicePresentation {+ ChoicePresentation.resolve(labels: labels, width: width, textScale: scale)+ }+ func testFewShortLabelsAreSegmented() {+ XCTAssertEqual(resolve(["Handheld", "Docked"], 400), .segmented)+ XCTAssertEqual(resolve(["30 fps", "60 fps"], 300), .segmented)+ XCTAssertEqual(resolve(["Off", "Low", "Medium", "High"], 420), .segmented)+ }+ func testManyOptionsAreAListWhateverTheWidth() {+ let five = ["A", "B", "C", "D", "E"]+ XCTAssertEqual(resolve(five, 2000), .list)+ XCTAssertEqual(resolve(five, nil), .list)+ let languages = Array(repeating: "American English", count: 15)+ XCTAssertEqual(resolve(languages, 600), .list)+ }+ func testSingleOrNoOptionIsAList() {+ XCTAssertEqual(resolve(["Only"], 400), .list)+ XCTAssertEqual(resolve([], 400), .list)+ }+ func testLongLabelsDoNotFitTheirSegment() {+ let labels = ["Latin American Spanish", "Brazilian Portuguese"]+ XCTAssertEqual(resolve(labels, 300), .list)+ XCTAssertEqual(resolve(labels, 640), .segmented)+ }+ func testNarrowWidthAndLargerTextTurnSegmentsIntoAList() {+ let labels = ["Handheld", "Docked"]+ XCTAssertEqual(resolve(labels, 400), .segmented)+ XCTAssertEqual(resolve(labels, 150), .list)+ XCTAssertEqual(resolve(["Standard", "Performance", "Quality"], 360), .segmented)+ XCTAssertEqual(resolve(["Standard", "Performance", "Quality"], 360, scale: 1.6), .list)+ }+ func testWidthUnknownDecidesByCountOnly() {+ XCTAssertEqual(resolve(["Handheld", "Docked"], nil), .segmented)+ }+ func testTextScaleGrowsWithDynamicType() {+ XCTAssertEqual(ChoicePresentation.textScale(.large), 1)+ XCTAssertLessThan(ChoicePresentation.textScale(.small), 1)+ XCTAssertGreaterThan(ChoicePresentation.textScale(.accessibility3), ChoicePresentation.textScale(.xxxLarge))+ }+}diff --git a/frontend-ios/UITests/ShellAdditionalTests.swift b/frontend-ios/UITests/ShellAdditionalTests.swiftindex 175680c6..2aea58d1 100644--- a/frontend-ios/UITests/ShellAdditionalTests.swift+++ b/frontend-ios/UITests/ShellAdditionalTests.swift@@ -73,6 +73,54 @@ import XCTestcapture("controller-reaches-last-cover")}+ /// A choice with many options is one compact row that opens a list: a controller walks it and picks, B closes+ /// without a change, touch picks too.+ func testLongChoiceOpensAListAndPicks() {+ XCUIDevice.shared.orientation = .landscapeLeft+ app.launchArguments = ["--screen", "settings", "--input-test"]+ app.launch()+ let row = app.buttons["setting.DM_LANGUAGE"]+ let picker = app.descendants(matching: .any)["choice.picker"]+ XCTAssertTrue(app.buttons["qa.input.down"].waitForExistence(timeout: 10))+ XCTAssertTrue(app.switches["setting.DM_SHOW_FPS"].exists)+ // Play mode has two short options and stays segmented. Language is one row, not fifteen buttons.+ XCTAssertTrue(app.buttons["Play mode, Handheld"].exists)+ XCTAssertFalse(app.buttons["Language, Japanese"].exists)+ // The first press only shows the focus on Back, then Play, Play mode, Show frame rate, Language.+ for _ in 0..<5 { app.buttons["qa.input.down"].tap() }+ XCTAssertEqual(row.value as? String, "American English")+ capture("language-collapsed")+ app.buttons["qa.input.activate"].tap()+ XCTAssertTrue(picker.waitForExistence(timeout: 5))+ XCTAssertTrue(app.buttons["choice.option.es-419"].exists)+ capture("language-list")+ // Controller: down twice, A picks Japanese and closes.+ app.buttons["qa.input.down"].tap()+ app.buttons["qa.input.down"].tap()+ app.buttons["qa.input.activate"].tap()+ XCTAssertFalse(picker.waitForExistence(timeout: 1))+ XCTAssertEqual(row.value as? String, "Japanese")+ // B closes without a change: down moves the focus, back leaves the value alone.+ app.buttons["qa.input.activate"].tap()+ XCTAssertTrue(picker.waitForExistence(timeout: 5))+ app.buttons["qa.input.down"].tap()+ app.buttons["qa.input.back"].tap()+ XCTAssertFalse(picker.waitForExistence(timeout: 1))+ XCTAssertEqual(row.value as? String, "Japanese")+ // Touch: tap the row, tap an option.+ row.tap()+ XCTAssertTrue(picker.waitForExistence(timeout: 5))+ app.buttons["choice.option.fr"].tap()+ XCTAssertFalse(picker.waitForExistence(timeout: 1))+ XCTAssertEqual(row.value as? String, "French")+ // The close button and a tap outside leave it as well.+ row.tap()+ XCTAssertTrue(app.buttons["choice.close"].waitForExistence(timeout: 5))+ app.buttons["choice.close"].tap()+ XCTAssertFalse(picker.waitForExistence(timeout: 1))+ XCTAssertEqual(row.value as? String, "French")+ }+func testCoverFlowFollowsTheController() {XCUIDevice.shared.orientation = .landscapeLeftapp.launchArguments = ["--screen", "focus", "--input-test"]diff --git a/frontend-ios/UITests/ShellCaptureTests.swift b/frontend-ios/UITests/ShellCaptureTests.swiftindex 93c819c3..9b3d99e1 100644--- a/frontend-ios/UITests/ShellCaptureTests.swift+++ b/frontend-ios/UITests/ShellCaptureTests.swift@@ -27,6 +27,24 @@ import XCTestsleep(1)}+ /// The settings with the language row collapsed, its open list, and the settings scrolled under the top bar.+ func testCaptureChoiceAndTopBar() {+ XCUIDevice.shared.orientation = .landscapeLeft+ launch(["--screen", "settings", "--input-test"])+ func appShot(_ name: String) { shot(name) }+ for _ in 0..<5 { app.buttons["qa.input.down"].tap() }+ sleep(1)+ appShot("settings-language-collapsed")+ app.buttons["qa.input.activate"].tap()+ sleep(1)+ appShot("settings-language-list")+ app.buttons["qa.input.back"].tap()+ sleep(1)+ app.scrollViews.element(boundBy: app.scrollViews.count - 1).swipeUp()+ sleep(1)+ appShot("settings-scrolled-top-bar")+ }+func testCaptureMatrix() {for orientation in [UIDeviceOrientation.portrait, .landscapeLeft] {XCUIDevice.shared.orientation = orientation