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
Mac launcher: a Settings switch to start in console mode (#336)
v0lumehi0c97c7724cc9
diff --git a/frontend/Sources/NX2Apple/ConsoleCoordinator.swift b/frontend/Sources/NX2Apple/ConsoleCoordinator.swiftindex 9b63efbd..34ad4d82 100644--- a/frontend/Sources/NX2Apple/ConsoleCoordinator.swift+++ b/frontend/Sources/NX2Apple/ConsoleCoordinator.swift@@ -9,8 +9,17 @@ import AppKit/// once the game has quit. In the console the pointer hides after a few idle seconds.@MainActor final class ConsoleCoordinator: ObservableObject {@Published private(set) var active = false { didSet { if active != oldValue { active ? pointer.start() : pointer.stop() } } }- /// The launcher is showing (not the guided setup), so the mode can be entered.- @Published var available = false+ /// The launcher is showing (not the guided setup), so the mode can be entered. The first time it is, the Settings switch+ /// "Start in console mode" enters it (#336), with or without a controller: it is the player's own choice.+ @Published var available = false {+ didSet {+ guard available, !startHandled else { return }+ startHandled = true+ if ConsolePrompt.shouldStartInConsole(setting: startInConsole(), handled: false) { enter() }+ }+ }+ private var startHandled = false+ private let startInConsole: () -> Boolprivate var enteredFullScreen = falseprivate var entering = falseprivate var leftForGame = false@@ -31,7 +40,9 @@ import AppKitinit(window: @escaping () -> NSWindow? = { NSApp.keyWindow ?? NSApp.windows.first { $0.canBecomeMain } },setFullScreen: @escaping @MainActor (NSWindow, Bool, @escaping () -> Void) -> Void = ConsoleCoordinator.toggleFullScreen,fadeSeconds: TimeInterval = ConsoleCoordinator.transitionSeconds + 0.05,- appIsActive: @escaping () -> Bool = { NSApp?.isActive ?? true }) {+ appIsActive: @escaping () -> Bool = { NSApp?.isActive ?? true },+ startInConsole: @escaping () -> Bool = { ConsolePrompt.startInConsole }) {+ self.startInConsole = startInConsoleself.appIsActive = appIsActiveself.window = windowself.setFullScreen = setFullScreen@@ -124,8 +135,14 @@ struct CalmTransition: ViewModifier {}/// The controller-connect prompt: once per session, and never when the player turned it off in Settings.+/// On top of it, "Start in console mode" (`startKey`) enters the mode when the launcher starts, no controller needed.enum ConsolePrompt {static let defaultsKey = "consolePrompt"+ static let startKey = "consoleStartAtLaunch"+ static var startInConsole: Bool { UserDefaults.standard.bool(forKey: startKey) }+ /// Once per launch of the app: the first time the launcher is showing, and only when the player turned the setting on.+ /// Leaving the mode afterwards is respected until the next launch.+ static func shouldStartInConsole(setting: Bool, handled: Bool) -> Bool { setting && !handled }private(set) static var shownThisSession = falsestatic var enabled: Bool { UserDefaults.standard.object(forKey: defaultsKey) as? Bool ?? true }static func shouldShow(enabled: Bool, shown: Bool) -> Bool { enabled && !shown }diff --git a/frontend/Sources/NX2Apple/SettingsPage.swift b/frontend/Sources/NX2Apple/SettingsPage.swiftindex ac43bf9d..01c94bf1 100644--- a/frontend/Sources/NX2Apple/SettingsPage.swift+++ b/frontend/Sources/NX2Apple/SettingsPage.swift@@ -21,6 +21,7 @@ struct SettingsPage: View {var controlChanges = 0var padMerge: Binding<Bool> = .constant(false) // "All controllers are player 1" (ControlLayout.padMerge)@AppStorage(ConsolePrompt.defaultsKey) private var consolePromptOn = true // ConsoleCoordinator.swift+ @AppStorage(ConsolePrompt.startKey) private var startInConsole = false // ConsoleCoordinator.swift (#336)@AppStorage(BuildNotice.defaultsKey) private var notifyBuilds = true // BuildNotifications.swift@AppStorage(ReturnAfterPlay.defaultsKey) private var returnAfterPlay = true // ReturnAfterPlay.swift@EnvironmentObject var loc: Localizer@@ -29,7 +30,7 @@ struct SettingsPage: View {CardPageHeading(loc.t("settings.heading"), note: loc.t("settings.note"))LibraryCard(library: library, onChooseFolder: onChooseLibraryFolder)ControlsCard(controlChanges: controlChanges, padMerge: padMerge, consolePrompt: $consolePromptOn,- onOpenControls: onOpenControls, onOpenControllers: onOpenControllers)+ startInConsole: $startInConsole, onOpenControls: onOpenControls, onOpenControllers: onOpenControllers)ToolsCard(repo: repo, engine: engine, dependencies: dependencies, buildRunning: build.running,shellCachePath: build.shellCachePath, revealFolder: { build.revealFolder($0) }) {DiagnosticsButton(report: diagnostics, game: library.selected)diff --git a/frontend/Sources/NXLauncher/ControlsCard.swift b/frontend/Sources/NXLauncher/ControlsCard.swiftindex 75207eba..7122b151 100644--- a/frontend/Sources/NXLauncher/ControlsCard.swift+++ b/frontend/Sources/NXLauncher/ControlsCard.swift@@ -8,15 +8,17 @@ package struct ControlsCard: View {let controlChanges: Intlet padMerge: Binding<Bool> // "All controllers are player 1" (ControlLayout.padMerge)let consolePrompt: Binding<Bool>+ let startInConsole: Binding<Bool> // "Start in console mode" (#336)let onOpenControls: () -> Voidlet onOpenControllers: () -> Void // the Controllers sheet (the console mode's list, with the player-mode setting)@EnvironmentObject var loc: Localizerpackage init(controlChanges: Int, padMerge: Binding<Bool>, consolePrompt: Binding<Bool>,- onOpenControls: @escaping () -> Void, onOpenControllers: @escaping () -> Void) {+ startInConsole: Binding<Bool>, onOpenControls: @escaping () -> Void, onOpenControllers: @escaping () -> Void) {self.controlChanges = controlChangesself.padMerge = padMergeself.consolePrompt = consolePrompt+ self.startInConsole = startInConsoleself.onOpenControls = onOpenControlsself.onOpenControllers = onOpenControllers}@@ -42,6 +44,11 @@ package struct ControlsCard: View {Toggle("", isOn: consolePrompt).labelsHidden().toggleStyle(LauncherSwitchStyle()).padTarget("set.consolePrompt", scope: "main") { consolePrompt.wrappedValue.toggle() }}+ CardDivider()+ CardRow(loc.t("console.startInConsole"), detail: loc.t("console.startInConsoleNote")) {+ Toggle("", isOn: startInConsole).labelsHidden().toggleStyle(LauncherSwitchStyle())+ .padTarget("set.consoleStart", scope: "main") { startInConsole.wrappedValue.toggle() }+ }}}}diff --git a/frontend/Tests/NX2AppleTests/ConsoleLiveTests.swift b/frontend/Tests/NX2AppleTests/ConsoleLiveTests.swiftindex 97a21b80..177bf878 100644--- a/frontend/Tests/NX2AppleTests/ConsoleLiveTests.swift+++ b/frontend/Tests/NX2AppleTests/ConsoleLiveTests.swift@@ -276,6 +276,36 @@ import SwiftUIXCTAssertFalse(ConsolePrompt.shouldShow(enabled: false, shown: false))}+ /// #336 part 1: the Settings switch "Start in console mode" enters the mode when the launcher first shows, no controller needed.+ func testStartInConsoleEntersOnceWhenTheLauncherFirstShows() throws {+ XCTAssertTrue(ConsolePrompt.shouldStartInConsole(setting: true, handled: false))+ XCTAssertFalse(ConsolePrompt.shouldStartInConsole(setting: false, handled: false))+ XCTAssertFalse(ConsolePrompt.shouldStartInConsole(setting: true, handled: true))++ let window = OffscreenWindow(size: .zero)+ let on = ConsoleCoordinator(window: { window }, setFullScreen: { _, _, done in done() }, fadeSeconds: 0.05, startInConsole: { true })+ XCTAssertFalse(on.active, "not before the launcher shows")+ on.available = true+ XCTAssertTrue(on.active, "entered without any controller")+ on.exit()+ on.available = false // the guided setup again, then the launcher+ on.available = true+ XCTAssertFalse(on.active, "leaving the mode is respected until the next start")++ let off = ConsoleCoordinator(window: { window }, setFullScreen: { _, _, done in done() }, fadeSeconds: 0.05, startInConsole: { false })+ off.available = true+ XCTAssertFalse(off.active)+ }++ func testStartInConsoleWaitsForTheGuidedSetup() throws {+ let window = OffscreenWindow(size: .zero)+ let coordinator = ConsoleCoordinator(window: { window }, setFullScreen: { _, _, done in done() }, fadeSeconds: 0.05, startInConsole: { true })+ coordinator.available = false+ XCTAssertFalse(coordinator.active, "the setup is no place for the console")+ coordinator.available = true+ XCTAssertTrue(coordinator.active, "the first time the launcher shows")+ }+func testBatteryFillFraction() {XCTAssertEqual(BatteryIcon.fillFraction(0.76), 0.76)XCTAssertEqual(BatteryIcon.fillFraction(0), 0)diff --git a/frontend/l10n/de.json b/frontend/l10n/de.jsonindex f65a5f62..95a8fce3 100644--- a/frontend/l10n/de.json+++ b/frontend/l10n/de.json@@ -205,6 +205,8 @@"console.shaders": "Shader werden kompiliert","console.shadersProgress": "Shader werden kompiliert · %d von %d","console.simulatedShaders": "Simulierter Fortschritt in dieser Vorschau",+ "console.startInConsole": "Im Konsolenmodus starten",+ "console.startInConsoleNote": "Öffnet bei jedem Start des Launchers den Konsolenmodus, mit oder ohne Controller. Beenden über das Menü „Darstellung“.","console.starting": "%@ startet …","console.startingNote": "Dein Spiel wird vorbereitet","console.unassigned": "Nicht zugewiesen",diff --git a/frontend/l10n/en.json b/frontend/l10n/en.jsonindex c18d9e6e..5e2be2b3 100644--- a/frontend/l10n/en.json+++ b/frontend/l10n/en.json@@ -203,6 +203,8 @@"console.shaders": "Compiling shaders","console.shadersProgress": "Compiling shaders · %d of %d","console.simulatedShaders": "Simulated progress in this preview",+ "console.startInConsole": "Start in console mode",+ "console.startInConsoleNote": "Opens the console mode every time the launcher starts, with or without a controller. Leave it from the View menu.","console.starting": "Starting %@…","console.startingNote": "Getting your game ready","console.unassigned": "Unassigned",diff --git a/frontend/l10n/fr.json b/frontend/l10n/fr.jsonindex 48164583..9415c6ae 100644--- a/frontend/l10n/fr.json+++ b/frontend/l10n/fr.json@@ -204,6 +204,8 @@"console.shaders": "Compilation des shaders","console.shadersProgress": "Compilation des shaders · %d sur %d","console.simulatedShaders": "Progression simulée dans cet aperçu",+ "console.startInConsole": "Démarrer en mode console",+ "console.startInConsoleNote": "Ouvre le mode console à chaque démarrage du lanceur, avec ou sans manette. Pour le quitter, utilisez le menu Présentation.","console.starting": "Démarrage de %@…","console.startingNote": "Préparation de votre jeu","console.unassigned": "Non attribuée",diff --git a/frontend/l10n/it.json b/frontend/l10n/it.jsonindex f5fd17bf..22bf9f00 100644--- a/frontend/l10n/it.json+++ b/frontend/l10n/it.json@@ -204,6 +204,8 @@"console.shaders": "Compilazione degli shader","console.shadersProgress": "Compilazione degli shader · %d di %d","console.simulatedShaders": "Avanzamento simulato in questa anteprima",+ "console.startInConsole": "Avvia in modalità console",+ "console.startInConsoleNote": "Apre la modalità console a ogni avvio del launcher, con o senza controller. Per uscire usa il menu Vista.","console.starting": "Avvio di %@…","console.startingNote": "Preparazione del gioco","console.unassigned": "Non assegnato",diff --git a/frontend/l10n/sv.json b/frontend/l10n/sv.jsonindex f27c3a9a..2de63c69 100644--- a/frontend/l10n/sv.json+++ b/frontend/l10n/sv.json@@ -114,6 +114,8 @@"cloud.state.waiting": "En nyare sparfil har inte skickats än. Den skickas vid nästa start.","cloud.title": "Molnsparfiler","cloud.turnOff": "Stäng av",+ "console.startInConsole": "Starta i konsolläge",+ "console.startInConsoleNote": "Öppnar konsolläget varje gång launchern startar, med eller utan handkontroll. Lämna det från menyn Visa.","controls.applied": "Tillämpas nästa gång du väljer Spela här. Äldre byggen ignorerar det.","controls.changes": "%d ändringar","controls.clear": "Ingen tangent",diff --git a/frontend/l10n/zh.json b/frontend/l10n/zh.jsonindex 9ed3eaa0..32fbdb37 100644--- a/frontend/l10n/zh.json+++ b/frontend/l10n/zh.json@@ -204,6 +204,8 @@"console.shaders": "正在编译着色器","console.shadersProgress": "正在编译着色器 · %d / %d","console.simulatedShaders": "此预览中的进度为模拟进度",+ "console.startInConsole": "启动时进入主机模式",+ "console.startInConsoleNote": "每次启动启动器都直接进入主机模式,不论是否连接手柄。可从「显示」菜单退出。","console.starting": "正在启动 %@…","console.startingNote": "正在准备游戏","console.unassigned": "未分配",