Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

A game can turn cloud saves off, and the shell folders can be removed

v0lumehidfb65754a8b0
diff --git a/frontend-ios/Sources/ShellDemo/SampleData.swift b/frontend-ios/Sources/ShellDemo/SampleData.swift
index 381733f1..ac4358f5 100644
--- a/frontend-ios/Sources/ShellDemo/SampleData.swift
+++ b/frontend-ios/Sources/ShellDemo/SampleData.swift
@@ -31,7 +31,7 @@ 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: "1", fromShell: tile.id == "orbit"),
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: [
@@ -43,7 +43,8 @@ func demoText(_ key: String.LocalizationValue) -> String {
])
], dataSource: tile.state == .needsGameData ? "" : demoText("This app's folder"), dataNote: demoText("Choose a RomFS folder or romfs.img on this device, an external drive, or iCloud Drive."),
cloudSaves: tile.id == "orbit" ? demoText("iCloud Drive / Game Saves") : nil,
- dlc: tile.id == "orbit" ? demoText("2 additional content packs") : demoText("No additional content"), hasModifiedSettings: true)
+ dlc: tile.id == "orbit" ? demoText("2 additional content packs") : demoText("No additional content"), hasModifiedSettings: true,
+ cloudFromShell: tile.id == "orbit")
}
}
static let controllers = [
diff --git a/frontend-ios/Sources/ShellDemo/ShellDemoApp.swift b/frontend-ios/Sources/ShellDemo/ShellDemoApp.swift
index 4cecb900..331d49d1 100644
--- a/frontend-ios/Sources/ShellDemo/ShellDemoApp.swift
+++ b/frontend-ios/Sources/ShellDemo/ShellDemoApp.swift
@@ -139,13 +139,16 @@ struct DemoScreen: View {
for section in games[g].sections.indices {
if let index = games[g].sections[section].rows.firstIndex(where: { $0.id == row }) {
games[g].sections[section].rows[index].value = value
+ games[g].sections[section].rows[index].fromShell = false
games[g].hasModifiedSettings = true
}
}
}, onPickGameData: { _ in notice = demoText("Choose game data requested. The host supplies the picker.") },
onUseAppData: { _ in notice = demoText("Use app data requested.") },
onPickCloudSaves: { _ in notice = demoText("Choose cloud folder requested. The host supplies the picker.") },
- onDisableCloudSaves: { id in if let i = games.firstIndex(where: { $0.id == id }) { games[i].cloudSaves = nil } },
+ onDisableCloudSaves: { id in
+ if let i = games.firstIndex(where: { $0.id == id }) { games[i].cloudSaves = nil; games[i].cloudFromShell = false; games[i].cloudCanUseShell = true }
+ },
onResetDefaults: { id in
if let i = games.firstIndex(where: { $0.id == id }), let original = SampleData.games.first(where: { $0.id == id }) {
games[i].sections = original.sections
@@ -155,7 +158,13 @@ struct DemoScreen: View {
onAppUpdate: { notice = demoText("App update requested. The host supplies update instructions.") },
onBack: { notice = demoText("Back requested.") },
onPickShellData: { notice = demoText("Choose game data requested. The host supplies the picker.") },
- onPickShellCloud: { notice = demoText("Choose cloud folder requested. The host supplies the picker.") })
+ onPickShellCloud: { notice = demoText("Choose cloud folder requested. The host supplies the picker.") },
+ onUseShellCloud: { id in
+ if let i = games.firstIndex(where: { $0.id == id }), let original = SampleData.games.first(where: { $0.id == id }) {
+ games[i].cloudSaves = original.cloudSaves; games[i].cloudFromShell = true; games[i].cloudCanUseShell = false
+ }
+ }, onClearShellData: { ShellSettingsStore.current.clearDataFolderName() },
+ onClearShellCloud: { ShellSettingsStore.current.clearCloudSavesFolderName() })
}
}
diff --git a/frontend-ios/Sources/ShellHost/GameSettingsStore.swift b/frontend-ios/Sources/ShellHost/GameSettingsStore.swift
index 099e7996..2f742b94 100644
--- a/frontend-ios/Sources/ShellHost/GameSettingsStore.swift
+++ b/frontend-ios/Sources/ShellHost/GameSettingsStore.swift
@@ -6,6 +6,9 @@ import ShellUI
/// `cloudSavesBookmark`, so the engine can read the same names later.
public enum GameDefaults {
public static let suitePrefix = "dev.nx2apple.shell.game."
+ /// True when the player turned cloud saves off for this game. It wins over the shell's cloud-saves folder, and
+ /// choosing a folder for the game clears it.
+ public static let cloudSavesOffKey = "cloudSavesOff"
public static func suite(for titleID: String) -> UserDefaults {
UserDefaults(suiteName: suitePrefix + titleID) ?? .standard
}
@@ -38,6 +41,11 @@ public struct GameSettingsStore {
public func value(of setting: LauncherSetting) -> String { saved(setting) ?? fallback(setting) }
+ /// True when the row shows the shell's choice: the game has none saved and the shell asks for a value the game offers.
+ public func isFromShell(_ setting: LauncherSetting) -> Bool {
+ saved(setting) == nil && shell[setting.env].map(setting.accepts) == true
+ }
+
public func values() -> [String: String] {
Dictionary(uniqueKeysWithValues: profile.settings.map { ($0.env, value(of: $0)) })
}
@@ -57,8 +65,9 @@ public struct GameSettingsStore {
for setting in profile.settings { defaults.removeObject(forKey: setting.defaultsKey) }
}
+ /// Any saved choice can be forgotten by the reset, also one that keeps the game's default against the shell's.
public var hasModifiedSettings: Bool {
- profile.settings.contains { setting in saved(setting).map { !setting.isDefault($0) } ?? false }
+ profile.settings.contains { saved($0) != nil }
}
}
@@ -66,7 +75,7 @@ public struct GameSettingsStore {
public enum SettingsPresenter {
/// A row with `needs` (`<VAR>=<value>`) is drawn only while the row that sets that variable has that value. A row
/// naming a variable the list does not have stays drawn. Sections come in the list's order.
- public static func sections(profile: LauncherProfile, values: [String: String]) -> [SettingSection] {
+ public static func sections(profile: LauncherProfile, values: [String: String], fromShell: Set<String> = []) -> [SettingSection] {
func visible(_ s: LauncherSetting) -> Bool {
guard let needs = s.needs, let eq = needs.firstIndex(of: "=") else { return true }
guard let v = values[String(needs[..<eq])] else { return true }
@@ -75,18 +84,18 @@ public enum SettingsPresenter {
var titles: [String] = []
for s in profile.settings where !titles.contains(s.sectionTitle) { titles.append(s.sectionTitle) }
return titles.compactMap { title in
- let rows = profile.settings.filter { $0.sectionTitle == title && visible($0) }.map { row($0, value: values[$0.env] ?? $0.def) }
+ let rows = profile.settings.filter { $0.sectionTitle == title && visible($0) }.map { row($0, value: values[$0.env] ?? $0.def, fromShell: fromShell.contains($0.env)) }
return rows.isEmpty ? nil : SettingSection(id: title, title: title, rows: rows)
}
}
- static func row(_ s: LauncherSetting, value: String) -> SettingRow {
+ static func row(_ s: LauncherSetting, value: String, fromShell: Bool = false) -> SettingRow {
let kind: SettingKind
switch s.kind {
case "toggle": kind = .toggle(on: s.onValue, off: s.offValue)
case "range": kind = .range(min: s.min ?? 0, max: s.max ?? 1, step: s.step ?? 0.1, unit: s.env.hasSuffix("SCALE") ? "×" : "")
default: kind = .choice((s.options ?? []).map { SettingOption($0[0], $0[1]) })
}
- return SettingRow(id: s.env, label: s.label, note: s.note, kind: kind, value: value)
+ return SettingRow(id: s.env, label: s.label, note: s.note, kind: kind, value: value, fromShell: fromShell)
}
}
diff --git a/frontend-ios/Sources/ShellHost/ShellHostModel.swift b/frontend-ios/Sources/ShellHost/ShellHostModel.swift
index 97776ea0..fb192efa 100644
--- a/frontend-ios/Sources/ShellHost/ShellHostModel.swift
+++ b/frontend-ios/Sources/ShellHost/ShellHostModel.swift
@@ -144,6 +144,21 @@ public struct ShellHostConfig: Sendable {
return s
}
+ private enum CloudSaves { case off, own(URL), stale, shell(URL), none }
+
+ /// Where the game's cloud saves go: off when the player turned them off for the game, then the game's own folder,
+ /// then the shell settings' folder.
+ private func cloudSaves(_ id: String) -> CloudSaves {
+ if config.defaults(id).bool(forKey: GameDefaults.cloudSavesOffKey) { return .off }
+ switch cloudStore(id).resolve() {
+ case .url(let url): return .own(url)
+ case .stale: return .stale
+ case .none:
+ if case .url(let url) = shellCloud.resolve() { return .shell(url) }
+ return .none
+ }
+ }
+
private func data(for entry: CatalogueEntry) -> DataResolution {
guard let manifest = entry.manifest, entry.problem == nil else { return .missing }
return DataLocator.locate(manifest: manifest, picked: dataStore(entry.id).resolve(), appFolder: appFolder(for: entry.id),
@@ -172,17 +187,21 @@ public struct ShellHostConfig: Sendable {
var cloud: String?
var cloudNote = ""
var cloudFromShell = false
- switch cloudStore(entry.id).resolve() {
- case .url(let url): cloud = url.lastPathComponent
+ switch cloudSaves(entry.id) {
+ case .own(let url): cloud = url.lastPathComponent
case .stale: cloudNote = hostText("The folder you chose before is no longer readable. Please choose it again.")
- case .none:
- if case .url(let url) = shellCloud.resolve() { cloud = url.lastPathComponent; cloudFromShell = true }
+ case .shell(let url): cloud = hostText("\(url.lastPathComponent) (from Settings)"); cloudFromShell = true
+ case .off, .none: break
}
+ var shellFolder = false
+ if case .url = shellCloud.resolve() { shellFolder = true }
+ let fromShell = Set(profile.settings.filter(store.isFromShell).map(\.env))
return GameDetail(
- game: tile, sections: SettingsPresenter.sections(profile: profile, values: store.values()),
+ game: tile, sections: SettingsPresenter.sections(profile: profile, values: store.values(), fromShell: fromShell),
dataSource: dataSource(data), dataNote: dataNote(data, found: data.found),
cloudSaves: cloud, cloudNote: cloudNote, dlc: dlc(data), hasModifiedSettings: store.hasModifiedSettings,
- dataFromShell: data.source == .shell, cloudFromShell: cloudFromShell)
+ dataFromShell: data.source == .shell, cloudFromShell: cloudFromShell,
+ cloudCanUseShell: shellFolder && !cloudFromShell)
}
private func dataSource(_ data: DataResolution) -> String {
@@ -224,7 +243,10 @@ public struct ShellHostConfig: Sendable {
onShowLog: { [weak self] id in self?.showLog(id) },
onAppUpdate: { [weak self] in self?.appUpdate() },
onPickShellData: { [weak self] in self.map { model in Task { await model.pickShellDataNow() } } },
- onPickShellCloud: { [weak self] in self.map { model in Task { await model.pickShellCloudNow() } } })
+ onPickShellCloud: { [weak self] in self.map { model in Task { await model.pickShellCloudNow() } } },
+ onUseShellCloud: { [weak self] id in self?.useShellCloudSaves(id) },
+ onClearShellData: { [weak self] in self?.clearShellData() },
+ onClearShellCloud: { [weak self] in self?.clearShellCloud() })
}
public func change(_ id: String, setting: String, value: String) {
@@ -269,7 +291,8 @@ public struct ShellHostConfig: Sendable {
func pickCloudSavesNow(_ id: String) async {
guard let url = await picker.pickFolder() else { return }
- if !cloudStore(id).store(url) { notice = hostText("That folder could not be remembered. Try a different one.") }
+ if cloudStore(id).store(url) { config.defaults(id).removeObject(forKey: GameDefaults.cloudSavesOffKey) }
+ else { notice = hostText("That folder could not be remembered. Try a different one.") }
refresh(id)
}
@@ -289,9 +312,29 @@ public struct ShellHostConfig: Sendable {
public func disableCloudSaves(_ id: String) {
cloudStore(id).clear()
+ config.defaults(id).set(true, forKey: GameDefaults.cloudSavesOffKey)
+ refresh(id)
+ }
+
+ /// The game follows the shell settings' cloud-saves folder again.
+ public func useShellCloudSaves(_ id: String) {
+ cloudStore(id).clear()
+ config.defaults(id).removeObject(forKey: GameDefaults.cloudSavesOffKey)
refresh(id)
}
+ func clearShellData() {
+ shellData.clear()
+ shellSettings.clearDataFolderName()
+ refreshAll()
+ }
+
+ func clearShellCloud() {
+ shellCloud.clear()
+ shellSettings.clearCloudSavesFolderName()
+ refreshAll()
+ }
+
public func showLog(_ id: String) {
guard let entry = entry(id) else { return }
let app = appFolder(for: id)
@@ -316,10 +359,9 @@ public struct ShellHostConfig: Sendable {
guard let entry = entry(id), let manifest = entry.manifest, let profile = entry.profile, let framework = entry.frameworkURL,
details.first(where: { $0.id == id })?.game.state == .playable, let dataURL = data(for: entry).url else { return }
var cloud: URL?
- switch cloudStore(id).resolve() {
- case .url(let url): cloud = url
- case .stale: break
- case .none: if case .url(let url) = shellCloud.resolve() { cloud = url }
+ switch cloudSaves(id) {
+ case .own(let url), .shell(let url): cloud = url
+ case .off, .stale, .none: break
}
// Remembered when Play is triggered, even if the launcher then fails (the stub). The order changes at the next load.
LastPlayedStore(defaults: config.defaults(id)).record(config.now())
diff --git a/frontend-ios/Sources/ShellUI/ChoicePicker.swift b/frontend-ios/Sources/ShellUI/ChoicePicker.swift
index 476a5b2b..ac4b9a5a 100644
--- a/frontend-ios/Sources/ShellUI/ChoicePicker.swift
+++ b/frontend-ios/Sources/ShellUI/ChoicePicker.swift
@@ -169,6 +169,7 @@ struct ChoiceValueRow: View {
if !row.note.isEmpty {
Text(row.note).shellType(ShellType.note).foregroundStyle(.white.opacity(0.5)).fixedSize(horizontal: false, vertical: true)
}
+ if row.fromShell { FromSettingsMark() }
}
Spacer(minLength: 8)
Text(valueLabel).shellText(14.5, .semibold).foregroundStyle(ShellPalette.cream)
diff --git a/frontend-ios/Sources/ShellUI/GameDetailView.swift b/frontend-ios/Sources/ShellUI/GameDetailView.swift
index aa75b0f0..b869d6c5 100644
--- a/frontend-ios/Sources/ShellUI/GameDetailView.swift
+++ b/frontend-ios/Sources/ShellUI/GameDetailView.swift
@@ -49,7 +49,11 @@ public struct GameDetailView: View {
note: detail.cloudNote.isEmpty ? ShellStrings.text("Choose the same iCloud Drive folder you use on your Mac.") : detail.cloudNote) {
Button(ShellStrings.text("Choose folder…")) { actions.onPickCloudSaves(detail.id) }
.buttonStyle(ShellButtonStyle(fills: true)).shellTarget("set.cloud") { actions.onPickCloudSaves(detail.id) }
- if detail.cloudSaves != nil && !detail.cloudFromShell {
+ if detail.cloudCanUseShell {
+ Button(ShellStrings.text("Use Settings folder")) { actions.onUseShellCloud(detail.id) }
+ .buttonStyle(ShellButtonStyle(fills: true)).shellTarget("set.cloud.shell") { actions.onUseShellCloud(detail.id) }
+ }
+ if detail.cloudSaves != nil {
Button(ShellStrings.text("Turn off")) { actions.onDisableCloudSaves(detail.id) }
.buttonStyle(ShellButtonStyle(fills: true)).accessibilityLabel(ShellStrings.text("Turn off cloud saves"))
.shellTarget("set.cloud.off") { actions.onDisableCloudSaves(detail.id) }
@@ -208,6 +212,7 @@ struct SettingControl: View, Equatable {
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) }
+ if row.fromShell { FromSettingsMark() }
}
}
/// The Mac's segmented choice, across the whole card: a dim track, equal segments, the chosen value in cream.
@@ -255,6 +260,14 @@ struct SettingControl: View, Equatable {
}
}
+/// Says that a row shows the shell settings' choice, because the game has none of its own.
+struct FromSettingsMark: View {
+ var body: some View {
+ Text(ShellStrings.text("From Settings")).shellType(ShellType.note).foregroundStyle(ShellPalette.cream.opacity(0.75))
+ .fixedSize(horizontal: false, vertical: true)
+ }
+}
+
/// Children side by side in equal widths that fill the row. Its ideal width is the widest child times the count, so
/// a `ViewThatFits` can fall back when the labels would not fit at equal widths.
struct EqualRow: Layout {
diff --git a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
index d5b5a955..93ba2f37 100644
--- a/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
+++ b/frontend-ios/Sources/ShellUI/Resources/Localizable.xcstrings
@@ -385,6 +385,22 @@
}
}
},
+ "From Settings": {
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "From Settings"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "来自设置"
+ }
+ }
+ }
+ },
"Game data": {
"localizations": {
"en": {
@@ -833,6 +849,22 @@
}
}
},
+ "Remove": {
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Remove"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "移除"
+ }
+ }
+ }
+ },
"Reset to tested defaults": {
"localizations": {
"en": {
@@ -993,6 +1025,22 @@
}
}
},
+ "Use Settings folder": {
+ "localizations": {
+ "en": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "Use Settings folder"
+ }
+ },
+ "zh-Hans": {
+ "stringUnit": {
+ "state": "translated",
+ "value": "使用设置中的文件夹"
+ }
+ }
+ }
+ },
"Use app data": {
"localizations": {
"en": {
diff --git a/frontend-ios/Sources/ShellUI/ShellInputs.swift b/frontend-ios/Sources/ShellUI/ShellInputs.swift
index b7abf4a9..eb5c6d24 100644
--- a/frontend-ios/Sources/ShellUI/ShellInputs.swift
+++ b/frontend-ios/Sources/ShellUI/ShellInputs.swift
@@ -55,13 +55,16 @@ public struct SettingRow: Identifiable, Equatable, Sendable {
public var value: String
/// The caller resolves dependencies and locks before supplying rows.
public var enabled: Bool
- public init(id: String, label: String, note: String = "", kind: SettingKind, value: String, enabled: Bool = true) {
+ /// The value is the shell settings' choice, because the game has none of its own.
+ public var fromShell: Bool
+ public init(id: String, label: String, note: String = "", kind: SettingKind, value: String, enabled: Bool = true, fromShell: Bool = false) {
self.id = id
self.label = label
self.note = note
self.kind = kind
self.value = value
self.enabled = enabled
+ self.fromShell = fromShell
}
}
@@ -85,9 +88,11 @@ public struct GameDetail: Identifiable, Equatable, Sendable {
/// The data or cloud-saves folder is the shell settings' one, not one the player picked for this game.
public var dataFromShell: Bool
public var cloudFromShell: Bool
+ /// The shell settings have a cloud-saves folder this game does not use now, so the game can follow it.
+ public var cloudCanUseShell: Bool
public init(game: GameTile, sections: [SettingSection] = [], dataSource: String = "", dataNote: String = "",
cloudSaves: String? = nil, cloudNote: String = "", dlc: String = "", hasModifiedSettings: Bool = false,
- dataFromShell: Bool = false, cloudFromShell: Bool = false) {
+ dataFromShell: Bool = false, cloudFromShell: Bool = false, cloudCanUseShell: Bool = false) {
self.game = game
self.sections = sections
self.dataSource = dataSource
@@ -98,6 +103,7 @@ public struct GameDetail: Identifiable, Equatable, Sendable {
self.hasModifiedSettings = hasModifiedSettings
self.dataFromShell = dataFromShell
self.cloudFromShell = cloudFromShell
+ self.cloudCanUseShell = cloudCanUseShell
}
}
@@ -165,13 +171,18 @@ public struct ShellActions {
public var onBack: () -> Void
public var onPickShellData: () -> Void
public var onPickShellCloud: () -> Void
+ public var onUseShellCloud: (String) -> Void
+ public var onClearShellData: () -> Void
+ public var onClearShellCloud: () -> Void
public init(onSelect: @escaping (String) -> Void = { _ in }, onPlay: @escaping (String) -> Void = { _ in },
onChange: @escaping (String, String, String) -> Void = { _, _, _ in },
onPickGameData: @escaping (String) -> Void = { _ in }, onUseAppData: @escaping (String) -> Void = { _ in },
onPickCloudSaves: @escaping (String) -> Void = { _ in }, onDisableCloudSaves: @escaping (String) -> Void = { _ in },
onResetDefaults: @escaping (String) -> Void = { _ in }, onShowLog: @escaping (String) -> Void = { _ in },
onAppUpdate: @escaping () -> Void = {}, onBack: @escaping () -> Void = {},
- onPickShellData: @escaping () -> Void = {}, onPickShellCloud: @escaping () -> Void = {}) {
+ onPickShellData: @escaping () -> Void = {}, onPickShellCloud: @escaping () -> Void = {},
+ onUseShellCloud: @escaping (String) -> Void = { _ in }, onClearShellData: @escaping () -> Void = {},
+ onClearShellCloud: @escaping () -> Void = {}) {
self.onSelect = onSelect
self.onPlay = onPlay
self.onChange = onChange
@@ -185,5 +196,8 @@ public struct ShellActions {
self.onBack = onBack
self.onPickShellData = onPickShellData
self.onPickShellCloud = onPickShellCloud
+ self.onUseShellCloud = onUseShellCloud
+ self.onClearShellData = onClearShellData
+ self.onClearShellCloud = onClearShellCloud
}
}
diff --git a/frontend-ios/Sources/ShellUI/ShellSettingsStore.swift b/frontend-ios/Sources/ShellUI/ShellSettingsStore.swift
index 72f0654b..62a58e5a 100644
--- a/frontend-ios/Sources/ShellUI/ShellSettingsStore.swift
+++ b/frontend-ios/Sources/ShellUI/ShellSettingsStore.swift
@@ -34,6 +34,8 @@ public final class ShellSettingsStore: @unchecked Sendable {
public func storeDataFolderName(_ name: String) { defaults.set(name, forKey: Self.dataFolderNameKey) }
public func storeCloudSavesFolderName(_ name: String) { defaults.set(name, forKey: Self.cloudSavesNameKey) }
+ public func clearDataFolderName() { defaults.removeObject(forKey: Self.dataFolderNameKey) }
+ public func clearCloudSavesFolderName() { defaults.removeObject(forKey: Self.cloudSavesNameKey) }
public func storeLanguage(_ code: String) { defaults.set(code, forKey: Self.languageKey) }
public func storePerformanceHUD(_ on: Bool) { defaults.set(on, forKey: Self.performanceHUDKey) }
diff --git a/frontend-ios/Sources/ShellUI/ShellSettingsView.swift b/frontend-ios/Sources/ShellUI/ShellSettingsView.swift
index 220adbe3..84cf3f25 100644
--- a/frontend-ios/Sources/ShellUI/ShellSettingsView.swift
+++ b/frontend-ios/Sources/ShellUI/ShellSettingsView.swift
@@ -63,6 +63,11 @@ struct ShellSettingsView: View {
Button(ShellStrings.text("Choose folder…")) { actions.onPickShellData() }
.buttonStyle(ShellButtonStyle(fills: true)).accessibilityIdentifier("shellSettings.data")
.shellTarget("shs.data") { actions.onPickShellData() }
+ if store.dataFolderName != nil {
+ Button(ShellStrings.text("Remove")) { actions.onClearShellData() }
+ .buttonStyle(ShellButtonStyle(fills: true)).accessibilityIdentifier("shellSettings.data.remove")
+ .shellTarget("shs.data.remove") { actions.onClearShellData() }
+ }
}
}
SettingsGroup(title: ShellStrings.text("Cloud saves")) {
@@ -72,6 +77,12 @@ struct ShellSettingsView: View {
Button(ShellStrings.text("Choose folder…")) { actions.onPickShellCloud() }
.buttonStyle(ShellButtonStyle(fills: true)).accessibilityIdentifier("shellSettings.cloud")
.shellTarget("shs.cloud") { actions.onPickShellCloud() }
+ if store.cloudSavesFolderName != nil {
+ Button(ShellStrings.text("Turn off")) { actions.onClearShellCloud() }
+ .buttonStyle(ShellButtonStyle(fills: true)).accessibilityIdentifier("shellSettings.cloud.off")
+ .accessibilityLabel(ShellStrings.text("Turn off cloud saves"))
+ .shellTarget("shs.cloud.off") { actions.onClearShellCloud() }
+ }
}
}
SettingsGroup(title: ShellStrings.text("Interface")) {
diff --git a/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift b/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift
index bd53ac21..2e15ae95 100644
--- a/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift
+++ b/frontend-ios/Tests/ShellHostTests/ShellHostModelTests.swift
@@ -235,8 +235,8 @@ final class Clock: @unchecked Sendable { var date: Date; init(_ d: Date) { date
await model.pickShellCloudNow()
#expect(shell.cloudSavesFolderName == "Shared Saves" && shell.cloudSavesBookmark != nil)
var orbit = try detail(model)
- #expect(orbit.cloudSaves == "Shared Saves" && orbit.cloudFromShell)
- #expect(try detail(model, Fixtures.chain).cloudSaves == "Shared Saves")
+ #expect(orbit.cloudSaves == "Shared Saves (from Settings)" && orbit.cloudFromShell)
+ #expect(try detail(model, Fixtures.chain).cloudSaves == "Shared Saves (from Settings)")
await model.playNow(Fixtures.orbit)
#expect(launcher.launched.last?.cloudSavesURL?.lastPathComponent == "Shared Saves")
// The game's own folder wins
@@ -246,9 +246,90 @@ final class Clock: @unchecked Sendable { var date: Date; init(_ d: Date) { date
#expect(orbit.cloudSaves == "Own Saves" && !orbit.cloudFromShell)
await own2.playNow(Fixtures.orbit)
#expect(launcher.launched.last?.cloudSavesURL?.lastPathComponent == "Own Saves")
- // Turning the game's folder off falls back to the shell's, and the game's setting stays untouched in between
+ // Turning the game's folder off means off, though the shell has a folder
own2.actions.onDisableCloudSaves(Fixtures.orbit)
- #expect(try detail(own2).cloudSaves == "Shared Saves")
+ #expect(try detail(own2).cloudSaves == nil)
+ }
+
+ @Test func aGameCanTurnCloudSavesOffAndFollowTheShellFolderAgain() async throws {
+ let box = try Sandbox()
+ try box.giveAppData()
+ let shared = box.root.appendingPathComponent("iCloud/Shared Saves", isDirectory: true)
+ let own = box.root.appendingPathComponent("iCloud/Own Saves", isDirectory: true)
+ for folder in [shared, own] { try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true) }
+ let launcher = RecordingLauncher()
+ let shell = shellSettings()
+ let model = ShellHostModel(config: box.config(), launcher: launcher, picker: FakePicker(url: shared), shellSettings: shell)
+ #expect(try !detail(model).cloudCanUseShell, "no shell folder to follow")
+ await model.pickShellCloudNow()
+ model.actions.onDisableCloudSaves(Fixtures.orbit)
+ var orbit = try detail(model)
+ #expect(orbit.cloudSaves == nil && !orbit.cloudFromShell && orbit.cloudCanUseShell)
+ #expect(try detail(model, Fixtures.chain).cloudSaves == "Shared Saves (from Settings)", "another game is not affected")
+ await model.playNow(Fixtures.orbit)
+ #expect(launcher.launched.last?.cloudSavesURL == nil)
+ // The off choice survives a new session
+ let again = ShellHostModel(config: box.config(), launcher: launcher, shellSettings: shell)
+ #expect(try detail(again).cloudSaves == nil)
+ // Choosing a folder for the game clears it
+ let picking = ShellHostModel(config: box.config(), launcher: launcher, picker: FakePicker(url: own), shellSettings: shell)
+ await picking.pickCloudSavesNow(Fixtures.orbit)
+ orbit = try detail(picking)
+ #expect(orbit.cloudSaves == "Own Saves" && orbit.cloudCanUseShell)
+ await picking.playNow(Fixtures.orbit)
+ #expect(launcher.launched.last?.cloudSavesURL?.lastPathComponent == "Own Saves")
+ // Following the shell again
+ picking.actions.onUseShellCloud(Fixtures.orbit)
+ orbit = try detail(picking)
+ #expect(orbit.cloudSaves == "Shared Saves (from Settings)" && orbit.cloudFromShell && !orbit.cloudCanUseShell)
+ await picking.playNow(Fixtures.orbit)
+ #expect(launcher.launched.last?.cloudSavesURL?.lastPathComponent == "Shared Saves")
+ // Off with a game folder that the player picks later, and off again from the shell folder
+ picking.actions.onDisableCloudSaves(Fixtures.orbit)
+ picking.actions.onUseShellCloud(Fixtures.orbit)
+ #expect(try detail(picking).cloudFromShell)
+ }
+
+ @Test func theShellFoldersCanBeRemoved() async throws {
+ let box = try Sandbox()
+ try box.giveAppData()
+ let drive = box.root.appendingPathComponent("Drive/Switch", isDirectory: true)
+ try box.write("", to: drive.appendingPathComponent("fixture.marker"))
+ let shared = box.root.appendingPathComponent("iCloud/Shared Saves", isDirectory: true)
+ try FileManager.default.createDirectory(at: shared, withIntermediateDirectories: true)
+ let shell = shellSettings()
+ let model = ShellHostModel(config: box.config(), picker: FakePicker(url: shared), shellSettings: shell)
+ await model.pickShellCloudNow()
+ let data = ShellHostModel(config: box.config(), picker: FakePicker(url: drive), shellSettings: shell)
+ await data.pickShellDataNow()
+ #expect(shell.cloudSavesFolderName != nil && shell.cloudSavesBookmark != nil && shell.dataFolderName != nil && shell.dataBookmark != nil)
+ model.actions.onClearShellCloud()
+ #expect(shell.cloudSavesFolderName == nil && shell.cloudSavesBookmark == nil)
+ #expect(try detail(model).cloudSaves == nil && !detail(model).cloudCanUseShell)
+ #expect(shell.dataFolderName != nil, "the other folder stays")
+ model.actions.onClearShellData()
+ #expect(shell.dataFolderName == nil && shell.dataBookmark == nil)
+ #expect(try detail(model).game.state == .playable, "the app folder has the data")
+ #expect(try !detail(model).dataFromShell)
+ }
+
+ @Test func aRowShowsThatItsValueComesFromTheShellUntilTheGameChoosesItself() throws {
+ let box = try Sandbox()
+ try box.giveAppData()
+ try giveOrbitAnOverlayRow(box)
+ let shell = shellSettings()
+ let model = ShellHostModel(config: box.config(), shellSettings: shell)
+ func row() throws -> SettingRow { try #require(detail(model).sections.flatMap(\.rows).first { $0.id == "DM_METAL_HUD" }) }
+ #expect(try !row().fromShell, "the shell has no choice")
+ shell.storePerformanceHUD(true)
+ model.refreshAll()
+ #expect(try row().fromShell && row().value == "1")
+ #expect(try !detail(model).hasModifiedSettings)
+ model.actions.onChange(Fixtures.orbit, "DM_METAL_HUD", "0")
+ #expect(try !row().fromShell && row().value == "0", "the game's own choice")
+ #expect(try detail(model).hasModifiedSettings, "the explicit off can be reset")
+ model.actions.onResetDefaults(Fixtures.orbit)
+ #expect(try row().fromShell && row().value == "1" && !detail(model).hasModifiedSettings)
}
@Test func theShellDataFolderIsNotPresentedAsThePlayersPickForTheGame() async throws {
diff --git a/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swift b/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swift
index 42c5e92a..9c5d455f 100644
--- a/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swift
+++ b/frontend-ios/Tests/ShellHostTests/ShellSettingsStoreTests.swift
@@ -31,8 +31,15 @@ import ShellUI
var store = GameSettingsStore(profile: profile, defaults: defaults, shell: shellDefaults)
#expect(store.values()["DM_SHOW_FPS"] == "1", "the shell's value over the built-in default")
#expect(!store.hasModifiedSettings, "a shell default is not a change the player made in this game")
+ let fps = try #require(profile.settings.first { $0.env == "DM_SHOW_FPS" })
+ #expect(store.isFromShell(fps))
store.set("DM_SHOW_FPS", to: "0")
#expect(store.values()["DM_SHOW_FPS"] == "0", "the game's own choice, though it equals the built-in default")
+ #expect(!store.isFromShell(fps))
+ #expect(store.hasModifiedSettings, "the saved off has to be resettable")
+ store.reset()
+ #expect(store.isFromShell(fps) && !store.hasModifiedSettings)
+ store.set("DM_SHOW_FPS", to: "0")
#expect(defaults.object(forKey: "launcher.DM_SHOW_FPS") as? String == "0")
store.set("DM_SHOW_FPS", to: "1")
#expect(defaults.object(forKey: "launcher.DM_SHOW_FPS") == nil, "a choice equal to the shell's value follows the shell again")