Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import AppKit

@MainActor
final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
true
}
}
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_executable(SimStore MACOSX_BUNDLE
AppDelegate.swift
SimStoreApp.swift
ContentView.swift
)
Expand Down
2 changes: 2 additions & 0 deletions src/SimStoreApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import SwiftUI

@main
struct SimStoreApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate

var body: some Scene {
WindowGroup("SimStore") {
ContentView()
Expand Down
32 changes: 32 additions & 0 deletions tests/AppLifecycleTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import AppKit

@main
struct AppLifecycleTest {
@MainActor
static func main() {
let application = NSApplication.shared
let delegate = AppDelegate()
application.delegate = delegate
application.setActivationPolicy(.regular)

let window = NSWindow(
contentRect: NSRect(x: 200, y: 200, width: 640, height: 420),
styleMask: [.titled, .closable],
backing: .buffered,
defer: false
)
window.isReleasedWhenClosed = false
window.makeKeyAndOrderFront(nil)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
guard window.isVisible else {
fatalError("The test window did not appear.")
}
print("Closing the last window; the process must exit normally.")
window.performClose(nil)
}
withExtendedLifetime(delegate) {
application.run()
}
fatalError("The application event loop returned without terminating the process.")
}
}
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ target_compile_options(SimStoreSmokeTest PRIVATE -parse-as-library)
add_test(NAME app-window COMMAND SimStoreSmokeTest "$<TARGET_BUNDLE_DIR:SimStore>")
set_tests_properties(app-window PROPERTIES TIMEOUT 20 RUN_SERIAL TRUE)

add_executable(SimStoreLifecycleTest AppLifecycleTest.swift "${PROJECT_SOURCE_DIR}/src/AppDelegate.swift")
add_test(NAME app-window-close COMMAND SimStoreLifecycleTest)
set_tests_properties(app-window-close PROPERTIES TIMEOUT 10 RUN_SERIAL TRUE)

execute_process(COMMAND xcrun --sdk "${CMAKE_OSX_SYSROOT}" --show-sdk-version
OUTPUT_VARIABLE SDK_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand Down