2023-03-08 16:57:39 +01:00
|
|
|
//
|
|
|
|
// https://mczachurski.dev
|
|
|
|
// Copyright © 2023 Marcin Czachurski and the repository contributors.
|
2023-03-28 10:35:38 +02:00
|
|
|
// Licensed under the Apache License 2.0.
|
2023-03-08 16:57:39 +01:00
|
|
|
//
|
2023-04-01 12:10:59 +02:00
|
|
|
|
2023-03-08 16:57:39 +01:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
extension UIApplication {
|
|
|
|
var keyWindow: UIWindow? {
|
|
|
|
// Get connected scenes
|
|
|
|
return UIApplication.shared.connectedScenes
|
|
|
|
// Keep only active scenes, onscreen and visible to the user
|
|
|
|
.filter { $0.activationState == .foregroundActive }
|
|
|
|
// Keep only the first `UIWindowScene`
|
|
|
|
.first(where: { $0 is UIWindowScene })
|
|
|
|
// Get its associated windows
|
|
|
|
.flatMap({ $0 as? UIWindowScene })?.windows
|
|
|
|
// Finally, keep only the key window
|
|
|
|
.first(where: \.isKeyWindow)
|
|
|
|
}
|
|
|
|
}
|