Fix a crash on iOS 26 when the scene's keyWindow is nil at cold start.

On iOS 26, `UIWindowScene.keyWindow` can be nil during scene connection
until the scene becomes active. The implicitly-unwrapped `mainWindow`
then crashes on the next line. Fall back to `scene.windows.first`, which
is the SwiftUI WindowGroup's window and is already attached to the scene
at this point.
This commit is contained in:
Daniel Anderson
2026-05-03 23:26:06 -06:00
committed by Mauro
parent 4a5cfc2f10
commit 1058c17511

View File

@@ -70,7 +70,9 @@ class WindowManager: SecureWindowManagerProtocol {
scene.resizeWindowOnMac(to: previousSize)
}
mainWindow = scene.keyWindow
// `keyWindow` can be nil on iOS 26 until the scene becomes active, but the
// SwiftUI WindowGroup's window is already attached to the scene by then.
mainWindow = scene.keyWindow ?? scene.windows.first
mainWindow.tintColor = .compound.textActionPrimary
overlayWindow = PassthroughWindow(windowScene: scene)