From 30a663d11d22a9d7c09f409cde11dea61692d634 Mon Sep 17 00:00:00 2001 From: Dominik Kapusta Date: Thu, 9 May 2024 16:36:46 +0200 Subject: [PATCH] Fix closing full-screen videos with the X button on macOS 14.4 and above (#2762) Task/Issue URL: https://app.asana.com/0/72649045549333/1206959015087322/f Description: Partially revert a fix to #1618 on macOS 14.4 and above because the original issue seems to be gone and that fix seemed to have started breaking full screen videos in macOS Sonoma 14.4 and above. --- .../Tab/View/WebViewContainerView.swift | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/DuckDuckGo/Tab/View/WebViewContainerView.swift b/DuckDuckGo/Tab/View/WebViewContainerView.swift index e87e18f677..e75c81c627 100644 --- a/DuckDuckGo/Tab/View/WebViewContainerView.swift +++ b/DuckDuckGo/Tab/View/WebViewContainerView.swift @@ -141,21 +141,23 @@ final class WebViewContainerView: NSView { } .store(in: &cancellables) - fullScreenWindowWillCloseCancellable = NotificationCenter.default.publisher(for: NSWindow.willCloseNotification, object: fullScreenWindow) - .sink { [weak self] notification in - self?.fullScreenWindowWillCloseCancellable = nil - let fullScreenWindowController = (notification.object as? NSWindow)?.windowController - DispatchQueue.main.async { [weak fullScreenWindowController] in - guard let fullScreenWindowController else { return } - // just in case. - // if WKFullScreenWindowController receives `close()` the next time it‘s open it will crash because its _webView is nil - // https://errors.duckduckgo.com/organizations/ddg/issues/3411/?project=6&referrer=release-issue-stream - NSException.try { - fullScreenWindowController.setValue(NSView(), forKeyPath: #keyPath(webView)) + // https://app.asana.com/0/72649045549333/1206959015087322/f + if #unavailable(macOS 14.4) { + fullScreenWindowWillCloseCancellable = NotificationCenter.default.publisher(for: NSWindow.willCloseNotification, object: fullScreenWindow) + .sink { [weak self] notification in + self?.fullScreenWindowWillCloseCancellable = nil + let fullScreenWindowController = (notification.object as? NSWindow)?.windowController + DispatchQueue.main.async { [weak fullScreenWindowController] in + guard let fullScreenWindowController else { return } + // just in case. + // if WKFullScreenWindowController receives `close()` the next time it‘s open it will crash because its _webView is nil + // https://errors.duckduckgo.com/organizations/ddg/issues/3411/?project=6&referrer=release-issue-stream + NSException.try { + fullScreenWindowController.setValue(NSView(), forKeyPath: #keyPath(webView)) + } } - } - } + } }