Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions frontend-ios/Demo/ShellDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@

/* Begin PBXBuildFile section */
2861C1407044359116FE0A66 /* ShellCaptureTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8694319745E3759D50772855 /* ShellCaptureTests.swift */; };
2BF462D88A6CE3993C4AEB9A /* ShellHostUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3902CFEF269CA462AFE8048 /* ShellHostUITests.swift */; };
2EEF6A8F9A7D58C09181EAB5 /* RealArt.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF911DEE5C19B0D069418726 /* RealArt.swift */; };
3E143B39E0F97A669D2F6EFF /* ShellAdditionalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF3DBBE6BC067DDD34E3560C /* ShellAdditionalTests.swift */; };
44E0EBFDB9557A0C8BB741BE /* ShellUI in Frameworks */ = {isa = PBXBuildFile; productRef = 7F6858A53523100F9E10590E /* ShellUI */; };
4749F987D74B27CAA0E02480 /* ShellDemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 59E0A7AE45425C5BA9689FE4 /* ShellDemoApp.swift */; };
47DB35565D19F0ACFF1E2F7E /* ShellHost in Frameworks */ = {isa = PBXBuildFile; productRef = D80A22588F977AEE019B7CFE /* ShellHost */; };
876E4B3FCD4C78C4085BCE30 /* ShellControllers in Frameworks */ = {isa = PBXBuildFile; productRef = D58DB30045BDC25980479EF9 /* ShellControllers */; };
C12D9CC70DEF69CCB48F44E7 /* Games in Resources */ = {isa = PBXBuildFile; fileRef = 3FAC070A229B08BED4005826 /* Games */; };
D94D715334EE4F5E0CCBA788 /* SampleArt.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39DB78D11BCF59879A3712F5 /* SampleArt.swift */; };
DF097C40B129901722DD4DF3 /* ShellDemoUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 916109EC3198FC9C0E9D655B /* ShellDemoUITests.swift */; };
E71FEFEAE303CA4343BBDE2E /* SampleData.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE23919FFDC3D06EF0D3065 /* SampleData.swift */; };
F15D381F62331B5172AD6D22 /* Localizable.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = D1591481D38DDC20A1A9B215 /* Localizable.xcstrings */; };
FAE394E91FBBBC0FD28A1C39 /* HostDemo.swift in Sources */ = {isa = PBXBuildFile; fileRef = B516EC05EC6F1241E8281A82 /* HostDemo.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -31,14 +35,17 @@

/* Begin PBXFileReference section */
39DB78D11BCF59879A3712F5 /* SampleArt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleArt.swift; sourceTree = "<group>"; };
3FAC070A229B08BED4005826 /* Games */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Games; path = ../Tests/ShellHostTests/Fixtures/Games; sourceTree = SOURCE_ROOT; };
59E0A7AE45425C5BA9689FE4 /* ShellDemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellDemoApp.swift; sourceTree = "<group>"; };
8694319745E3759D50772855 /* ShellCaptureTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellCaptureTests.swift; sourceTree = "<group>"; };
916109EC3198FC9C0E9D655B /* ShellDemoUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellDemoUITests.swift; sourceTree = "<group>"; };
B1D199F3FD9C677BD245559E /* ShellDemoApp.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = ShellDemoApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
B516EC05EC6F1241E8281A82 /* HostDemo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HostDemo.swift; sourceTree = "<group>"; };
B88394C7E11B302B2B420DF2 /* frontend-ios */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "frontend-ios"; path = ..; sourceTree = SOURCE_ROOT; };
CBE23919FFDC3D06EF0D3065 /* SampleData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleData.swift; sourceTree = "<group>"; };
CEB77983EFFD9EA46FE3DFDF /* ShellDemoUITests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = ShellDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D1591481D38DDC20A1A9B215 /* Localizable.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = Localizable.xcstrings; sourceTree = "<group>"; };
D3902CFEF269CA462AFE8048 /* ShellHostUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellHostUITests.swift; sourceTree = "<group>"; };
DF3DBBE6BC067DDD34E3560C /* ShellAdditionalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShellAdditionalTests.swift; sourceTree = "<group>"; };
FF911DEE5C19B0D069418726 /* RealArt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RealArt.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand All @@ -50,6 +57,7 @@
files = (
44E0EBFDB9557A0C8BB741BE /* ShellUI in Frameworks */,
876E4B3FCD4C78C4085BCE30 /* ShellControllers in Frameworks */,
47DB35565D19F0ACFF1E2F7E /* ShellHost in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -67,6 +75,7 @@
5928E24F76B598AD8FD0D1AB /* ShellDemo */ = {
isa = PBXGroup;
children = (
B516EC05EC6F1241E8281A82 /* HostDemo.swift */,
FF911DEE5C19B0D069418726 /* RealArt.swift */,
39DB78D11BCF59879A3712F5 /* SampleArt.swift */,
CBE23919FFDC3D06EF0D3065 /* SampleData.swift */,
Expand All @@ -83,6 +92,7 @@
DF3DBBE6BC067DDD34E3560C /* ShellAdditionalTests.swift */,
8694319745E3759D50772855 /* ShellCaptureTests.swift */,
916109EC3198FC9C0E9D655B /* ShellDemoUITests.swift */,
D3902CFEF269CA462AFE8048 /* ShellHostUITests.swift */,
);
name = UITests;
path = ../UITests;
Expand All @@ -108,6 +118,7 @@
E65C041019EAFE79D28C3E4E = {
isa = PBXGroup;
children = (
3FAC070A229B08BED4005826 /* Games */,
2152F5714F5AA74B9FBBB0F0 /* Packages */,
5928E24F76B598AD8FD0D1AB /* ShellDemo */,
B149173B288581EEEA22408A /* UITests */,
Expand All @@ -134,6 +145,7 @@
packageProductDependencies = (
7F6858A53523100F9E10590E /* ShellUI */,
D58DB30045BDC25980479EF9 /* ShellControllers */,
D80A22588F977AEE019B7CFE /* ShellHost */,
);
productName = ShellDemoApp;
productReference = B1D199F3FD9C677BD245559E /* ShellDemoApp.app */;
Expand Down Expand Up @@ -199,6 +211,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C12D9CC70DEF69CCB48F44E7 /* Games in Resources */,
F15D381F62331B5172AD6D22 /* Localizable.xcstrings in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -210,6 +223,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
FAE394E91FBBBC0FD28A1C39 /* HostDemo.swift in Sources */,
2EEF6A8F9A7D58C09181EAB5 /* RealArt.swift in Sources */,
D94D715334EE4F5E0CCBA788 /* SampleArt.swift in Sources */,
E71FEFEAE303CA4343BBDE2E /* SampleData.swift in Sources */,
Expand All @@ -224,6 +238,7 @@
3E143B39E0F97A669D2F6EFF /* ShellAdditionalTests.swift in Sources */,
2861C1407044359116FE0A66 /* ShellCaptureTests.swift in Sources */,
DF097C40B129901722DD4DF3 /* ShellDemoUITests.swift in Sources */,
2BF462D88A6CE3993C4AEB9A /* ShellHostUITests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -309,6 +324,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = ../Tests/ShellHostTests/Fixtures/Games/0100000000030000/DmGame.framework/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -340,6 +356,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = ../Tests/ShellHostTests/Fixtures/Games/0100000000030000/DmGame.framework/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -487,6 +504,10 @@
isa = XCSwiftPackageProductDependency;
productName = ShellControllers;
};
D80A22588F977AEE019B7CFE /* ShellHost */ = {
isa = XCSwiftPackageProductDependency;
productName = ShellHost;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = D41A7603C6BA5BB604CCFDE4 /* Project object */;
Expand Down
6 changes: 6 additions & 0 deletions frontend-ios/Demo/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ targets:
platform: iOS
sources:
- ../Sources/ShellDemo
# The fixture bundles for --host, copied into the app as its Games folder. No game data, no pictures.
- path: ../Tests/ShellHostTests/Fixtures/Games
type: folder
buildPhase: resources
dependencies:
- package: ShellUI
product: ShellUI
- package: ShellUI
product: ShellControllers
- package: ShellUI
product: ShellHost
ShellDemoUITests:
type: bundle.ui-testing
platform: iOS
Expand Down
6 changes: 5 additions & 1 deletion frontend-ios/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ let package = Package(
.library(name: "ShellUI", targets: ["ShellUI"]),
// The controller adapter: GameController input turned into ShellInput, kept apart from the views.
.library(name: "ShellControllers", targets: ["ShellControllers"]),
// The host layer behind the views: catalogue, settings, game data, cloud saves, log and the launcher seam.
.library(name: "ShellHost", targets: ["ShellHost"]),
.executable(name: "ShellDemo", targets: ["ShellDemo"])
],
targets: [
.target(name: "ShellUI", resources: [.process("Resources")]),
.target(name: "ShellControllers", dependencies: ["ShellUI"]),
.executableTarget(name: "ShellDemo", dependencies: ["ShellUI", "ShellControllers"], resources: [.process("Resources")]),
.target(name: "ShellHost", dependencies: ["ShellUI", "ShellControllers"], resources: [.process("Resources")]),
.executableTarget(name: "ShellDemo", dependencies: ["ShellUI", "ShellControllers", "ShellHost"], resources: [.process("Resources")]),
.testTarget(name: "ShellUITests", dependencies: ["ShellUI"]),
.testTarget(name: "ShellHostTests", dependencies: ["ShellHost", "ShellUI", "ShellControllers"], resources: [.copy("Fixtures")]),
.testTarget(name: "ShellControllersTests", dependencies: ["ShellControllers", "ShellUI"])
]
)
37 changes: 36 additions & 1 deletion frontend-ios/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# iOS shell views

A Swift 6 package for iOS and iPadOS 26 and later. `ShellUI` is the view layer of the multi-game shell described in Route C (#144). It renders what it is given and reports what the player does. It has no engine dependency, game launching, storage, document picker, networking or game-file access.
A Swift 6 package for iOS and iPadOS 26 and later. `ShellUI` is the view layer of the multi-game shell described in Route C (#144). It renders what it is given and reports what the player does. It has no engine dependency, game launching, storage, document picker, networking or game-file access. `ShellHost` is the layer behind it that does those things.

## Run

Expand Down Expand Up @@ -45,6 +45,41 @@ LibraryView(

The caller returns changed values through `games`. The views keep no second copy.

## Host

`ShellHost` is a library for the real shell app and the demo. It turns real files into the view values and acts on `ShellActions`. `ShellUI` stays view-only. Main types: `ShellHostModel` (the `@Observable` model, its `actions` go to `LibraryView`) and `ShellHostView` (`LibraryView` on a model, plus the log sheet and a notice alert).

| 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 |
| `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` |
| `BookmarkStore` | A security-scoped bookmark in the game's suite: `pickedDataBookmark` for game data, `cloudSavesBookmark` for the cloud-save folder. Written with the picker's scope, kept only if it resolves again, scope held once resolved, a stale one reported so the shell asks again, a refreshed one rewritten. No sync logic. | `dm/ios/Sources/DataBookmark.m` |
| `FolderPicker` | `DocumentFolderPicker` is a `UIDocumentPickerViewController` for a folder, opened in place. Tests use a fake. | `DocumentPicker` in `dm/ios/Sources/Launcher.swift` |
| Log | Show log reads the tail (256 KB) of `log.txt` in the game's data folder, else the app's folder, into a read-only sheet. | |
| Update | `ShellHostConfig.updateURL` is opened by Update app. | |
| Controllers | `ShellHostModel.startControllers()` runs `GamepadAdapter` and fills `controllers` (`ControllerInfo`) and `input` (`ShellInput`). | |

```swift
let config = ShellHostConfig(gamesRoot: gamesURL, appDataRoot: ShellHostConfig.defaultAppDataRoot(),
environment: HostEnvironment(chain: dmshChain))
let model = ShellHostModel(config: config, launcher: StubGameLauncher(), picker: DocumentFolderPicker())
ShellHostView(model: model)
```

### Launching: the `GameLauncher` seam

```swift
public protocol GameLauncher: Sendable { @MainActor func launch(_ game: LaunchableGame) async throws }
```

Play on a playable game builds a `LaunchableGame` (title ID, name, manifest, bundle folder, framework URL, data folder, the app's `Documents/games/<title ID>/`, every `DM_*` value as a dictionary, the picked cloud-save folder) and calls `launch`. A thrown error is shown as the notice. `StubGameLauncher` only logs and throws `GameLaunchError.notAvailable` ("Launching is not available yet."). Route C's M2 (#144) plugs in the real launcher: it sets the environment from `environment` and the folders (`DM_PROFILE`, `DM_ROMFS`, `DM_SAVE`, `DM_TEMP`, `DM_SAVE_SYNC` from `cloudSavesURL`), `dlopen`s `frameworkURL` and starts the host with the manifest's modules. Nothing else in the host changes: pass it as `launcher:`. The engine and `dm/` are not part of this package.

### Host mode of the demo

`--host` runs `ShellHostView` on the fixture bundles in `Tests/ShellHostTests/Fixtures/Games` (the Xcode app carries them as its `Games` folder, the package executable takes `--games-dir <folder>`): playable, needs game data, app update (another chain and a newer OS) and broken (no framework, damaged manifest, manifest without keys, damaged settings list). They hold no game data and no pictures (`.gitignore` keeps images out, the tests draw their own). Marker files in a temporary app-data folder make most of them playable, and launching is the stub. `--select <title ID>` picks the first game.

## Layouts

Only the available size decides, never the device model, idiom or orientation (`ShellLayout` in `LibraryView.swift`):
Expand Down
53 changes: 53 additions & 0 deletions frontend-ios/Sources/ShellDemo/HostDemo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import SwiftUI
import ShellHost
import ShellUI

/// `--host`: the same views on `ShellHost` instead of the sample values. The games are the fixture bundles from
/// `Tests/ShellHostTests/Fixtures/Games` (in the app's `Games` folder, or `--games-dir <folder>`): valid ones, one built
/// for another chain, one for a newer OS, and broken ones. Each valid game gets an empty marker file in a temporary
/// app-data folder, which makes it playable, except "Quiet Fixture", which stays at "needs game data". Launching is the
/// stub. Choices go to throwaway defaults suites that are cleared at every start.
struct HostDemoScreen: View {
@State private var model: ShellHostModel

init() {
let args = ProcessInfo.processInfo.arguments
let fm = FileManager.default
let gamesRoot: URL
if let i = args.firstIndex(of: "--games-dir"), args.indices.contains(i + 1) {
gamesRoot = URL(fileURLWithPath: args[i + 1], isDirectory: true)
} else {
gamesRoot = Bundle.main.url(forResource: "Games", withExtension: nil)
?? (fm.urls(for: .documentDirectory, in: .userDomainMask).first ?? fm.temporaryDirectory).appendingPathComponent("Games")
}
let appData = fm.temporaryDirectory.appendingPathComponent("shell-demo-appdata", isDirectory: true)
try? fm.removeItem(at: appData)
try? fm.createDirectory(at: appData, withIntermediateDirectories: true)
let entries = GameCatalogue.scan(root: gamesRoot)
for entry in entries { UserDefaults().removePersistentDomain(forName: Self.suite + entry.id) }
for entry in entries where entry.problem == nil && entry.id != "0100000000080000" {
guard let marker = entry.manifest?.romfsMarker else { continue }
let file = appData.appendingPathComponent(entry.id).appendingPathComponent("romfs", isDirectory: true).appendingPathComponent(marker)
try? fm.createDirectory(at: file.deletingLastPathComponent(), withIntermediateDirectories: true)
fm.createFile(atPath: file.path, contents: Data())
}
let suite = Self.suite
let config = ShellHostConfig(gamesRoot: gamesRoot, appDataRoot: appData,
environment: HostEnvironment(chain: "b-3f9a2c"),
updateURL: URL(string: "https://github.com/LNPANDY/NX2Apple/releases"),
defaults: { UserDefaults(suiteName: suite + $0) ?? .standard })
#if canImport(UIKit)
_model = State(initialValue: ShellHostModel(config: config, picker: DocumentFolderPicker()))
#else
_model = State(initialValue: ShellHostModel(config: config))
#endif
}

private static let suite = "dev.nx2apple.shell.demo."

var body: some View {
ShellHostView(model: model, initialSelection: ProcessInfo.processInfo.arguments.firstIndex(of: "--select")
.flatMap { ProcessInfo.processInfo.arguments.indices.contains($0 + 1) ? ProcessInfo.processInfo.arguments[$0 + 1] : nil })
.background(ShellPalette.background)
}
}
6 changes: 5 additions & 1 deletion frontend-ios/Sources/ShellDemo/ShellDemoApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import ShellUI
import ShellControllers

@main struct ShellDemoApp: App {
var body: some Scene { WindowGroup { DemoScreen() } }
var body: some Scene {
WindowGroup {
if ProcessInfo.processInfo.arguments.contains("--host") { HostDemoScreen() } else { DemoScreen() }
}
}
}

/// The demo owns sample values. None of this state or callback simulation is part of ShellUI.
Expand Down
Loading
Loading