Skip to content

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

macOS: swift run shows the window

Yoan Ancellydc32650a5d34
diff --git a/frontend/Sources/NSPortBuilder/NSPortBuilderApp.swift b/frontend/Sources/NSPortBuilder/NSPortBuilderApp.swift
index 99326f63..ae6e5470 100644
--- a/frontend/Sources/NSPortBuilder/NSPortBuilderApp.swift
+++ b/frontend/Sources/NSPortBuilder/NSPortBuilderApp.swift
@@ -2,6 +2,8 @@ import SwiftUI
@main
struct NSPortBuilderApp: App {
+ @NSApplicationDelegateAdaptor private var delegate: AppDelegate
+
var body: some Scene {
WindowGroup("NX2Apple") { ContentView() }
.windowStyle(.hiddenTitleBar)
@@ -9,3 +11,13 @@ struct NSPortBuilderApp: App {
.windowResizability(.automatic)
}
}
+
+/// `swift run` starts a bare executable with no Info.plist, which macOS does not treat as a
+/// regular app: no Dock icon, and the window can stay hidden behind the terminal. Inside the
+/// .app bundle this changes nothing.
+final class AppDelegate: NSObject, NSApplicationDelegate {
+ func applicationDidFinishLaunching(_ notification: Notification) {
+ NSApp.setActivationPolicy(.regular)
+ NSApp.activate(ignoringOtherApps: true)
+ }
+}