mirror of https://github.com/xaoxuu/ProHUD
mainWindowScene
This commit is contained in:
parent
b62c027cd5
commit
238ffa1055
|
@ -21,7 +21,7 @@ class AlertWindow: Window {
|
|||
}
|
||||
let w: AlertWindow
|
||||
if #available(iOS 13.0, *) {
|
||||
if let scene = config.windowScene ?? UIApplication.shared.windows.last?.windowScene {
|
||||
if let scene = config.windowScene ?? UIWindowScene.mainWindowScene {
|
||||
w = .init(windowScene: scene)
|
||||
} else {
|
||||
w = .init(frame: UIScreen.main.bounds)
|
||||
|
|
|
@ -52,3 +52,15 @@ class Window: UIWindow {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@available(iOS 13.0, *)
|
||||
extension UIWindowScene {
|
||||
|
||||
static var mainWindowScene: UIWindowScene? {
|
||||
UIApplication.shared.connectedScenes.first(where: { scene in
|
||||
guard let ws = scene as? UIWindowScene else { return false }
|
||||
return ws.activationState == .foregroundActive
|
||||
}) as? UIWindowScene
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class SheetWindow: Window {
|
|||
init(sheet: Sheet) {
|
||||
self.sheet = sheet
|
||||
if #available(iOS 13.0, *) {
|
||||
if let scene = sheet.config.windowScene ?? UIApplication.shared.windows.last?.windowScene {
|
||||
if let scene = sheet.config.windowScene ?? UIWindowScene.mainWindowScene {
|
||||
super.init(windowScene: scene)
|
||||
} else {
|
||||
super.init(frame: UIScreen.main.bounds)
|
||||
|
|
|
@ -19,7 +19,7 @@ class ToastWindow: Window {
|
|||
self.toast = toast
|
||||
super.init(frame: .zero)
|
||||
if #available(iOS 13.0, *) {
|
||||
windowScene = toast.config.windowScene ?? UIApplication.shared.windows.last?.windowScene
|
||||
windowScene = toast.config.windowScene ?? UIWindowScene.mainWindowScene
|
||||
}
|
||||
toast.window = self
|
||||
windowLevel = .init(rawValue: UIWindow.Level.alert.rawValue + 1000)
|
||||
|
|
Loading…
Reference in New Issue