Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when opening permission popover for NewTab page address bar #3484

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions DuckDuckGo/Common/Extensions/NSViewExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ extension NSView {
set { isHidden = !newValue }
}

var isVisible: Bool {
guard !isHiddenOrHasHiddenAncestor,
let window, window.isVisible else { return false }
return true
}

func makeMeFirstResponder() {
guard let window = window else {
Logger.general.error("\(self.className): Window not available")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ extension NSPopover {
// https://app.asana.com/0/1201037661562251/1206407295280737/f
@objc(swizzled_showRelativeToRect:ofView:preferredEdge:)
private dynamic func swizzled_show(relativeTo positioningRect: NSRect, of positioningView: NSView, preferredEdge: NSRectEdge) {
if positioningView.superview == nil {
if positioningView.window == nil {
var observer: Cancellable?
observer = positioningView.observe(\.window) { positioningView, _ in
if positioningView.window != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class AddressBarButtonsViewController: NSViewController {
@IBOutlet weak var imageButtonWrapper: NSView!
@IBOutlet weak var imageButton: NSButton!
@IBOutlet weak var clearButton: NSButton!
@IBOutlet weak var buttonsContainer: NSStackView!
@IBOutlet private weak var buttonsContainer: NSStackView!

@IBOutlet weak var animationWrapperView: NSView!
var trackerAnimationView1: LottieAnimationView!
Expand All @@ -72,7 +72,7 @@ final class AddressBarButtonsViewController: NSViewController {

@IBOutlet weak var notificationAnimationView: NavigationBarBadgeAnimationView!

@IBOutlet weak var permissionButtons: NSView!
@IBOutlet private weak var permissionButtons: NSView!
@IBOutlet weak var cameraButton: PermissionButton! {
didSet {
cameraButton.isHidden = true
Expand Down Expand Up @@ -368,7 +368,7 @@ final class AddressBarButtonsViewController: NSViewController {
return
}
}
guard button.isShown, permissionButtons.isShown else { return }
guard button.isVisible else { return }

(popover.contentViewController as? PermissionAuthorizationViewController)?.query = query
popover.show(relativeTo: button.bounds, of: button, preferredEdge: .maxY)
Expand Down