TestHostApp.swift•883 B
import AppKit
import SwiftUI
@main
struct TestHostApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
.frame(minWidth: 600, minHeight: 500)
.frame(width: 800, height: 600)
}
.windowResizability(.contentSize)
.windowStyle(.titleBar)
.defaultSize(width: 800, height: 600)
}
}
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
// Make sure the app appears in foreground
NSApp.activate(ignoringOtherApps: true)
// Set activation policy to regular app
NSApp.setActivationPolicy(.regular)
}
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
true
}
}