diff --git a/DuckDuckGo/AutofillLoginSettingsListViewController.swift b/DuckDuckGo/AutofillLoginSettingsListViewController.swift index 500f9f3216..fba8246fca 100644 --- a/DuckDuckGo/AutofillLoginSettingsListViewController.swift +++ b/DuckDuckGo/AutofillLoginSettingsListViewController.swift @@ -33,6 +33,7 @@ enum AutofillSettingsSource: String { case appIconShortcut = "app_icon_shortcut" case homeScreenWidget = "home_screen_widget" case lockScreenWidget = "lock_screen_widget" + case newTabPageShortcut = "new_tab_page_shortcut" } protocol AutofillLoginSettingsListViewControllerDelegate: AnyObject { diff --git a/DuckDuckGo/MainViewController.swift b/DuckDuckGo/MainViewController.swift index 796a671420..b68183ce52 100644 --- a/DuckDuckGo/MainViewController.swift +++ b/DuckDuckGo/MainViewController.swift @@ -742,6 +742,7 @@ class MainViewController: UIViewController { homePageMessagesConfiguration: homePageConfiguration) controller.delegate = self + controller.shortcutsDelegate = self newTabPageViewController = controller addToContentContainer(controller: controller) @@ -2030,6 +2031,32 @@ extension MainViewController: NewTabPageControllerDelegate { } } +extension MainViewController: NewTabPageControllerShortcutsDelegate { + func newTabPageDidRequestDownloads(_ controller: NewTabPageViewController) { + segueToDownloads() + } + + func newTabPageDidRequestBookmarks(_ controller: NewTabPageViewController) { + segueToBookmarks() + } + + func newTabPageDidRequestPasswords(_ controller: NewTabPageViewController) { + launchAutofillLogins(source: .newTabPageShortcut) + } + + func newTabPageDidRequestAIChat(_ controller: NewTabPageViewController) { + loadUrl(Constant.duckAIURL) + } + + func newTabPageDidRequestSettings(_ controller: NewTabPageViewController) { + segueToSettings() + } + + private enum Constant { + static let duckAIURL = URL(string: "https://duckduckgo.com/?q=DuckDuckGo+AI+Chat&ia=chat&duckai=1")! + } +} + extension MainViewController: TabDelegate { func tab(_ tab: TabViewController, diff --git a/DuckDuckGo/NewTabPageControllerDelegate.swift b/DuckDuckGo/NewTabPageControllerDelegate.swift index 15981c4b5d..08ecc46c65 100644 --- a/DuckDuckGo/NewTabPageControllerDelegate.swift +++ b/DuckDuckGo/NewTabPageControllerDelegate.swift @@ -25,3 +25,11 @@ protocol NewTabPageControllerDelegate: AnyObject { func newTabPageDidDeleteFavorite(_ controller: NewTabPageViewController, favorite: BookmarkEntity) func newTabPageDidEditFavorite(_ controller: NewTabPageViewController, favorite: BookmarkEntity) } + +protocol NewTabPageControllerShortcutsDelegate: AnyObject { + func newTabPageDidRequestDownloads(_ controller: NewTabPageViewController) + func newTabPageDidRequestBookmarks(_ controller: NewTabPageViewController) + func newTabPageDidRequestPasswords(_ controller: NewTabPageViewController) + func newTabPageDidRequestAIChat(_ controller: NewTabPageViewController) + func newTabPageDidRequestSettings(_ controller: NewTabPageViewController) +} diff --git a/DuckDuckGo/NewTabPageViewController.swift b/DuckDuckGo/NewTabPageViewController.swift index 9638f717d0..2d5c92fc57 100644 --- a/DuckDuckGo/NewTabPageViewController.swift +++ b/DuckDuckGo/NewTabPageViewController.swift @@ -30,6 +30,7 @@ final class NewTabPageViewController: UIHostingController Void)? + init(shortcutsPreferencesStorage: ShortcutsPreferencesStorage) { self.shortcutsPreferencesStorage = shortcutsPreferencesStorage enabledShortcuts = shortcutsPreferencesStorage.enabledShortcuts } + + func openShortcut(_ shortcut: NewTabPageShortcut) { + onShortcutOpened?(shortcut) + } } final class InMemoryShortcutsPreferencesStorage: ShortcutsPreferencesStorage { diff --git a/DuckDuckGo/ShortcutsView.swift b/DuckDuckGo/ShortcutsView.swift index 5057518042..3ee93cf3c2 100644 --- a/DuckDuckGo/ShortcutsView.swift +++ b/DuckDuckGo/ShortcutsView.swift @@ -25,7 +25,11 @@ struct ShortcutsView: View { var body: some View { NewTabPageGridView { _ in ForEach(model.enabledShortcuts) { shortcut in - ShortcutItemView(shortcut: shortcut, accessoryType: nil) + Button { + model.openShortcut(shortcut) + } label: { + ShortcutItemView(shortcut: shortcut, accessoryType: nil) + } } } }