From 4188a10ea96ab630bfb48582ba9844fb865c544f Mon Sep 17 00:00:00 2001 From: Daniel Anderson Date: Sun, 3 May 2026 23:26:06 -0600 Subject: [PATCH] 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. --- ElementX/Sources/Application/Windowing/WindowManager.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ElementX/Sources/Application/Windowing/WindowManager.swift b/ElementX/Sources/Application/Windowing/WindowManager.swift index 03d7b914a..08dc3728e 100644 --- a/ElementX/Sources/Application/Windowing/WindowManager.swift +++ b/ElementX/Sources/Application/Windowing/WindowManager.swift @@ -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)