Skip to content

Commit

Permalink
separate tab search for fire windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx committed Dec 16, 2024
1 parent 228c50f commit 8dc9c3f
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 32 deletions.
2 changes: 1 addition & 1 deletion DuckDuckGo/HomePage/Model/HomePageAddressBarModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ extension HomePage.Models {
return AddressBarViewController(
coder: coder,
tabCollectionViewModel: tabCollectionViewModel,
isBurner: tabCollectionViewModel.isBurner,
burnerMode: tabCollectionViewModel.burnerMode,
popovers: nil,
isSearchBox: true
)
Expand Down
1 change: 0 additions & 1 deletion DuckDuckGo/MainWindow/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ final class MainViewController: NSViewController {
}()

navigationBarViewController = NavigationBarViewController.create(tabCollectionViewModel: tabCollectionViewModel,
isBurner: isBurner,
networkProtectionPopoverManager: networkProtectionPopoverManager,
networkProtectionStatusReporter: networkProtectionStatusReporter,
autofillPopoverPresenter: autofillPopoverPresenter,
Expand Down
8 changes: 4 additions & 4 deletions DuckDuckGo/NavigationBar/View/AddressBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ final class AddressBarViewController: NSViewController, ObservableObject {

init?(coder: NSCoder,
tabCollectionViewModel: TabCollectionViewModel,
isBurner: Bool,
burnerMode: BurnerMode,
popovers: NavigationBarPopovers?,
isSearchBox: Bool = false,
onboardingPixelReporter: OnboardingAddressBarReporting = OnboardingPixelReporter()) {
self.tabCollectionViewModel = tabCollectionViewModel
self.popovers = popovers
self.suggestionContainerViewModel = SuggestionContainerViewModel(
isHomePage: tabViewModel?.tab.content == .newtab,
isBurner: isBurner,
suggestionContainer: SuggestionContainer())
self.isBurner = isBurner
isBurner: burnerMode.isBurner,
suggestionContainer: SuggestionContainer(burnerMode: burnerMode))
self.isBurner = burnerMode.isBurner
self.onboardingPixelReporter = onboardingPixelReporter
self.isSearchBox = isSearchBox

Expand Down
12 changes: 5 additions & 7 deletions DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ final class NavigationBarViewController: NSViewController {
var addressBarViewController: AddressBarViewController?

private var tabCollectionViewModel: TabCollectionViewModel
private let isBurner: Bool
private var burnerMode: BurnerMode { tabCollectionViewModel.burnerMode }

// swiftlint:disable weak_delegate
private let goBackButtonMenuDelegate: NavigationButtonMenuDelegate
Expand Down Expand Up @@ -124,7 +124,6 @@ final class NavigationBarViewController: NSViewController {
private let networkProtectionFeatureActivation: NetworkProtectionFeatureActivation

static func create(tabCollectionViewModel: TabCollectionViewModel,
isBurner: Bool,
networkProtectionFeatureActivation: NetworkProtectionFeatureActivation = NetworkProtectionKeychainTokenStore(),
downloadListCoordinator: DownloadListCoordinator = .shared,
dragDropManager: BookmarkDragDropManager = .shared,
Expand All @@ -134,17 +133,16 @@ final class NavigationBarViewController: NSViewController {
aiChatMenuConfig: AIChatMenuVisibilityConfigurable,
brokenSitePromptLimiter: BrokenSitePromptLimiter) -> NavigationBarViewController {
NSStoryboard(name: "NavigationBar", bundle: nil).instantiateInitialController { coder in
self.init(coder: coder, tabCollectionViewModel: tabCollectionViewModel, isBurner: isBurner, networkProtectionFeatureActivation: networkProtectionFeatureActivation, downloadListCoordinator: downloadListCoordinator, dragDropManager: dragDropManager, networkProtectionPopoverManager: networkProtectionPopoverManager, networkProtectionStatusReporter: networkProtectionStatusReporter, autofillPopoverPresenter: autofillPopoverPresenter, aiChatMenuConfig: aiChatMenuConfig, brokenSitePromptLimiter: brokenSitePromptLimiter)
self.init(coder: coder, tabCollectionViewModel: tabCollectionViewModel, networkProtectionFeatureActivation: networkProtectionFeatureActivation, downloadListCoordinator: downloadListCoordinator, dragDropManager: dragDropManager, networkProtectionPopoverManager: networkProtectionPopoverManager, networkProtectionStatusReporter: networkProtectionStatusReporter, autofillPopoverPresenter: autofillPopoverPresenter, aiChatMenuConfig: aiChatMenuConfig, brokenSitePromptLimiter: brokenSitePromptLimiter)
}!
}

init?(coder: NSCoder, tabCollectionViewModel: TabCollectionViewModel, isBurner: Bool, networkProtectionFeatureActivation: NetworkProtectionFeatureActivation, downloadListCoordinator: DownloadListCoordinator, dragDropManager: BookmarkDragDropManager, networkProtectionPopoverManager: NetPPopoverManager, networkProtectionStatusReporter: NetworkProtectionStatusReporter, autofillPopoverPresenter: AutofillPopoverPresenter,
init?(coder: NSCoder, tabCollectionViewModel: TabCollectionViewModel, networkProtectionFeatureActivation: NetworkProtectionFeatureActivation, downloadListCoordinator: DownloadListCoordinator, dragDropManager: BookmarkDragDropManager, networkProtectionPopoverManager: NetPPopoverManager, networkProtectionStatusReporter: NetworkProtectionStatusReporter, autofillPopoverPresenter: AutofillPopoverPresenter,
aiChatMenuConfig: AIChatMenuVisibilityConfigurable, brokenSitePromptLimiter: BrokenSitePromptLimiter) {

self.popovers = NavigationBarPopovers(networkProtectionPopoverManager: networkProtectionPopoverManager, autofillPopoverPresenter: autofillPopoverPresenter, isBurner: isBurner)
self.popovers = NavigationBarPopovers(networkProtectionPopoverManager: networkProtectionPopoverManager, autofillPopoverPresenter: autofillPopoverPresenter, isBurner: tabCollectionViewModel.isBurner)
self.tabCollectionViewModel = tabCollectionViewModel
self.networkProtectionButtonModel = NetworkProtectionNavBarButtonModel(popoverManager: networkProtectionPopoverManager, statusReporter: networkProtectionStatusReporter)
self.isBurner = isBurner
self.networkProtectionFeatureActivation = networkProtectionFeatureActivation
self.downloadListCoordinator = downloadListCoordinator
self.dragDropManager = dragDropManager
Expand Down Expand Up @@ -234,7 +232,7 @@ final class NavigationBarViewController: NSViewController {
let onboardingPixelReporter = OnboardingPixelReporter()
guard let addressBarViewController = AddressBarViewController(coder: coder,
tabCollectionViewModel: tabCollectionViewModel,
isBurner: isBurner,
burnerMode: burnerMode,
popovers: popovers,
onboardingPixelReporter: onboardingPixelReporter) else {
fatalError("NavigationBarViewController: Failed to init AddressBarViewController")
Expand Down
27 changes: 16 additions & 11 deletions DuckDuckGo/Suggestions/Model/SuggestionContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,12 @@ final class SuggestionContainer {
self.loading = suggestionLoading
}

convenience init () {
convenience init (burnerMode: BurnerMode) {
let urlFactory = { urlString in
return URL.makeURL(fromSuggestionPhrase: urlString)
}
let openTabsProvider: OpenTabsProvider = { @MainActor in
let selectedTab = WindowControllersManager.shared.selectedTab
return WindowControllersManager.shared.allTabViewModels.compactMap { model in
guard model.tab !== selectedTab, model.tab.content.isUrl else { return nil }
return model.tab.content.userEditableUrl.map { url in
OpenTab(title: model.title, url: url)
}
}
}
self.init(openTabsProvider: openTabsProvider, suggestionLoading: SuggestionLoader(urlFactory: urlFactory),
self.init(openTabsProvider: Self.defaultOpenTabsProvider(burnerMode: burnerMode),
suggestionLoading: SuggestionLoader(urlFactory: urlFactory),
historyCoordinating: HistoryCoordinator.shared,
bookmarkManager: LocalBookmarkManager.shared)
}
Expand Down Expand Up @@ -102,6 +94,19 @@ final class SuggestionContainer {
latestQuery = nil
}

private static func defaultOpenTabsProvider(burnerMode: BurnerMode) -> OpenTabsProvider {
{ @MainActor in
let selectedTab = WindowControllersManager.shared.selectedTab
let openTabViewModels = WindowControllersManager.shared.allTabViewModels(for: burnerMode)
return openTabViewModels.compactMap { model in
guard model.tab !== selectedTab, model.tab.content.isUrl else { return nil }
return model.tab.content.userEditableUrl.map { url in
OpenTab(title: model.title, url: url)
}
}
}
}

}

struct OpenTab: BrowserTab {
Expand Down
12 changes: 11 additions & 1 deletion DuckDuckGo/Windows/View/WindowControllersManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,20 @@ extension WindowControllersManager {

var allTabViewModels: [TabViewModel] {
return allTabCollectionViewModels.flatMap {
Array($0.tabViewModels.values)
$0.tabViewModels.values
}
}

func allTabViewModels(for burnerMode: BurnerMode) -> [TabViewModel] {
allTabCollectionViewModels
.filter { tabCollectionViewModel in
tabCollectionViewModel.burnerMode == burnerMode
}
.flatMap {
$0.tabViewModels.values
}
}

func windowController(for tabCollectionViewModel: TabCollectionViewModel) -> MainWindowController? {
return mainWindowControllers.first(where: {
tabCollectionViewModel === $0.mainViewController.tabCollectionViewModel
Expand Down
5 changes: 4 additions & 1 deletion IntegrationTests/Tab/SearchNonexistentDomainTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ final class SearchNonexistentDomainTests: XCTestCase {
addressBar.stringValue = enteredString

let suggestionLoadingMock = SuggestionLoadingMock()
let suggestionContainer = SuggestionContainer(suggestionLoading: suggestionLoadingMock, historyCoordinating: HistoryCoordinator.shared, bookmarkManager: LocalBookmarkManager.shared)
let suggestionContainer = SuggestionContainer(openTabsProvider: { [] },
suggestionLoading: suggestionLoadingMock,
historyCoordinating: HistoryCoordinator.shared,
bookmarkManager: LocalBookmarkManager.shared)
addressBar.suggestionContainerViewModel = SuggestionContainerViewModel(isHomePage: true, isBurner: false, suggestionContainer: suggestionContainer)

suggestionContainer.getSuggestions(for: enteredString)
Expand Down
9 changes: 6 additions & 3 deletions UnitTests/Suggestions/Model/SuggestionContainerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ final class SuggestionContainerTests: XCTestCase {
func testWhenGetSuggestionsIsCalled_ThenContainerAsksAndHoldsSuggestionsFromLoader() {
let suggestionLoadingMock = SuggestionLoadingMock()
let historyCoordinatingMock = HistoryCoordinatingMock()
let suggestionContainer = SuggestionContainer(suggestionLoading: suggestionLoadingMock,
let suggestionContainer = SuggestionContainer(openTabsProvider: { [] },
suggestionLoading: suggestionLoadingMock,
historyCoordinating: historyCoordinatingMock,
bookmarkManager: LocalBookmarkManager.shared)

Expand All @@ -50,7 +51,8 @@ final class SuggestionContainerTests: XCTestCase {
func testWhenStopGettingSuggestionsIsCalled_ThenNoSuggestionsArePublished() {
let suggestionLoadingMock = SuggestionLoadingMock()
let historyCoordinatingMock = HistoryCoordinatingMock()
let suggestionContainer = SuggestionContainer(suggestionLoading: suggestionLoadingMock,
let suggestionContainer = SuggestionContainer(openTabsProvider: { [] },
suggestionLoading: suggestionLoadingMock,
historyCoordinating: historyCoordinatingMock,
bookmarkManager: LocalBookmarkManager.shared)

Expand All @@ -65,7 +67,8 @@ final class SuggestionContainerTests: XCTestCase {
func testSuggestionLoadingCacheClearing() {
let suggestionLoadingMock = SuggestionLoadingMock()
let historyCoordinatingMock = HistoryCoordinatingMock()
let suggestionContainer = SuggestionContainer(suggestionLoading: suggestionLoadingMock,
let suggestionContainer = SuggestionContainer(openTabsProvider: { [] },
suggestionLoading: suggestionLoadingMock,
historyCoordinating: historyCoordinatingMock,
bookmarkManager: LocalBookmarkManager.shared)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ final class SuggestionContainerViewModelTests: XCTestCase {
SearchPreferences.shared.showAutocompleteSuggestions = true
suggestionLoadingMock = SuggestionLoadingMock()
historyCoordinatingMock = HistoryCoordinatingMock()
suggestionContainer = SuggestionContainer(suggestionLoading: suggestionLoadingMock,
suggestionContainer = SuggestionContainer(openTabsProvider: { [] },
suggestionLoading: suggestionLoadingMock,
historyCoordinating: historyCoordinatingMock,
bookmarkManager: LocalBookmarkManager.shared)
suggestionContainerViewModel = SuggestionContainerViewModel(suggestionContainer: suggestionContainer)
Expand All @@ -59,7 +60,7 @@ final class SuggestionContainerViewModelTests: XCTestCase {
// MARK: - Tests

func testWhenSelectionIndexIsNilThenSelectedSuggestionViewModelIsNil() {
let suggestionContainer = SuggestionContainer()
let suggestionContainer = SuggestionContainer(burnerMode: .regular)
let suggestionContainerViewModel = SuggestionContainerViewModel(suggestionContainer: suggestionContainer)

XCTAssertNil(suggestionContainerViewModel.selectionIndex)
Expand Down Expand Up @@ -87,7 +88,7 @@ final class SuggestionContainerViewModelTests: XCTestCase {
}

func testWhenSelectCalledWithIndexOutOfBoundsThenSelectedSuggestionViewModelIsNil() {
let suggestionContainer = SuggestionContainer()
let suggestionContainer = SuggestionContainer(burnerMode: .regular)
let suggestionListViewModel = SuggestionContainerViewModel(suggestionContainer: suggestionContainer)

suggestionListViewModel.select(at: 0)
Expand Down

0 comments on commit 8dc9c3f

Please sign in to comment.