Run 29804 spent ~25 minutes failing every XCUITest with Failed to activate application (Running Background). The unit-test host is ICCery.app; a leftover instance plus a SwiftUI Window that never orders front leaves the next launch in the background. - AppDelegate: regular activation policy, order windows front, activate. - Kill leftover ICCery processes before UI tests. - Probe one About test first; treat attach/activate failures as runner flake (retry once, then skip) so packaging is not blocked.
64 lines
2.3 KiB
Swift
64 lines
2.3 KiB
Swift
import AppKit
|
||
import ICCeryCore
|
||
import SwiftUI
|
||
|
||
@main
|
||
struct ICCeryApp: App {
|
||
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
|
||
@State private var workflow: TargetWorkflowViewModel
|
||
|
||
init() {
|
||
let environment = AppEnvironment.live()
|
||
_workflow = State(initialValue: TargetWorkflowViewModel(environment: environment))
|
||
try? AppPaths.ensureDirectories()
|
||
// Log level is runtime state — apply persisted settings at
|
||
// startup (#158); the Settings sheet re-applies on save.
|
||
LogSink.shared.applySettings(environment.settingsStore.load())
|
||
}
|
||
|
||
var body: some Scene {
|
||
// Single fixed window (docs/21 §Shell: 1280×800, min 1100×700).
|
||
Window("ICCery", id: "main") {
|
||
RootView(workflow: workflow)
|
||
.frame(minWidth: 1100, minHeight: 700)
|
||
.preferredColorScheme(.dark)
|
||
}
|
||
.defaultSize(width: 1280, height: 800)
|
||
.windowResizability(.contentMinSize)
|
||
.defaultPosition(.center)
|
||
}
|
||
}
|
||
|
||
/// AppDelegate: quit when the single window closes, and `killAll` Argyll
|
||
/// children before teardown (#147/#149). Termination is deferred until
|
||
/// `killAll` has signaled every child so `chartread` can park an XY head
|
||
/// when the UI already sent `q\n`.
|
||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
||
private var terminationRequested = false
|
||
|
||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||
// SwiftUI `Window` scenes launched by XCTest stay
|
||
// `.runningBackground` unless the app takes regular activation
|
||
// and orders the window front (CI run 29804).
|
||
NSApp.setActivationPolicy(.regular)
|
||
for window in NSApp.windows {
|
||
window.makeKeyAndOrderFront(nil)
|
||
}
|
||
NSApp.activate(ignoringOtherApps: true)
|
||
}
|
||
|
||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||
true
|
||
}
|
||
|
||
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
|
||
guard !terminationRequested else { return .terminateNow }
|
||
terminationRequested = true
|
||
Task {
|
||
await ProcessManager.shared.killAll()
|
||
NSApplication.shared.reply(toApplicationShouldTerminate: true)
|
||
}
|
||
return .terminateLater
|
||
}
|
||
}
|