diff --git a/Sources/ProHUD/Alert/AlertManager.swift b/Sources/ProHUD/Alert/AlertManager.swift index a356cda..30ce4ac 100644 --- a/Sources/ProHUD/Alert/AlertManager.swift +++ b/Sources/ProHUD/Alert/AlertManager.swift @@ -52,9 +52,8 @@ extension AlertTarget { self.navEvents[.onViewDidDisappear]?(self) } // hide window - guard let window = view.window as? AlertWindow, let windowScene = windowScene else { return } - let count = window.alerts.count - if count == 0 { + guard let window = attachedWindow, let windowScene = windowScene ?? AppContext.windowScene else { return } + if window.alerts.count == 0 { AppContext.alertWindow[windowScene] = nil UIView.animateLinear(duration: duration) { window.backgroundView.alpha = 0 diff --git a/Sources/ProHUD/Capsule/CapsuleManager.swift b/Sources/ProHUD/Capsule/CapsuleManager.swift index 889dd42..e23be22 100644 --- a/Sources/ProHUD/Capsule/CapsuleManager.swift +++ b/Sources/ProHUD/Capsule/CapsuleManager.swift @@ -136,7 +136,7 @@ extension CapsuleTarget { } @objc open func pop() { - guard let window = attachedWindow, let windowScene = windowScene else { return } + guard let window = attachedWindow, let windowScene = windowScene ?? AppContext.windowScene else { return } let position = vm?.position ?? .top AppContext.capsuleWindows[windowScene]?[position] = nil navEvents[.onViewWillDisappear]?(self) diff --git a/Sources/ProHUD/Sheet/SheetWindow.swift b/Sources/ProHUD/Sheet/SheetWindow.swift index a1f34c1..2c2a8f8 100644 --- a/Sources/ProHUD/Sheet/SheetWindow.swift +++ b/Sources/ProHUD/Sheet/SheetWindow.swift @@ -31,13 +31,13 @@ class SheetWindow: Window { extension SheetTarget { func getContextWindows() -> [SheetWindow] { - guard let windowScene = windowScene else { + guard let windowScene = windowScene ?? AppContext.windowScene else { return [] } return AppContext.sheetWindows[windowScene] ?? [] } func setContextWindows(_ windows: [SheetWindow]) { - guard let windowScene = windowScene else { + guard let windowScene = windowScene ?? AppContext.windowScene else { return } AppContext.sheetWindows[windowScene] = windows diff --git a/Sources/ProHUD/Toast/ToastWindow.swift b/Sources/ProHUD/Toast/ToastWindow.swift index 11ea671..87ed9c4 100644 --- a/Sources/ProHUD/Toast/ToastWindow.swift +++ b/Sources/ProHUD/Toast/ToastWindow.swift @@ -38,13 +38,13 @@ class ToastWindow: Window { extension ToastTarget { func getContextWindows() -> [ToastWindow] { - guard let windowScene = windowScene else { + guard let windowScene = windowScene ?? AppContext.windowScene else { return [] } return AppContext.toastWindows[windowScene] ?? [] } func setContextWindows(_ windows: [ToastWindow]) { - guard let windowScene = windowScene else { + guard let windowScene = windowScene ?? AppContext.windowScene else { return } AppContext.toastWindows[windowScene] = windows