Skip to content

Commit

Permalink
Fix crash when opening permission popover for NewTab page address bar (
Browse files Browse the repository at this point in the history
…#3484)

Task/Issue URL: https://app.asana.com/0/1202406491309510/1208667754274335/f

Description:
Fixes crash when permission requested with NewTab address bar experiment caused by permission popover tried to be presented on the NewTab page address bar
  • Loading branch information
mallexxx authored Oct 31, 2024
1 parent 9022def commit fbdb8a5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
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

0 comments on commit fbdb8a5

Please sign in to comment.