Skip to content

Commit

Permalink
fix popover closing on macOS 11
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx committed Jan 16, 2024
1 parent 999aef3 commit 034c1ac
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo/Bookmarks/View/AddBookmarkFolderModalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct AddBookmarkFolderModalView: ModalView {
.fontWeight(.semibold)

HStack(spacing: 16) {
Text("Name:", comment: "New bookmark folder dialog folder name field heading")
Text(UserText.newBookmarkDialogBookmarkNameTitle)
.frame(height: 22)

TextField("", text: $model.folderName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct AddBookmarkFolderPopoverView: ModalView {
}

VStack(alignment: .leading, spacing: 7) {
Text("Name:", comment: "Add Folder popover: folder name text field title")
Text(UserText.newFolderDialogFolderNameTitle)

TextField("", text: $model.folderName)
.focusedOnAppear()
Expand Down
16 changes: 10 additions & 6 deletions DuckDuckGo/Bookmarks/View/AddBookmarkPopover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ final class AddBookmarkPopover: NSPopover {
let window = addressBar.window else { return .infinite }
var frame = window.convertToScreen(addressBar.convert(addressBar.bounds, to: nil))

frame = frame.insetBy(dx: -36, dy: -window.frame.size.height)
frame = frame.insetBy(dx: -42, dy: -window.frame.size.height)

return frame
}
Expand All @@ -53,18 +53,22 @@ final class AddBookmarkPopover: NSPopover {
}

private func setupBookmarkAddController() {
guard let bookmark else {
contentViewController = NSViewController()
return
}
contentViewController = NSHostingController(rootView: AddBookmarkPopoverView(model: AddBookmarkPopoverViewModel(bookmark: bookmark)))
guard let bookmark else { return }
contentViewController = NSHostingController(rootView: AddBookmarkPopoverView(model: AddBookmarkPopoverViewModel(bookmark: bookmark))
.legacyOnDismiss { [weak self] in
self?.performClose(nil)
})
}

override func show(relativeTo positioningRect: NSRect, of positioningView: NSView, preferredEdge: NSRectEdge) {
self.addressBar = positioningView.superview
super.show(relativeTo: positioningRect, of: positioningView, preferredEdge: preferredEdge)
}

override func performClose(_ sender: Any?) {
self.close()
}

func popoverWillClose() {
bookmark = nil
}
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/Common/Localizables/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ struct UserText {
static let newFolder = NSLocalizedString("folder.optionsMenu.newFolder", value: "New Folder", comment: "Option for creating a new folder")
static let renameFolder = NSLocalizedString("folder.optionsMenu.renameFolder", value: "Rename Folder", comment: "Option for renaming a folder")
static let deleteFolder = NSLocalizedString("folder.optionsMenu.deleteFolder", value: "Delete Folder", comment: "Option for deleting a folder")
static let newFolderDialogFolderNameTitle = NSLocalizedString("add.folder.name", value: "Name:", comment: "Add Folder popover: folder name text field title")
static let newBookmarkDialogBookmarkNameTitle = NSLocalizedString("add.bookmark.name", value: "Name:", comment: "New bookmark folder dialog folder name field heading")

static let updateBookmark = NSLocalizedString("bookmark.update", value: "Update Bookmark", comment: "Option for updating a bookmark")

Expand Down
27 changes: 24 additions & 3 deletions DuckDuckGo/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@
},
"Add to Favorites" : {

},
"add.bookmark.name" : {
"comment" : "New bookmark folder dialog folder name field heading",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Name:"
}
}
}
},
"add.favorite" : {
"comment" : "Button for adding a favorite bookmark",
Expand All @@ -175,6 +187,18 @@
}
}
},
"add.folder.name" : {
"comment" : "Add Folder popover: folder name text field title",
"extractionState" : "extracted_with_value",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "new",
"value" : "Name:"
}
}
}
},
"add.link.to.bookmarks" : {
"comment" : "Context menu item",
"extractionState" : "extracted_with_value",
Expand Down Expand Up @@ -4329,9 +4353,6 @@
}
}
},
"Name:" : {
"comment" : "New bookmark folder dialog folder name field heading\nAdd Folder popover: folder name text field title"
},
"navigate.back" : {
"comment" : "Context menu item",
"extractionState" : "extracted_with_value",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,22 @@ extension AddressBarButtonsViewController: PermissionContextMenuDelegate {

extension AddressBarButtonsViewController: NSPopoverDelegate {

func popoverShouldClose(_ popover: NSPopover) -> Bool {
switch popover {
case bookmarkPopover:
// fix popover reopening on next bookmarkButtonAction (on macOS 11)
DispatchQueue.main.async { [weak self] in
if let bookmarkPopover = self?.bookmarkPopover, bookmarkPopover.isShown {
bookmarkPopover.close()
}
}
return false

default:
return true
}
}

func popoverWillClose(_ notification: Notification) {
switch notification.object as? NSPopover {
case bookmarkPopover:
Expand All @@ -995,6 +1011,7 @@ extension AddressBarButtonsViewController: NSPopoverDelegate {
NotificationCenter.default.post(name: .bookmarkPromptShouldShow, object: nil)
}
updateBookmarkButtonVisibility()
self.bookmarkPopover = nil

case privacyDashboardPopover:
privacyEntryPointButton.state = .off
Expand Down

0 comments on commit 034c1ac

Please sign in to comment.