Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show fetch favicons prompt when dismissing settings #3884

Merged
merged 6 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions DuckDuckGo/FavoritesViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class FavoritesViewModel: ObservableObject {
@Published private(set) var allFavorites: [FavoriteItem] = []
@Published private(set) var isCollapsed: Bool = true

// In memory only so that when settings is dismissed we can show the prompt.
// Missing icons will trigger the prompt from elsewhere too so we don't need to persist this.
private(set) var hasMissingIcons = false

private(set) var faviconLoader: FavoritesFaviconLoading?

private var cancellables = Set<AnyCancellable>()
Expand Down Expand Up @@ -128,6 +132,7 @@ class FavoritesViewModel: ObservableObject {

var onFaviconMissing: () -> Void = {}
func faviconMissing() {
hasMissingIcons = true
onFaviconMissing()
}

Expand Down
25 changes: 24 additions & 1 deletion DuckDuckGo/MainViewController+Segues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ extension MainViewController {
let settingsController = SettingsHostingController(viewModel: settingsViewModel, viewProvider: legacyViewProvider)

// We are still presenting legacy views, so use a Navcontroller
let navController = UINavigationController(rootViewController: settingsController)
let navController = SettingsUINavigationController(rootViewController: settingsController)
settingsController.modalPresentationStyle = UIModalPresentationStyle.automatic

present(navController, animated: true) {
Expand Down Expand Up @@ -325,3 +325,26 @@ extension MainViewController {
}

}

// Exists to fire a did disappear notification for settings when the controller did disappear
// so that we get the event regarldess of where in the UI hierarchy it happens.
class SettingsUINavigationController: UINavigationController {

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

init(rootViewController: SettingsHostingController) {
super.init(rootViewController: rootViewController)
}

override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
NotificationCenter.default.post(name: .settingsDidDisappear, object: nil)
}

}

extension NSNotification.Name {
static let settingsDidDisappear: NSNotification.Name = Notification.Name(rawValue: "com.duckduckgo.settings.didDisappear")
}
12 changes: 12 additions & 0 deletions DuckDuckGo/NewTabPageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ final class NewTabPageViewController: UIHostingController<AnyView>, NewTabPage {
override func viewDidLoad() {
super.viewDidLoad()

registerForSettingsDidDisappear()
setUpDaxDialog()
}

Expand All @@ -116,6 +117,17 @@ final class NewTabPageViewController: UIHostingController<AnyView>, NewTabPage {
sendDailyDisplayPixel()
}

func registerForSettingsDidDisappear() {
NotificationCenter.default.addObserver(self, selector: #selector(onSettingsDidDisappear), name: .settingsDidDisappear, object: nil)
}


@objc func onSettingsDidDisappear() {
if self.favoritesModel.hasMissingIcons {
self.delegate?.newTabPageDidRequestFaviconsFetcherOnboarding(self)
}
}

private func setUpDaxDialog() {
let daxDialogController = DaxDialogViewController.loadFromStoryboard()
guard let dialogView = daxDialogController.view else { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ public struct FaviconsFetcherOnboardingView: View {

Text(UserText.fetchFaviconsOnboardingTitle)
.daxTitle1()
.multilineTextAlignment(.center)

Text(UserText.fetchFaviconsOnboardingMessage)
.multilineTextAlignment(.center)
.daxBodyRegular()
.minimumScaleFactor(0.8)
}
.padding(.horizontal, 24)
.padding(.vertical, 20)
Expand Down
Loading