Files
ghostgram/submodules/Display/Source/UIApplicationWindowScenes.swift
ichmagmaus111andClaude Opus 5.5 0622057a4f Ghostgram: open-source release
Ghostgram for iOS, rebuilt from scratch on Telegram iOS 13.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 17:57:09 +01:00

33 lines
1.6 KiB
Swift

import UIKit
public extension UIApplication {
/// Replacement for `UIApplication.windows`, which iOS 15 deprecated in favour of reading the
/// windows off a relevant `UIWindowScene`.
///
/// Collects the windows of every connected window scene. Within a scene the ordering matches what
/// the old property returned, so for the single-scene case — which is what the app runs in outside
/// of external-display setups — `first` / `last` / `reversed()` keep their previous meaning.
var allWindowSceneWindows: [UIWindow] {
// `connectedScenes` is an unordered Set, while the old `windows` property was ordered
// back-to-front by window level. Prefer the foreground-active scene so that callers taking
// `first`/`last`/`reversed()` see the scene the user is actually looking at (iPad
// multi-window, Stage Manager and external displays all produce several window scenes),
// and sort by level to restore the documented ordering.
var windowScenes: [UIWindowScene] = []
for scene in self.connectedScenes {
guard let windowScene = scene as? UIWindowScene else {
continue
}
windowScenes.append(windowScene)
}
let foregroundScenes = windowScenes.filter { $0.activationState == .foregroundActive }
let effectiveScenes = foregroundScenes.isEmpty ? windowScenes : foregroundScenes
var result: [UIWindow] = []
for windowScene in effectiveScenes {
result.append(contentsOf: windowScene.windows.sorted(by: { $0.windowLevel < $1.windowLevel }))
}
return result
}
}