Skip to content

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

Console mode launches games fullscreen

LNPANDY219403ff046d
diff --git a/frontend/Sources/NSPortBuilder/ConsoleState.swift b/frontend/Sources/NSPortBuilder/ConsoleState.swift
index f4242953..0084c320 100644
--- a/frontend/Sources/NSPortBuilder/ConsoleState.swift
+++ b/frontend/Sources/NSPortBuilder/ConsoleState.swift
@@ -41,6 +41,8 @@ struct ConsoleGame: Identifiable {
func value(_ setting: LaunchSetting) -> String { values[setting.env] ?? setting.def }
var visibleSettings: [LaunchSetting] {
settings.filter { setting in
+ // Console mode launches fullscreen whatever Display says (GameStart's fullscreen), so the sheet does not offer it.
+ guard setting.env != "DM_FULLSCREEN" else { return false }
guard let needs = setting.needs else { return true }
let parts = needs.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false).map(String.init)
guard parts.count == 2, let parent = settings.first(where: { $0.env == parts[0] }) else { return false }
diff --git a/frontend/Sources/NSPortBuilder/GameStart.swift b/frontend/Sources/NSPortBuilder/GameStart.swift
index 3ee09b5c..6452e391 100644
--- a/frontend/Sources/NSPortBuilder/GameStart.swift
+++ b/frontend/Sources/NSPortBuilder/GameStart.swift
@@ -3,10 +3,11 @@ import Foundation
/// What Play starts a Mac game with, in one place: the desktop launcher's Play button and the console mode both use it, so a
/// game gets the same environment from either (the saved choices for an app that does not read them itself, the mods, the Controls
-/// page's layout, DM_PAD_MERGE, DM_SCREEN and DM_LAUNCHER=0).
+/// page's layout, DM_PAD_MERGE, DM_SCREEN and DM_LAUNCHER=0). Console mode plays on a TV-sized screen with a controller, so it asks for
+/// `fullscreen`, which forces DM_FULLSCREEN on whatever the game's Display setting says.
enum GameStart {
@MainActor static func environment(for game: LibraryGame, library: GameLibrary, controls: ControlLayout, repo: String,
- labels: (String) -> String,
+ labels: (String) -> String, fullscreen: Bool = false,
screen: NSScreen? = NSApp?.keyWindow?.screen ?? NSScreen.main) -> [String: String] {
library.migrateLaunchOptions()
CloudSavesMigration.run() // before the app reads its env.txt: DM_SAVE_SYNC=icloud keeps the folder the iPhone app uses
@@ -15,6 +16,7 @@ enum GameStart {
var environment = game.startEnvironment(controls: controls.environment, settings: settings, mods: mods,
store: SavedChoices(app: game.appPath, titleID: game.titleID),
appReadsStore: SavedChoices.appReadsStore(app: game.appPath))
+ if fullscreen, settings.contains(where: { $0.env == "DM_FULLSCREEN" }) { environment["DM_FULLSCREEN"] = "1" }
if let id = displayID(of: screen) { environment["DM_SCREEN"] = String(id) }
return environment
}
diff --git a/frontend/Sources/NSPortBuilder/LiveConsoleDriver.swift b/frontend/Sources/NSPortBuilder/LiveConsoleDriver.swift
index 5801699a..4fa4b5cc 100644
--- a/frontend/Sources/NSPortBuilder/LiveConsoleDriver.swift
+++ b/frontend/Sources/NSPortBuilder/LiveConsoleDriver.swift
@@ -221,7 +221,7 @@ struct ConsolePadSnapshot: Equatable {
func play(_ gameID: String) {
state.play(gameID)
guard state.startingGameID == gameID, let game = library.games.first(where: { $0.id.uuidString == gameID }) else { return }
- let environment = GameStart.environment(for: game, library: library, controls: controls, repo: repo(), labels: labels)
+ let environment = GameStart.environment(for: game, library: library, controls: controls, repo: repo(), labels: labels, fullscreen: true)
state.starting = .preparing
launch(game, environment) { [weak self] pid, error in
DispatchQueue.main.async {
diff --git a/frontend/Sources/NSPortBuilder/MockConsoleDriver.swift b/frontend/Sources/NSPortBuilder/MockConsoleDriver.swift
index 9a9514fe..207c165e 100644
--- a/frontend/Sources/NSPortBuilder/MockConsoleDriver.swift
+++ b/frontend/Sources/NSPortBuilder/MockConsoleDriver.swift
@@ -20,8 +20,6 @@ import SwiftUI
options: [["30", t("console.fps30")], ["60", t("console.fps60")]], min: nil, max: nil, step: nil, on: nil, off: nil),
LaunchSetting(env: "DM_LANG", kind: "choice", label: t("console.language"), note: "", def: "en", section: nil,
options: [["en", t("console.english")], ["zh", t("console.chinese")], ["ja", t("console.japanese")]], min: nil, max: nil, step: nil, on: nil, off: nil),
- LaunchSetting(env: "DM_FULLSCREEN", kind: "toggle", label: t("console.fullscreen"), note: "", def: "1", section: nil,
- options: nil, min: nil, max: nil, step: nil, on: nil, off: nil),
LaunchSetting(env: "DM_RUMBLE", kind: "toggle", label: t("console.rumble"), note: "", def: "1", section: nil,
options: nil, min: nil, max: nil, step: nil, on: nil, off: nil)
]
diff --git a/frontend/Tests/NSPortBuilderTests/ConsoleLiveTests.swift b/frontend/Tests/NSPortBuilderTests/ConsoleLiveTests.swift
index 595267f0..a46edeac 100644
--- a/frontend/Tests/NSPortBuilderTests/ConsoleLiveTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/ConsoleLiveTests.swift
@@ -78,9 +78,23 @@ import SwiftUI
XCTAssertEqual(launches.first?.environment["DM_PAD_MERGE"], "1")
XCTAssertEqual(launches.first?.environment["DM_LAUNCHER"], "0")
if let main = NSScreen.main { XCTAssertEqual(launches.first?.environment["DM_SCREEN"], GameStart.displayID(of: main).map(String.init), "the game opens on the launcher's display") }
+ XCTAssertEqual(launches.first?.environment["DM_FULLSCREEN"], "1", "console mode plays fullscreen whatever Display says")
XCTAssertEqual(launches.first?.game.titleID, titleID)
- let expected = launches.first.map { GameStart.environment(for: $0.game, library: GameLibrary(file: temporary.appendingPathComponent("other.json")), controls: layout, repo: "", labels: { $0 }) }
- XCTAssertEqual(launches.first?.environment, expected, "the same function the desktop Play uses")
+ let expected = launches.first.map { GameStart.environment(for: $0.game, library: GameLibrary(file: temporary.appendingPathComponent("other.json")), controls: layout, repo: "", labels: { $0 }, fullscreen: true) }
+ XCTAssertEqual(launches.first?.environment, expected, "the same function the desktop Play uses, with the console's fullscreen")
+ }
+
+ func testConsoleLaunchesFullscreenOverTheSavedDisplayChoice() throws {
+ var launches: [Launch] = []
+ let (driver, library, _) = try makeDriver { launches.append($0) }
+ let game = try XCTUnwrap(library.games.first)
+ let display = try XCTUnwrap(LaunchSetting.forMac(app: game.appPath, titleID: game.titleID, repo: "", labels: { $0 })?.first { $0.env == "DM_FULLSCREEN" })
+ library.setLaunchOption(display, display.onValue, for: game.id) // a saved Fullscreen choice, as the desktop would record it
+ driver.refresh()
+ let id = try XCTUnwrap(driver.state.games.first?.id)
+ driver.play(id)
+ XCTAssertEqual(launches.first?.environment["DM_FULLSCREEN"], "1")
+ XCTAssertNil(driver.state.games.first?.visibleSettings.first { $0.env == "DM_FULLSCREEN" }, "the sheet does not offer what Play overrides")
}
func testStartingEndsWhenTheGameQuits() async throws {