Skip to content

Commit

Permalink
Fix downloads not appearing (#2693)
Browse files Browse the repository at this point in the history
  • Loading branch information
mallexxx authored Apr 24, 2024
1 parent 8a18353 commit 0cbe805
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions DuckDuckGo/NavigationBar/View/NavigationBarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -644,15 +644,20 @@ final class NavigationBarViewController: NSViewController {

private func subscribeToDownloads() {
downloadListCoordinator.updates
.filter { update in
// filter download completion events only
if case .updated(let oldValue) = update.kind,
oldValue.progress != nil && update.item.progress == nil {
return true
} else {
return false
}
}
.throttle(for: 1.0, scheduler: DispatchQueue.main, latest: true)
.sink { [weak self] update in
guard let self else { return }

if case .updated(let oldValue) = update.kind,
DownloadsPreferences.shared.shouldOpenPopupOnCompletion,
update.item.destinationURL != nil,
update.item.tempURL == nil,
oldValue.tempURL != nil, // download finished
if DownloadsPreferences.shared.shouldOpenPopupOnCompletion,
!update.item.isBurner,
WindowControllersManager.shared.lastKeyMainWindowController?.window === downloadsButton.window {

Expand All @@ -661,11 +666,11 @@ final class NavigationBarViewController: NSViewController {
downloadsDelegate: self)
} else if update.item.isBurner {
invalidateDownloadButtonHidingTimer()
updateDownloadsButton(updatingFromPinnedViewsNotification: false)
}
updateDownloadsButton()
}
.store(in: &downloadsCancellables)

downloadListCoordinator.progress.publisher(for: \.totalUnitCount)
.combineLatest(downloadListCoordinator.progress.publisher(for: \.completedUnitCount))
.throttle(for: 0.2, scheduler: DispatchQueue.main, latest: true)
Expand Down

0 comments on commit 0cbe805

Please sign in to comment.