Skip to content

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

Console: games ready on this Mac first, no filter pills

v0lumehi4cff52d4489f
diff --git a/frontend/Sources/NSPortBuilder/ConsoleState.swift b/frontend/Sources/NSPortBuilder/ConsoleState.swift
index 0084c320..e0a7062f 100644
--- a/frontend/Sources/NSPortBuilder/ConsoleState.swift
+++ b/frontend/Sources/NSPortBuilder/ConsoleState.swift
@@ -38,6 +38,11 @@ struct ConsoleGame: Identifiable {
var settings: [LaunchSetting] = []
var values: [String: String] = [:]
+ /// The console's order: the games this Mac can play first, then the rest, each group in the order it came in.
+ static func readyFirst(_ games: [ConsoleGame]) -> [ConsoleGame] {
+ games.filter { $0.status == .ready } + games.filter { $0.status != .ready }
+ }
+
func value(_ setting: LaunchSetting) -> String { values[setting.env] ?? setting.def }
var visibleSettings: [LaunchSetting] {
settings.filter { setting in
diff --git a/frontend/Sources/NSPortBuilder/ConsoleView.swift b/frontend/Sources/NSPortBuilder/ConsoleView.swift
index f257b8cc..fae42a65 100644
--- a/frontend/Sources/NSPortBuilder/ConsoleView.swift
+++ b/frontend/Sources/NSPortBuilder/ConsoleView.swift
@@ -22,23 +22,6 @@ enum ConsoleInput {
}
}
-/// The console collection's filter ("全部 / 已构建 / iPhone"): display-only over the driver's games.
-enum ConsoleFilter: String, CaseIterable, Identifiable {
- case all, built, iphone
-
- var id: String { rawValue }
-
- func label(_ lang: Lang) -> String {
- let zh = ["全部", "已构建", "iPhone"]
- let de = ["Alle", "Gebaut", "iPhone"]
- switch lang {
- case .zh: return zh[Self.allCases.firstIndex(of: self)!]
- case .de: return de[Self.allCases.firstIndex(of: self)!]
- default: return ["All", "Built", "iPhone"][Self.allCases.firstIndex(of: self)!]
- }
- }
-}
-
@MainActor struct ConsoleView<Driver: ConsoleDriver>: View {
@ObservedObject var driver: Driver
var lang: Lang = .initial()
@@ -52,16 +35,6 @@ enum ConsoleFilter: String, CaseIterable, Identifiable {
@StateObject private var gamepad: LauncherGamepad
@State private var tileFrames: [String: CGRect] = [:]
@State private var updateAlert: String?
- /// The collection filter ("全部 / 已构建 / iPhone"): display-only, the driver keeps every game.
- @State private var consoleFilter: ConsoleFilter = .all
-
- private var visibleGames: [ConsoleGame] {
- switch consoleFilter {
- case .all: return state.games
- case .built: return state.games.filter { $0.status == .ready }
- case .iphone: return state.games.filter { $0.platforms.contains(.iphone) || $0.status == .iphoneOnly }
- }
- }
/// The glyph set follows the input used last: a controller's own buttons, or key caps after the keyboard.
@State private var glyphs: ConsoleGlyphs
@@ -221,22 +194,6 @@ enum ConsoleFilter: String, CaseIterable, Identifiable {
.buttonStyle(.plain)
.accessibilityLabel(String(format: lang == .zh ? "更新 %@" : "Update %@", updateTag))
}
- if state.games.count > 1 {
- HStack(spacing: compact ? 5 : 7) {
- ForEach([ConsoleFilter.all, .built, .iphone]) { f in
- Button { withAnimation(.easeInOut(duration: 0.15)) { consoleFilter = f } } label: {
- Text(f.label(lang)).font(.manrope(compact ? 11 : 13, consoleFilter == f ? .bold : .medium))
- .padding(.horizontal, compact ? 8 : 11).padding(.vertical, compact ? 4 : 6)
- .background(consoleFilter == f ? Color.white.opacity(0.14) : Color.white.opacity(0.05), in: Capsule())
- .overlay(Capsule().strokeBorder(consoleFilter == f ? Color.white.opacity(0.3) : Color.white.opacity(0.08)))
- .contentShape(Capsule())
- }
- .buttonStyle(.plain)
- .accessibilityAddTraits(consoleFilter == f ? .isSelected : [])
- .accessibilityLabel(f.label(lang))
- }
- }
- }
Text(state.time, style: .time).font(.manrope(compact ? 17 : 22, .medium)).monospacedDigit()
.foregroundStyle(.white.opacity(0.65)).fixedSize()
}
@@ -254,7 +211,7 @@ enum ConsoleFilter: String, CaseIterable, Identifiable {
return ScrollViewReader { proxy in
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .top, spacing: (compact ? 22 : 28) - 16) {
- ForEach(visibleGames) { game in
+ ForEach(state.games) { game in
let selected = state.focusedGame?.id == game.id
Button { driver.focus(game.id); driver.play(game.id) } label: {
ConsoleGameTile(game: game, selected: selected, compact: compact, lang: lang, captionVisible: tileVisible(game.id, rowWidth: size.width - 2 * (inset - 8)))
@@ -559,6 +516,7 @@ struct ConsoleGameTile: View {
var body: some View {
VStack(alignment: .leading, spacing: 12) {
ConsoleArtwork(image: game.artwork, title: game.title).aspectRatio(1.8, contentMode: .fit)
+ .opacity(game.status == .ready ? 1 : 0.45) // not playable on this Mac: dimmed, its status on top
.overlay(alignment: .bottomLeading) {
if game.status != .ready {
Text(L10n.string(game.status.labelKey, lang)).font(.manrope(compact ? 14 : 18, .semibold))
diff --git a/frontend/Sources/NSPortBuilder/LiveConsoleDriver.swift b/frontend/Sources/NSPortBuilder/LiveConsoleDriver.swift
index 82f2989c..a1881275 100644
--- a/frontend/Sources/NSPortBuilder/LiveConsoleDriver.swift
+++ b/frontend/Sources/NSPortBuilder/LiveConsoleDriver.swift
@@ -131,10 +131,10 @@ struct ConsolePadSnapshot: Equatable {
DispatchQueue.main.async { [weak self] in self?.refreshQueued = false; self?.refresh() }
}
- /// The library as console games, in the library's order, keeping the focus and each game's shown values.
+ /// The library as console games, the ones ready on this Mac first, keeping the focus and each game's shown values.
func refresh() {
let focus = state.focusedGameID
- let games = library.games.map { consoleGame($0) }
+ let games = ConsoleGame.readyFirst(library.games.map { consoleGame($0) })
state.games = games
state.focusedGameID = games.contains { $0.id == focus } ? focus : (library.selected.map { $0.id.uuidString }.flatMap { id in games.contains { $0.id == id } ? id : nil } ?? games.first?.id)
state.time = Date()
diff --git a/frontend/Sources/NSPortBuilder/MockConsoleDriver.swift b/frontend/Sources/NSPortBuilder/MockConsoleDriver.swift
index 207c165e..c7ebeb00 100644
--- a/frontend/Sources/NSPortBuilder/MockConsoleDriver.swift
+++ b/frontend/Sources/NSPortBuilder/MockConsoleDriver.swift
@@ -26,14 +26,14 @@ import SwiftUI
// Library-style titles. Covers come from the launcher's own artwork lookup in the repo copy (nothing is bundled or downloaded).
let titles = ["Hollow Knight: Silksong", "Celeste", "Hades", "Sea of Stars", "Portal", "Balatro", "Animal Well", "Cuphead", "Stardew Valley", "Return of the Obra Dinn", "Blasphemous", "Hades II"]
let noBanners = FileManager.default.temporaryDirectory.appendingPathComponent("console-demo-no-banners") // the demo ids are invented: no eShop banner to find
- let games = titles.enumerated().map { index, title in
+ let games = ConsoleGame.readyFirst(titles.enumerated().map { index, title in
ConsoleGame(id: "demo.\(index)", title: title, version: "1.0.\(index % 3)", platforms: index % 3 == 1 ? [.mac] : [.mac, .iphone],
artwork: artworkRepo.flatMap { repo in
GameLibrary.artwork(for: LibraryGame(titleID: String(format: "%016X", index), name: title), repo: repo, banners: noBanners)
}.map { Image(nsImage: $0) }, // nil: the view draws a placeholder cover from the title
status: index == 3 ? .needsBuild : index == 5 ? .needsData : index == 7 ? .broken(t("console.demoBroken")) : index == 9 ? .iphoneOnly : .ready,
settings: settings)
- }
+ })
var snapshot = ConsoleState(games: scenario == .empty ? [] : scenario == .few ? Array(games.prefix(2)) : games,
focusedGameID: scenario == .empty ? nil : "demo.0",
controllers: [.init(id: "pad.1", name: t("console.demoController"), player: 1)],
diff --git a/frontend/Tests/NSPortBuilderTests/ConsoleTests.swift b/frontend/Tests/NSPortBuilderTests/ConsoleTests.swift
index ee544930..e42d02c1 100644
--- a/frontend/Tests/NSPortBuilderTests/ConsoleTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/ConsoleTests.swift
@@ -4,6 +4,15 @@ import Combine
@testable import NSPortBuilder
final class ConsoleTests: XCTestCase {
+ /// The games ready on this Mac come first. The rest follow in their own order, each with its status.
+ func testReadyGamesComeFirst() {
+ func game(_ id: String, _ status: ConsoleGame.Status) -> ConsoleGame {
+ ConsoleGame(id: id, title: id, version: "", platforms: [.mac], artwork: nil, status: status)
+ }
+ let games = [game("a", .needsBuild), game("b", .ready), game("c", .iphoneOnly), game("d", .ready), game("e", .broken("x"))]
+ XCTAssertEqual(ConsoleGame.readyFirst(games).map(\.id), ["b", "d", "a", "c", "e"])
+ }
+
@MainActor func testScenariosAndBoundedFocus() {
let driver = MockConsoleDriver(animated: false)
XCTAssertEqual(driver.state.games.count, 12)
@@ -16,7 +25,7 @@ final class ConsoleTests: XCTestCase {
state.moveFocus(-100)
XCTAssertEqual(state.focusedGame?.id, "demo.0")
state.moveFocus(100)
- XCTAssertEqual(state.focusedGame?.id, "demo.11")
+ XCTAssertEqual(state.focusedGame?.id, "demo.9", "the games this Mac cannot play come last")
XCTAssertEqual(MockConsoleDriver(scenario: .few, animated: false).state.games.count, 2)
var empty = MockConsoleDriver(scenario: .empty, animated: false).state
empty.moveFocus(1)