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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user