Skip to content

Commit

Permalink
Merge branch 'develop' into sam/bookmarks-phase-2-submenu
Browse files Browse the repository at this point in the history
# By Sam Symons (3) and others
# Via Chris Brind (3) and GitHub (1)
* develop:
  Improve bookmark UI context menus (#678)
  Force callers to refresh even when the save fails. (#701)
  update version
  Update BSK (#693)
  update embedded files
  Possible fix for errant pop-up (#694)
  Use LazyVStack to improve new tab page performance. (#699)
  Update to use URL constructors and helpers from BSK (#698)
  Update for BSK changes of URL parameter API (#697)

# Conflicts:
#	DuckDuckGo/Common/Localizables/UserText.swift
  • Loading branch information
samsymons committed Aug 26, 2022
2 parents dcd882e + e8b5d29 commit bc5c5f4
Show file tree
Hide file tree
Showing 72 changed files with 624 additions and 506 deletions.
26 changes: 13 additions & 13 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -5268,7 +5268,7 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0.28.5;
CURRENT_PROJECT_VERSION = 0.28.6;
DEVELOPMENT_TEAM = HKE973VLUW;
ENABLE_HARDENED_RUNTIME = YES;
GCC_PREPROCESSOR_DEFINITIONS = "REVIEW=1";
Expand All @@ -5277,7 +5277,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.28.5;
MARKETING_VERSION = 0.28.6;
PRODUCT_BUNDLE_IDENTIFIER = com.duckduckgo.macos.browser.review;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "DuckDuckGo Review";
Expand Down Expand Up @@ -5419,15 +5419,15 @@
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0.28.5;
CURRENT_PROJECT_VERSION = 0.28.6;
DEVELOPMENT_TEAM = HKE973VLUW;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = DuckDuckGo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.28.5;
MARKETING_VERSION = 0.28.6;
PRODUCT_BUNDLE_IDENTIFIER = com.duckduckgo.macos.browser;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = DuckDuckGo;
Expand Down Expand Up @@ -5619,15 +5619,15 @@
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0.28.5;
CURRENT_PROJECT_VERSION = 0.28.6;
DEVELOPMENT_TEAM = "";
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = DuckDuckGo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.28.5;
MARKETING_VERSION = 0.28.6;
PRODUCT_BUNDLE_IDENTIFIER = com.duckduckgo.macos.browser.debug;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = DuckDuckGo;
Expand Down Expand Up @@ -5872,15 +5872,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0.28.5;
CURRENT_PROJECT_VERSION = 0.28.6;
DEVELOPMENT_TEAM = HKE973VLUW;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = DuckDuckGo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.28.5;
MARKETING_VERSION = 0.28.6;
PRODUCT_BUNDLE_IDENTIFIER = com.duckduckgo.macos.browser.debug;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = DuckDuckGo;
Expand All @@ -5901,15 +5901,15 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0.28.5;
CURRENT_PROJECT_VERSION = 0.28.6;
DEVELOPMENT_TEAM = HKE973VLUW;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = DuckDuckGo/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.28.5;
MARKETING_VERSION = 0.28.6;
PRODUCT_BUNDLE_IDENTIFIER = com.duckduckgo.macos.browser;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = DuckDuckGo;
Expand Down Expand Up @@ -6034,7 +6034,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 0.28.5;
CURRENT_PROJECT_VERSION = 0.28.6;
DEVELOPMENT_TEAM = HKE973VLUW;
ENABLE_HARDENED_RUNTIME = YES;
GCC_PREPROCESSOR_DEFINITIONS = "REVIEW=1";
Expand All @@ -6043,7 +6043,7 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MARKETING_VERSION = 0.28.5;
MARKETING_VERSION = 0.28.6;
PRODUCT_BUNDLE_IDENTIFIER = com.duckduckgo.macos.browser.review;
PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)";
PRODUCT_NAME = "DuckDuckGo Review";
Expand Down Expand Up @@ -6212,7 +6212,7 @@
repositoryURL = "https://github.com/duckduckgo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 24.0.0;
version = 27.0.1;
};
};
AA06B6B52672AF8100F541C5 /* XCRemoteSwiftPackageReference "Sparkle" */ = {
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/API/APIRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ enum APIRequest {
var etag = httpResponse?.headerValue(for: APIHeaders.Name.etag)

// Handle weak etags
etag = etag?.drop(prefix: "W/")
etag = etag?.dropping(prefix: "W/")
completion(Response(data: data, etag: etag, urlResponse: response), nil)
}
}
Expand All @@ -105,7 +105,7 @@ enum APIRequest {
headers: HTTPHeaders = APIHeaders().defaultHeaders,
timeoutInterval: TimeInterval = 60.0) -> URLRequest {
let url = (try? parameters?.reduce(url) { partialResult, parameter in
try partialResult.addParameter(
try partialResult.appendingParameter(
name: parameter.key,
value: parameter.value,
allowedReservedCharacters: allowedQueryReservedCharacters
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/App Delegate/CopyHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class CopyHandler: NSObject {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(selectedText, forType: .string)

if let urlString = URL(trimmedAddressBarString: selectedText.trimmingWhitespaces())?.absoluteString,
if let urlString = URL(trimmedAddressBarString: selectedText.trimmingWhitespace())?.absoluteString,
urlString == selectedText {
NSPasteboard.general.setString(urlString, forType: .URL)
}
Expand Down
3 changes: 2 additions & 1 deletion DuckDuckGo/Autoconsent/UI/CookieConsentPopover.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public final class CookieConsentPopover {
viewController.delegate = self
}

public func close(animated: Bool) {
public func close(animated: Bool, completion: (() -> Void)? = nil) {
guard let overlayWindow = windowController.window else {
return
}
Expand All @@ -57,6 +57,7 @@ public final class CookieConsentPopover {
let removeWindow = {
overlayWindow.parent?.removeChildWindow(overlayWindow)
overlayWindow.orderOut(nil)
completion?()
}

if animated {
Expand Down
48 changes: 39 additions & 9 deletions DuckDuckGo/Autoconsent/UI/CookieConsentPopoverManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,51 @@ final class CookieConsentPopoverManager: CookieConsentPopoverDelegate {
var completion: ((Bool) -> Void)?
weak var currentTab: Tab?

lazy var popOver: CookieConsentPopover = {
let popover = CookieConsentPopover()
popover.delegate = self
return popover
}()
private(set) var popOver: CookieConsentPopover?

func cookieConsentPopover(_ popOver: CookieConsentPopover, didFinishWithResult result: Bool) {
popOver.close(animated: true)
popOver.close(animated: true) { [weak self] in
self?.popOver = nil
self?.currentTab = nil
}

if let completion = completion {
completion(result)
}
}

func show(on view: NSView, animated: Bool, result: ((Bool) -> Void)? = nil) {
preparePopover()

guard let popOver = popOver else {
return
}

func show(on view: NSView, animated: Bool, result: @escaping (Bool) -> Void) {
popOver.show(on: view, animated: true)
self.completion = result
popOver.show(on: view, animated: animated)
if let result = result {
self.completion = result
}
}

func close(animated: Bool) {
guard let popOver = popOver else {
return
}

popOver.close(animated: animated)
}

private func preparePopover() {
// If the tab was closed, we want to start the animation again
if currentTab == nil {
popOver = nil
}

guard popOver == nil else {
return
}

popOver = CookieConsentPopover()
popOver?.delegate = self
}
}
8 changes: 1 addition & 7 deletions DuckDuckGo/Autofill/ContentOverlayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,7 @@ public final class ContentOverlayViewController: NSViewController, EmailManagerR
completion: @escaping (Data?, Error?) -> Void) {
let currentQueue = OperationQueue.current

let finalURL: URL

if let parameters = parameters {
finalURL = (try? url.addParameters(parameters)) ?? url
} else {
finalURL = url
}
let finalURL = (try? url.appendingParameters(parameters ?? [:])) ?? url

var request = URLRequest(url: finalURL, timeoutInterval: timeoutInterval)
request.allHTTPHeaderFields = headers
Expand Down
38 changes: 24 additions & 14 deletions DuckDuckGo/Bookmarks Bar/View/BookmarksBarCollectionViewItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ protocol BookmarksBarCollectionViewItemDelegate: AnyObject {

func bookmarksBarCollectionViewItemOpenInNewTabAction(_ item: BookmarksBarCollectionViewItem)
func bookmarksBarCollectionViewItemOpenInNewWindowAction(_ item: BookmarksBarCollectionViewItem)
func bookmarksBarCollectionViewItemToggleFavoriteBookmarkAction(_ item: BookmarksBarCollectionViewItem)
func bookmarksBarCollectionViewItemAddToFavoritesAction(_ item: BookmarksBarCollectionViewItem)
func bookmarksBarCollectionViewEditAction(_ item: BookmarksBarCollectionViewItem)
func bookmarksBarCollectionViewItemMoveToEndAction(_ item: BookmarksBarCollectionViewItem)
func bookmarksBarCollectionViewItemCopyBookmarkURLAction(_ item: BookmarksBarCollectionViewItem)
func bookmarksBarCollectionViewItemDeleteEntityAction(_ item: BookmarksBarCollectionViewItem)
Expand Down Expand Up @@ -168,16 +169,19 @@ extension BookmarksBarCollectionViewItem {
// MARK: Bookmark Menu Items

func createBookmarkMenuItems(isFavorite: Bool) -> [NSMenuItem] {
return [
let items = [
openBookmarkInNewTabMenuItem(),
openBookmarkInNewWindowMenuItem(),
NSMenuItem.separator(),
toggleBookmarkAsFavoriteMenuItem(isFavorite: isFavorite),
addToFavoritesMenuItem(isFavorite: isFavorite),
editItem(),
moveToEndMenuItem(),
NSMenuItem.separator(),
copyBookmarkURLMenuItem(),
deleteEntityMenuItem()
]
].compactMap { $0 }

return items
}

func openBookmarkInNewTabMenuItem() -> NSMenuItem {
Expand All @@ -198,21 +202,26 @@ extension BookmarksBarCollectionViewItem {
delegate?.bookmarksBarCollectionViewItemOpenInNewWindowAction(self)
}

func toggleBookmarkAsFavoriteMenuItem(isFavorite: Bool) -> NSMenuItem {
let title: String

if isFavorite {
title = UserText.removeFromFavorites
} else {
title = UserText.addToFavorites
func addToFavoritesMenuItem(isFavorite: Bool) -> NSMenuItem? {
guard !isFavorite else {
return nil
}

return menuItem(title, #selector(toggleBookmarkAsFavoriteMenuItemSelected(_:)))
return menuItem(UserText.addToFavorites, #selector(addToFavoritesMenuItemSelected(_:)))
}

@objc
func addToFavoritesMenuItemSelected(_ sender: NSMenuItem) {
delegate?.bookmarksBarCollectionViewItemAddToFavoritesAction(self)
}

func editItem() -> NSMenuItem {
return menuItem("Edit…", #selector(editItemSelected(_:)))
}

@objc
func toggleBookmarkAsFavoriteMenuItemSelected(_ sender: NSMenuItem) {
delegate?.bookmarksBarCollectionViewItemToggleFavoriteBookmarkAction(self)
func editItemSelected(_ sender: NSMenuItem) {
delegate?.bookmarksBarCollectionViewEditAction(self)
}

func moveToEndMenuItem() -> NSMenuItem {
Expand Down Expand Up @@ -246,6 +255,7 @@ extension BookmarksBarCollectionViewItem {

func createFolderMenuItems() -> [NSMenuItem] {
return [
editItem(),
moveToEndMenuItem(),
NSMenuItem.separator(),
deleteEntityMenuItem()
Expand Down
37 changes: 35 additions & 2 deletions DuckDuckGo/Bookmarks Bar/View/BookmarksBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,14 @@ extension BookmarksBarViewController: BookmarksBarViewModelDelegate {
WindowsManager.openNewWindow(with: bookmark.url)
case .clickItem:
WindowControllersManager.shared.show(url: bookmark.url)
case .toggleFavorite:
bookmark.isFavorite = !bookmark.isFavorite
case .addToFavorites:
bookmark.isFavorite = true
bookmarkManager.update(bookmark: bookmark)
case .edit:
let addBookmarkViewController = AddBookmarkModalViewController.create()
addBookmarkViewController.delegate = self
addBookmarkViewController.edit(bookmark: bookmark)
presentAsModalWindow(addBookmarkViewController)
case .moveToEnd:
bookmarkManager.move(objectUUID: bookmark.id, toIndex: nil) { _ in }
case .copyURL:
Expand All @@ -228,6 +233,11 @@ extension BookmarksBarViewController: BookmarksBarViewModelDelegate {
let menu = bookmarkFolderMenu(items: menuItems)

menu.popUp(positioning: nil, at: CGPoint(x: 0, y: item.view.frame.minY - 7), in: item.view)
case .edit:
let addFolderViewController = AddFolderModalViewController.create()
addFolderViewController.delegate = self
addFolderViewController.edit(folder: folder)
presentAsModalWindow(addFolderViewController)
case .moveToEnd:
bookmarkManager.move(objectUUID: folder.id, toIndex: nil) { _ in }
case .deleteEntity:
Expand Down Expand Up @@ -265,3 +275,26 @@ extension BookmarksBarViewController: NSMenuDelegate {
}

}

// MARK: - Editing

extension BookmarksBarViewController: AddBookmarkModalViewControllerDelegate, AddFolderModalViewControllerDelegate {

func addFolderViewController(_ viewController: AddFolderModalViewController, addedFolderWith name: String) {
assertionFailure("Cannot add new folders to the bookmarks bar via the modal")
}

func addFolderViewController(_ viewController: AddFolderModalViewController, saved folder: BookmarkFolder) {
bookmarkManager.update(folder: folder)
}

func addBookmarkViewController(_ viewController: AddBookmarkModalViewController, addedBookmarkWithTitle title: String, url: URL) {
assertionFailure("Cannot add new bookmarks to the bookmarks bar via the modal")
}

func addBookmarkViewController(_ viewController: AddBookmarkModalViewController, saved bookmark: Bookmark, newURL: URL) {
bookmarkManager.update(bookmark: bookmark)
_ = bookmarkManager.updateUrl(of: bookmark, to: newURL)
}

}
11 changes: 8 additions & 3 deletions DuckDuckGo/Bookmarks Bar/View/BookmarksBarViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ final class BookmarksBarViewModel: NSObject {
case openInBackgroundTab
case openInNewTab
case openInNewWindow
case toggleFavorite
case addToFavorites
case edit
case moveToEnd
case copyURL
case deleteEntity
Expand Down Expand Up @@ -468,8 +469,12 @@ extension BookmarksBarViewModel: BookmarksBarCollectionViewItemDelegate {
delegate?.bookmarksBarViewModelReceived(action: .openInNewWindow, for: item)
}

func bookmarksBarCollectionViewItemToggleFavoriteBookmarkAction(_ item: BookmarksBarCollectionViewItem) {
delegate?.bookmarksBarViewModelReceived(action: .toggleFavorite, for: item)
func bookmarksBarCollectionViewItemAddToFavoritesAction(_ item: BookmarksBarCollectionViewItem) {
delegate?.bookmarksBarViewModelReceived(action: .addToFavorites, for: item)
}

func bookmarksBarCollectionViewEditAction(_ item: BookmarksBarCollectionViewItem) {
delegate?.bookmarksBarViewModelReceived(action: .edit, for: item)
}

func bookmarksBarCollectionViewItemMoveToEndAction(_ item: BookmarksBarCollectionViewItem) {
Expand Down
Loading

0 comments on commit bc5c5f4

Please sign in to comment.