Files
yattee/Yattee/Extensions/UIApplication+ForegroundScene.swift
Arkadiusz Fal 5f31610489 Look up the foreground scene instead of the first connected one
The swipe-action share sheet, the expanded player's safe area and the
Dynamic Island side check took connectedScenes.first, which ignores
which scene is active (on the iPhone Duo it can be the other panel's)
and presented the share sheet from the main window, behind an expanded
player.

UIApplication.foregroundWindowScene/foregroundWindow resolve the
foreground-active scene (else foreground-inactive, else any) and its
key window, the order the widescreen layout already used. The share
sheet now presents from the key window, which is the player's while it
is up. The tvOS display mode manager uses the same lookup.
2026-10-04 23:27:18 +02:00

31 lines
1.1 KiB
Swift

//
// UIApplication+ForegroundScene.swift
// Yattee
//
// The window scene and window the user is looking at, for code that has no
// view of its own to ask. `connectedScenes.first` is not that: on the iPhone
// Duo it can be the other panel's scene, and it ignores which one is active.
//
#if canImport(UIKit)
import UIKit
extension UIApplication {
/// The foreground-active scene, else a foreground-inactive one (Control
/// Center or Notification Center open over the app), else any scene.
var foregroundWindowScene: UIWindowScene? {
let scenes = connectedScenes.compactMap { $0 as? UIWindowScene }
return scenes.first { $0.activationState == .foregroundActive }
?? scenes.first { $0.activationState == .foregroundInactive }
?? scenes.first
}
/// The key window of `foregroundWindowScene` (the expanded player's window
/// while it is up), else its first window.
var foregroundWindow: UIWindow? {
let scene = foregroundWindowScene
return scene?.windows.first { $0.isKeyWindow } ?? scene?.windows.first
}
}
#endif